diff --git a/controllers/controller_shared.go b/controllers/controller_shared.go index e3a4cc7d4..e90a87744 100644 --- a/controllers/controller_shared.go +++ b/controllers/controller_shared.go @@ -26,9 +26,14 @@ import ( const grafanaFinalizer = "operator.grafana.com/finalizer" const ( + // condition types conditionNoMatchingInstance = "NoMatchingInstance" conditionNoMatchingFolder = "NoMatchingFolder" conditionInvalidSpec = "InvalidSpec" + + // condition reasons + conditionApplySuccessful = "ApplySuccessful" + conditionApplyFailed = "ApplyFailed" ) const annotationAppliedNotificationPolicy = "operator.grafana.com/applied-notificationpolicy" @@ -148,7 +153,7 @@ func ReconcilePlugins(ctx context.Context, k8sClient client.Client, scheme *runt func setNoMatchingInstance(conditions *[]metav1.Condition, generation int64, reason, message string) { meta.SetStatusCondition(conditions, metav1.Condition{ Type: conditionNoMatchingInstance, - Status: "True", + Status: metav1.ConditionTrue, ObservedGeneration: generation, LastTransitionTime: metav1.Time{ Time: time.Now(), @@ -165,7 +170,7 @@ func removeNoMatchingInstance(conditions *[]metav1.Condition) { func setNoMatchingFolder(conditions *[]metav1.Condition, generation int64, reason, message string) { meta.SetStatusCondition(conditions, metav1.Condition{ Type: conditionNoMatchingFolder, - Status: "True", + Status: metav1.ConditionTrue, ObservedGeneration: generation, LastTransitionTime: metav1.Time{ Time: time.Now(), @@ -182,7 +187,7 @@ func removeNoMatchingFolder(conditions *[]metav1.Condition) { func setInvalidSpec(conditions *[]metav1.Condition, generation int64, reason, message string) { meta.SetStatusCondition(conditions, metav1.Condition{ Type: conditionInvalidSpec, - Status: "True", + Status: metav1.ConditionTrue, ObservedGeneration: generation, LastTransitionTime: metav1.Time{ Time: time.Now(), @@ -215,11 +220,11 @@ func buildSynchronizedCondition(resource string, syncType string, generation int } if len(applyErrors) == 0 { - condition.Status = "True" + condition.Status = metav1.ConditionTrue condition.Reason = "ApplySuccessful" condition.Message = fmt.Sprintf("%s was successfully applied to %d instances", resource, total) } else { - condition.Status = "False" + condition.Status = metav1.ConditionFalse condition.Reason = "ApplyFailed" var sb strings.Builder diff --git a/controllers/grafanaalertrulegroup_controller.go b/controllers/grafanaalertrulegroup_controller.go index 443402017..259d6b36b 100644 --- a/controllers/grafanaalertrulegroup_controller.go +++ b/controllers/grafanaalertrulegroup_controller.go @@ -163,7 +163,7 @@ func (r *GrafanaAlertRuleGroupReconciler) reconcileWithInstance(ctx context.Cont return fmt.Errorf("building grafana client: %w", err) } - trueRef := "true" + trueRef := "true" //nolint:goconst editable := true if group.Spec.Editable != nil && !*group.Spec.Editable { editable = false diff --git a/controllers/grafanacontactpoint_controller.go b/controllers/grafanacontactpoint_controller.go index 28bd21212..a8bf9eeab 100644 --- a/controllers/grafanacontactpoint_controller.go +++ b/controllers/grafanacontactpoint_controller.go @@ -149,12 +149,12 @@ func (r *GrafanaContactPointReconciler) Reconcile(ctx context.Context, req ctrl. } if len(applyErrors) == 0 { - condition.Status = "True" - condition.Reason = "ApplySuccessful" + condition.Status = metav1.ConditionTrue + condition.Reason = conditionApplySuccessful condition.Message = fmt.Sprintf("Contact point was successfully applied to %d instances", len(instances)) } else { - condition.Status = "False" - condition.Reason = "ApplyFailed" + condition.Status = metav1.ConditionFalse + condition.Reason = conditionApplyFailed var sb strings.Builder for i, err := range applyErrors { diff --git a/controllers/grafananotificationtemplate_controller.go b/controllers/grafananotificationtemplate_controller.go index c2d460257..3c3ba99e7 100644 --- a/controllers/grafananotificationtemplate_controller.go +++ b/controllers/grafananotificationtemplate_controller.go @@ -138,12 +138,12 @@ func (r *GrafanaNotificationTemplateReconciler) Reconcile(ctx context.Context, r } if len(applyErrors) == 0 { - condition.Status = "True" - condition.Reason = "ApplySuccessful" + condition.Status = metav1.ConditionTrue + condition.Reason = conditionApplySuccessful condition.Message = fmt.Sprintf("Notification template was successfully applied to %d instances", len(instances)) } else { - condition.Status = "False" - condition.Reason = "ApplyFailed" + condition.Status = metav1.ConditionFalse + condition.Reason = conditionApplyFailed var sb strings.Builder for i, err := range applyErrors { @@ -163,7 +163,7 @@ func (r *GrafanaNotificationTemplateReconciler) reconcileWithInstance(ctx contex return fmt.Errorf("building grafana client: %w", err) } - trueRef := "true" + trueRef := "true" //nolint:goconst editable := true if notificationTemplate.Spec.Editable != nil && !*notificationTemplate.Spec.Editable { editable = false