Skip to content

Commit 489ae98

Browse files
committed
[datadog-operator] expose CRD-specific watch namespace settings
1 parent 2c09b7d commit 489ae98

File tree

6 files changed

+120
-3
lines changed

6 files changed

+120
-3
lines changed

charts/datadog-operator/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2.5.1
4+
5+
* Expose CRD-specific namespace watch configuration added in Operator 1.8.0 release.
6+
37
## 2.5.0
48

59
* Update Datadog Operator version to 1.11.1.

charts/datadog-operator/Chart.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: v2
22
name: datadog-operator
3-
version: 2.5.0
3+
version: 2.5.1
44
appVersion: 1.11.1
55
description: Datadog Operator
66
keywords:

charts/datadog-operator/README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Datadog Operator
22

3-
![Version: 2.5.0](https://img.shields.io/badge/Version-2.5.0-informational?style=flat-square) ![AppVersion: 1.11.1](https://img.shields.io/badge/AppVersion-1.11.1-informational?style=flat-square)
3+
![Version: 2.5.1](https://img.shields.io/badge/Version-2.5.1-informational?style=flat-square) ![AppVersion: 1.11.1](https://img.shields.io/badge/AppVersion-1.11.1-informational?style=flat-square)
44

55
## Values
66

@@ -60,7 +60,11 @@
6060
| tolerations | list | `[]` | Allows to schedule Datadog Operator on tainted nodes |
6161
| volumeMounts | list | `[]` | Specify additional volumes to mount in the container |
6262
| volumes | list | `[]` | Specify additional volumes to mount in the container |
63-
| watchNamespaces | list | `[]` | Restricts the Operator to watch its managed resources on specific namespaces |
63+
| watchNamespaces | list | `[]` | Restricts the Operator to watch its managed resources on specific namespaces unless CRD-specific watchNamespaces properties are set |
64+
| watchNamespacesAgent | list | `[]` | Restricts the Operator to watch DatadogAgent resources on specific namespaces. Requires v1.8.0+ |
65+
| watchNamespacesAgentProfile | list | `[]` | Restricts the Operator to watch DatadogAgentProfile resources on specific namespaces. Requires v1.8.0+ |
66+
| watchNamespacesMonitor | list | `[]` | Restricts the Operator to watch DatadogMonitor resources on specific namespaces. Requires v1.8.0+ |
67+
| watchNamespacesSLO | list | `[]` | Restricts the Operator to watch DatadogSLO resources on specific namespaces. Requires v1.8.0+ |
6468

6569
## How to configure which namespaces are watched by the Operator.
6670

charts/datadog-operator/templates/deployment.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ spec:
6262
fieldRef:
6363
fieldPath: metadata.namespace
6464
{{- end }}
65+
{{- if .Values.watchNamespacesAgent }}
66+
- name: DD_AGENT_WATCH_NAMESPACE
67+
value: {{ .Values.watchNamespacesAgent | join "," }}
68+
{{- end }}
69+
{{- if .Values.watchNamespacesMonitor }}
70+
- name: DD_MONITOR_WATCH_NAMESPACE
71+
value: {{ .Values.watchNamespacesMonitor | join "," }}
72+
{{- end }}
73+
{{- if .Values.watchNamespacesSLO }}
74+
- name: DD_SLO_WATCH_NAMESPACE
75+
value: {{ .Values.watchNamespacesSLO | join "," }}
76+
{{- end }}
77+
{{- if .Values.watchNamespacesAgentProfile }}
78+
- name: DD_AGENT_PROFILE_WATCH_NAMESPACE
79+
value: {{ .Values.watchNamespacesAgentProfile | join "," }}
80+
{{- end }}
6581
- name: POD_NAME
6682
valueFrom:
6783
fieldRef:

charts/datadog-operator/values.yaml

+49
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ podLabels: {}
157157
collectOperatorMetrics: true
158158

159159
# watchNamespaces -- Restricts the Operator to watch its managed resources on specific namespaces
160+
# unless CRD-specific watchNamespaces properties are set
160161
watchNamespaces: []
161162
# example: watch only two namespaces:
162163
# watchNamespaces:
@@ -167,6 +168,54 @@ watchNamespaces: []
167168
# watchNamespaces:
168169
# - ""
169170

171+
# watchNamespacesAgent -- Restricts the Operator to watch DatadogAgent resources on specific namespaces.
172+
# Requires v1.8.0+
173+
watchNamespacesAgent: []
174+
# example: watch only two namespaces:
175+
# watchNamespacesAgent:
176+
# - "default"
177+
# - "datadog"
178+
#
179+
# to watch all namespaces
180+
# watchNamespacesAgent:
181+
# - ""
182+
183+
# watchNamespacesMonitor -- Restricts the Operator to watch DatadogMonitor resources on specific namespaces.
184+
# Requires v1.8.0+
185+
watchNamespacesMonitor: []
186+
# example: watch only two namespaces:
187+
# watchNamespacesMonitor:
188+
# - "default"
189+
# - "datadog"
190+
#
191+
# to watch all namespaces
192+
# watchNamespacesMonitor:
193+
# - ""
194+
195+
# watchNamespacesSLO -- Restricts the Operator to watch DatadogSLO resources on specific namespaces.
196+
# Requires v1.8.0+
197+
watchNamespacesSLO: []
198+
# example: watch only two namespaces:
199+
# watchNamespacesSLO:
200+
# - "default"
201+
# - "datadog"
202+
#
203+
# to watch all namespaces
204+
# watchNamespacesSLO:
205+
# - ""
206+
207+
# watchNamespacesAgentProfile -- Restricts the Operator to watch DatadogAgentProfile resources on specific namespaces.
208+
# Requires v1.8.0+
209+
watchNamespacesAgentProfile: []
210+
# example: watch only two namespaces:
211+
# watchNamespacesAgentProfile:
212+
# - "default"
213+
# - "datadog"
214+
#
215+
# to watch all namespaces
216+
# watchNamespacesAgentProfile:
217+
# - ""
218+
170219
# containerSecurityContext -- A security context defines privileges and access control settings for a container.
171220
containerSecurityContext: {}
172221

test/datadog-operator/operator_deployment_test.go

+44
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ func Test_operator_chart(t *testing.T) {
8484
assertions: verifyLivenessProbeOverride,
8585
skipTest: SkipTest,
8686
},
87+
{
88+
name: "Watch namespaces correctly set",
89+
command: common.HelmCommand{
90+
ReleaseName: "datadog-operator",
91+
ChartPath: "../../charts/datadog-operator",
92+
ShowOnly: []string{"templates/deployment.yaml"},
93+
Values: []string{"../../charts/datadog-operator/values.yaml"},
94+
Overrides: map[string]string{
95+
"watchNamespaces": "{common1,common2}",
96+
"watchNamespacesAgent": "{dda-ns}",
97+
"watchNamespacesMonitor": "{monitor-ns}",
98+
"watchNamespacesSLO": "{}",
99+
},
100+
},
101+
assertions: verifyWatchNamespaces,
102+
skipTest: SkipTest,
103+
},
87104
}
88105

89106
for _, tt := range tests {
@@ -131,3 +148,30 @@ func verifyLivenessProbeOverride(t *testing.T, manifest string) {
131148
assert.Equal(t, int32(20), operatorContainer.LivenessProbe.TimeoutSeconds)
132149
assert.Equal(t, int32(3), operatorContainer.LivenessProbe.FailureThreshold)
133150
}
151+
152+
func verifyWatchNamespaces(t *testing.T, manifest string) {
153+
var deployment appsv1.Deployment
154+
common.Unmarshal(t, manifest, &deployment)
155+
assert.Equal(t, 1, len(deployment.Spec.Template.Spec.Containers))
156+
operatorContainer := deployment.Spec.Template.Spec.Containers[0]
157+
watchNsEnv := FindEnvVarByName(operatorContainer.Env, "WATCH_NAMESPACE")
158+
agentNsEnv := FindEnvVarByName(operatorContainer.Env, "DD_AGENT_WATCH_NAMESPACE")
159+
monitorNsEnv := FindEnvVarByName(operatorContainer.Env, "DD_MONITOR_WATCH_NAMESPACE")
160+
sloNsEnv := FindEnvVarByName(operatorContainer.Env, "DD_SLO_WATCH_NAMESPACE")
161+
dapNsEnv := FindEnvVarByName(operatorContainer.Env, "DD_AGENT_PROFILE_WATCH_NAMESPACE")
162+
163+
assert.Equal(t, "common1,common2", watchNsEnv.Value)
164+
assert.Equal(t, "dda-ns", agentNsEnv.Value)
165+
assert.Equal(t, "monitor-ns", monitorNsEnv.Value)
166+
assert.Equal(t, "", sloNsEnv.Value)
167+
assert.Nil(t, dapNsEnv)
168+
}
169+
170+
func FindEnvVarByName(envs []v1.EnvVar, name string) *v1.EnvVar {
171+
for i, env := range envs {
172+
if env.Name == name {
173+
return &envs[i]
174+
}
175+
}
176+
return nil
177+
}

0 commit comments

Comments
 (0)