diff --git a/api/v1beta1/grafananotificationpolicy_types.go b/api/v1beta1/grafananotificationpolicy_types.go index 2c717773b..c2efef410 100644 --- a/api/v1beta1/grafananotificationpolicy_types.go +++ b/api/v1beta1/grafananotificationpolicy_types.go @@ -38,6 +38,11 @@ type GrafanaNotificationPolicySpec struct { // Routes for alerts to match against Route *Route `json:"route"` + + // Whether to enable or disable editing of the notification policy in Grafana UI + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable" + // +optional + Editable *bool `json:"editable,omitempty"` } type Route struct { diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 04286e664..d8c3f044b 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -1342,6 +1342,11 @@ func (in *GrafanaNotificationPolicySpec) DeepCopyInto(out *GrafanaNotificationPo *out = new(Route) (*in).DeepCopyInto(*out) } + if in.Editable != nil { + in, out := &in.Editable, &out.Editable + *out = new(bool) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GrafanaNotificationPolicySpec. diff --git a/config/crd/bases/grafana.integreatly.org_grafananotificationpolicies.yaml b/config/crd/bases/grafana.integreatly.org_grafananotificationpolicies.yaml index 81bb69377..c83cdc85b 100644 --- a/config/crd/bases/grafana.integreatly.org_grafananotificationpolicies.yaml +++ b/config/crd/bases/grafana.integreatly.org_grafananotificationpolicies.yaml @@ -43,6 +43,13 @@ spec: description: GrafanaNotificationPolicySpec defines the desired state of GrafanaNotificationPolicy properties: + editable: + description: Whether to enable or disable editing of the notification + policy in Grafana UI + type: boolean + x-kubernetes-validations: + - message: Value is immutable + rule: self == oldSelf instanceSelector: description: selects Grafanas for import properties: diff --git a/controllers/notificationpolicy_controller.go b/controllers/notificationpolicy_controller.go index 91efa2175..d831f03eb 100644 --- a/controllers/notificationpolicy_controller.go +++ b/controllers/notificationpolicy_controller.go @@ -160,8 +160,15 @@ func (r *GrafanaNotificationPolicyReconciler) reconcileWithInstance(ctx context. return fmt.Errorf("building grafana client: %w", err) } - strue := "true" - params := provisioning.NewPutPolicyTreeParams().WithBody(notificationPolicy.Spec.Route.ToModelRoute()).WithXDisableProvenance(&strue) + trueRef := "true" + editable := true + if notificationPolicy.Spec.Editable != nil && !*notificationPolicy.Spec.Editable { + editable = false + } + params := provisioning.NewPutPolicyTreeParams().WithBody(notificationPolicy.Spec.Route.ToModelRoute()) + if editable { + params.SetXDisableProvenance(&trueRef) + } if _, err := cl.Provisioning.PutPolicyTree(params); err != nil { //nolint:errcheck return fmt.Errorf("applying notification policy: %w", err) } diff --git a/deploy/helm/grafana-operator/crds/grafana.integreatly.org_grafananotificationpolicies.yaml b/deploy/helm/grafana-operator/crds/grafana.integreatly.org_grafananotificationpolicies.yaml index 81bb69377..c83cdc85b 100644 --- a/deploy/helm/grafana-operator/crds/grafana.integreatly.org_grafananotificationpolicies.yaml +++ b/deploy/helm/grafana-operator/crds/grafana.integreatly.org_grafananotificationpolicies.yaml @@ -43,6 +43,13 @@ spec: description: GrafanaNotificationPolicySpec defines the desired state of GrafanaNotificationPolicy properties: + editable: + description: Whether to enable or disable editing of the notification + policy in Grafana UI + type: boolean + x-kubernetes-validations: + - message: Value is immutable + rule: self == oldSelf instanceSelector: description: selects Grafanas for import properties: diff --git a/deploy/kustomize/base/crds.yaml b/deploy/kustomize/base/crds.yaml index f2af1297d..e7680805a 100644 --- a/deploy/kustomize/base/crds.yaml +++ b/deploy/kustomize/base/crds.yaml @@ -1593,6 +1593,13 @@ spec: description: GrafanaNotificationPolicySpec defines the desired state of GrafanaNotificationPolicy properties: + editable: + description: Whether to enable or disable editing of the notification + policy in Grafana UI + type: boolean + x-kubernetes-validations: + - message: Value is immutable + rule: self == oldSelf instanceSelector: description: selects Grafanas for import properties: diff --git a/docs/docs/api.md b/docs/docs/api.md index e34e6a33f..8e249f1e7 100644 --- a/docs/docs/api.md +++ b/docs/docs/api.md @@ -3228,6 +3228,15 @@ GrafanaNotificationPolicySpec defines the desired state of GrafanaNotificationPo Routes for alerts to match against
true + + editable + boolean + + Whether to enable or disable editing of the notification policy in Grafana UI
+
+ Validations:
  • self == oldSelf: Value is immutable
  • + + false resyncPeriod string