From 568adb31ab94fa25af46eb39edfae2d83004028f Mon Sep 17 00:00:00 2001 From: Shuhei Kitagawa Date: Fri, 14 Feb 2025 10:01:19 +0100 Subject: [PATCH] Add validations to DatadogMonitorSpec --- .../v1alpha1/datadogmonitor_types.go | 8 +++++++ .../v1/datadoghq.com_datadogmonitors.yaml | 21 +++++++++++++++++ ...atadoghq.com_datadogmonitors_v1alpha1.json | 23 +++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/api/datadoghq/v1alpha1/datadogmonitor_types.go b/api/datadoghq/v1alpha1/datadogmonitor_types.go index f3877907a..4eeeb5fc8 100644 --- a/api/datadoghq/v1alpha1/datadogmonitor_types.go +++ b/api/datadoghq/v1alpha1/datadogmonitor_types.go @@ -15,12 +15,18 @@ import ( // +k8s:openapi-gen=true type DatadogMonitorSpec struct { // Name is the monitor name + // +kubebuilder:validation:Required + // +kubebuilder:validation:MinLength=1 Name string `json:"name,omitempty"` // Message is a message to include with notifications for this monitor + // +kubebuilder:validation:Required + // +kubebuilder:validation:MinLength=1 Message string `json:"message,omitempty"` // Priority is an integer from 1 (high) to 5 (low) indicating alert severity Priority int64 `json:"priority,omitempty"` // Query is the Datadog monitor query + // +kubebuilder:validation:Required + // +kubebuilder:validation:MinLength=1 Query string `json:"query,omitempty"` // RestrictedRoles is a list of unique role identifiers to define which roles are allowed to edit the monitor. // `restricted_roles` is the successor of `locked`. For more information about `locked` and `restricted_roles`, @@ -31,6 +37,8 @@ type DatadogMonitorSpec struct { // +listType=set Tags []string `json:"tags,omitempty"` // Type is the monitor type + // +kubebuilder:validation:Required + // +kubebuilder:validation:Enum=metric alert;query alert;service check;event alert;log alert;process alert;rum alert;trace-analytics alert;slo alert;event-v2 alert;audit alert;composite Type DatadogMonitorType `json:"type,omitempty"` // Options are the optional parameters associated with your monitor Options DatadogMonitorOptions `json:"options,omitempty"` diff --git a/config/crd/bases/v1/datadoghq.com_datadogmonitors.yaml b/config/crd/bases/v1/datadoghq.com_datadogmonitors.yaml index dc58b1133..ddcebc197 100644 --- a/config/crd/bases/v1/datadoghq.com_datadogmonitors.yaml +++ b/config/crd/bases/v1/datadoghq.com_datadogmonitors.yaml @@ -68,9 +68,11 @@ spec: type: object message: description: Message is a message to include with notifications for this monitor + minLength: 1 type: string name: description: Name is the monitor name + minLength: 1 type: string options: description: Options are the optional parameters associated with your monitor @@ -203,6 +205,7 @@ spec: type: integer query: description: Query is the Datadog monitor query + minLength: 1 type: string restrictedRoles: description: |- @@ -221,7 +224,25 @@ spec: x-kubernetes-list-type: set type: description: Type is the monitor type + enum: + - metric alert + - query alert + - service check + - event alert + - log alert + - process alert + - rum alert + - trace-analytics alert + - slo alert + - event-v2 alert + - audit alert + - composite type: string + required: + - message + - name + - query + - type type: object status: description: DatadogMonitorStatus defines the observed state of DatadogMonitor diff --git a/config/crd/bases/v1/datadoghq.com_datadogmonitors_v1alpha1.json b/config/crd/bases/v1/datadoghq.com_datadogmonitors_v1alpha1.json index 5d40fa636..fa530ccbf 100644 --- a/config/crd/bases/v1/datadoghq.com_datadogmonitors_v1alpha1.json +++ b/config/crd/bases/v1/datadoghq.com_datadogmonitors_v1alpha1.json @@ -30,10 +30,12 @@ }, "message": { "description": "Message is a message to include with notifications for this monitor", + "minLength": 1, "type": "string" }, "name": { "description": "Name is the monitor name", + "minLength": 1, "type": "string" }, "options": { @@ -183,6 +185,7 @@ }, "query": { "description": "Query is the Datadog monitor query", + "minLength": 1, "type": "string" }, "restrictedRoles": { @@ -203,9 +206,29 @@ }, "type": { "description": "Type is the monitor type", + "enum": [ + "metric alert", + "query alert", + "service check", + "event alert", + "log alert", + "process alert", + "rum alert", + "trace-analytics alert", + "slo alert", + "event-v2 alert", + "audit alert", + "composite" + ], "type": "string" } }, + "required": [ + "message", + "name", + "query", + "type" + ], "type": "object" }, "status": {