Skip to content

Commit

Permalink
Merge pull request #208 from K-Phoen/converter-folder-annotation
Browse files Browse the repository at this point in the history
Fix the converter to use the proper annotation for folders
  • Loading branch information
K-Phoen committed Mar 20, 2023
2 parents 1b30229 + 401aabd commit abe791b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions internal/pkg/controllers/grafanadashboard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

const grafanaDashboardFinalizerName = "grafanadashboards.k8s.kevingomez.fr/finalizer"
const folderAnnotation = "dark/folder"
const DashboardFolderAnnotation = "dark/folder"

type dashboardManager interface {
FromRawSpec(ctx context.Context, folderName string, uid string, rawJSON []byte) error
Expand Down Expand Up @@ -103,7 +103,7 @@ func (r *GrafanaDashboardReconciler) Reconcile(ctx context.Context, req ctrl.Req
return ctrl.Result{}, nil
}

folder := dashboard.Annotations[folderAnnotation]
folder := dashboard.Annotations[DashboardFolderAnnotation]
if dashboard.Folder != "" {
folder = dashboard.Folder
}
Expand Down
16 changes: 10 additions & 6 deletions internal/pkg/converter/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ import (
"fmt"
"io"

v1 "github.com/K-Phoen/dark/api/v1"
"github.com/K-Phoen/dark/internal/pkg/controllers"
grabana "github.com/K-Phoen/grabana/decoder"
"github.com/K-Phoen/sdk"
"go.uber.org/zap"
"gopkg.in/yaml.v3"

v1 "github.com/K-Phoen/dark/api/v1"
)

type k8sDashboard struct {
APIVersion string `yaml:"apiVersion"`
Kind string
Metadata map[string]string
Folder string
Metadata map[string]interface{}
Spec *grabana.DashboardModel
}

Expand Down Expand Up @@ -81,15 +80,20 @@ func (converter *JSON) ToK8SManifest(input io.Reader, output io.Writer, options
manifest := k8sDashboard{
APIVersion: v1.GroupVersion.String(),
Kind: "GrafanaDashboard",
Metadata: map[string]string{"name": options.Name},
Folder: options.Folder,
Metadata: map[string]interface{}{"name": options.Name},
Spec: dashboard,
}

if options.Namespace != "" {
manifest.Metadata["namespace"] = options.Namespace
}

if options.Folder != "" {
manifest.Metadata["annotations"] = map[string]string{
controllers.DashboardFolderAnnotation: options.Folder,
}
}

converted, err := yaml.Marshal(manifest)
if err != nil {
converter.logger.Error("could marshall dashboard to yaml", zap.Error(err))
Expand Down

0 comments on commit abe791b

Please sign in to comment.