Skip to content

Commit

Permalink
fix: check if folder exists before creation
Browse files Browse the repository at this point in the history
this prevents invisible orphaned alert rules (and helps debugging)
  • Loading branch information
theSuess committed Feb 21, 2024
1 parent 884400b commit 8e28b22
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions controllers/grafanaalertrulegroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"

"github.com/go-openapi/strfmt"
"github.com/grafana/grafana-openapi-client-go/client/folders"
"github.com/grafana/grafana-openapi-client-go/client/provisioning"
"github.com/grafana/grafana-openapi-client-go/models"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -178,6 +179,15 @@ func (r *GrafanaAlertRuleGroupReconciler) reconcileWithInstance(ctx context.Cont
}
strue := "true"

_, err = cl.Folders.GetFolderByUID(folderUID)

Check failure on line 182 in controllers/grafanaalertrulegroup_controller.go

View workflow job for this annotation

GitHub Actions / go-lint

Error return value of `cl.Folders.GetFolderByUID` is not checked (errcheck)
if err != nil {
var folderNotFound *folders.GetFolderByUIDNotFound
if errors.As(err, &folderNotFound) {
return fmt.Errorf("folder with uid %s not found", folderUID)
}
return fmt.Errorf("fetching folder: %w", err)
}

applied, err := cl.Provisioning.GetAlertRuleGroup(group.Name, folderUID)
var ruleNotFound *provisioning.GetAlertRuleGroupNotFound
if err != nil && !errors.As(err, &ruleNotFound) {
Expand Down

0 comments on commit 8e28b22

Please sign in to comment.