Skip to content

Commit

Permalink
refactor: Ensure fodler conditions are applied and removed correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Baarsgaard committed Dec 16, 2024
1 parent c91f2f6 commit 32d8402
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions controllers/grafanafolder_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ func (r *GrafanaFolderReconciler) Reconcile(ctx context.Context, req ctrl.Reques
if err != nil || len(instances) == 0 {
setNoMatchingInstancesCondition(&folder.Status.Conditions, folder.Generation, err)
folder.Status.NoMatchingInstances = true
meta.RemoveStatusCondition(&folder.Status.Conditions, conditionFolderSynchronized)
controllerLog.Error(err, "could not find matching instances", "name", folder.Name, "namespace", folder.Namespace)
return ctrl.Result{RequeueAfter: RequeueDelay}, nil
}
Expand All @@ -217,13 +218,14 @@ func (r *GrafanaFolderReconciler) Reconcile(ctx context.Context, req ctrl.Reques
applyErrors[fmt.Sprintf("%s/%s", grafana.Namespace, grafana.Name)] = err.Error()
}
}
condition := buildSynchronizedCondition("Folder", conditionFolderSynchronized, folder.Generation, applyErrors, len(instances))
meta.SetStatusCondition(&folder.Status.Conditions, condition)

if len(applyErrors) > 0 {
return ctrl.Result{RequeueAfter: RequeueDelay}, fmt.Errorf("failed to apply to all instances: %v", applyErrors)
}

condition := buildSynchronizedCondition("Folder", conditionFolderSynchronized, folder.Generation, applyErrors, len(instances))
meta.SetStatusCondition(&folder.Status.Conditions, condition)

return ctrl.Result{RequeueAfter: folder.Spec.ResyncPeriod.Duration}, nil
}

Expand Down

0 comments on commit 32d8402

Please sign in to comment.