Skip to content

Commit

Permalink
Add validations to DatadogMonitorSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
shuheiktgw committed Feb 14, 2025
1 parent 53c0d8c commit 568adb3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/datadoghq/v1alpha1/datadogmonitor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand All @@ -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"`
Expand Down
21 changes: 21 additions & 0 deletions config/crd/bases/v1/datadoghq.com_datadogmonitors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -203,6 +205,7 @@ spec:
type: integer
query:
description: Query is the Datadog monitor query
minLength: 1
type: string
restrictedRoles:
description: |-
Expand All @@ -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
Expand Down
23 changes: 23 additions & 0 deletions config/crd/bases/v1/datadoghq.com_datadogmonitors_v1alpha1.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -183,6 +185,7 @@
},
"query": {
"description": "Query is the Datadog monitor query",
"minLength": 1,
"type": "string"
},
"restrictedRoles": {
Expand All @@ -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": {
Expand Down

0 comments on commit 568adb3

Please sign in to comment.