Skip to content

Commit

Permalink
Merge pull request #1739 from chenlujjj/feat/notificationpolicy-editable
Browse files Browse the repository at this point in the history
Add editable field to GrafanaNotificationPolicySpec
  • Loading branch information
theSuess authored Nov 4, 2024
2 parents de966dd + 5578cc8 commit d3f95e4
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 2 deletions.
5 changes: 5 additions & 0 deletions api/v1beta1/grafananotificationpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 9 additions & 2 deletions controllers/notificationpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions deploy/kustomize/base/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions docs/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3228,6 +3228,15 @@ GrafanaNotificationPolicySpec defines the desired state of GrafanaNotificationPo
Routes for alerts to match against<br/>
</td>
<td>true</td>
</tr><tr>
<td><b>editable</b></td>
<td>boolean</td>
<td>
Whether to enable or disable editing of the notification policy in Grafana UI<br/>
<br/>
<i>Validations</i>:<li>self == oldSelf: Value is immutable</li>
</td>
<td>false</td>
</tr><tr>
<td><b>resyncPeriod</b></td>
<td>string</td>
Expand Down

0 comments on commit d3f95e4

Please sign in to comment.