Skip to content

Commit

Permalink
[APMON-406] Set Datadog namespace env variable on Cluster Agent (#1012)
Browse files Browse the repository at this point in the history
* [APMON-406] Set env variable for the Datadog resources namespace

* DCA namespace resources env var added for V2

---------

Co-authored-by: julia-elsammak <[email protected]>
Co-authored-by: Julia-elsammak <[email protected]>
  • Loading branch information
3 people authored Dec 18, 2023
1 parent 0412bc8 commit 7934e9d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions apis/datadoghq/common/envvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const (
DDKubeletCAPath = "DD_KUBELET_CLIENT_CA"
DDKubeletHost = "DD_KUBERNETES_KUBELET_HOST"
DDKubeletTLSVerify = "DD_KUBELET_TLS_VERIFY"
DDKubeResourcesNamespace = "DD_KUBE_RESOURCES_NAMESPACE"
DDKubeStateMetricsCoreConfigMap = "DD_KUBE_STATE_METRICS_CORE_CONFIGMAP_NAME"
DDKubeStateMetricsCoreEnabled = "DD_KUBE_STATE_METRICS_CORE_ENABLED"
DDLeaderElection = "DD_LEADER_ELECTION"
Expand Down
5 changes: 3 additions & 2 deletions controllers/datadogagent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ import (
)

const (
testDdaName = "foo"
agentConfigFile = "/etc/datadog-agent/datadog.yaml"
testDdaName = "foo"
testDdaNamespace = "bar"
agentConfigFile = "/etc/datadog-agent/datadog.yaml"
)

func apiKeyValue() *corev1.EnvVarSource {
Expand Down
4 changes: 4 additions & 0 deletions controllers/datadogagent/clusteragent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ func clusterAgentDefaultEnvVars() []corev1.EnvVar {
Name: "DD_CLUSTER_AGENT_TOKEN_NAME",
Value: fmt.Sprintf("%stoken", testDdaName),
},
{
Name: "DD_KUBE_RESOURCES_NAMESPACE",
Value: testDdaNamespace,
},
}
}

Expand Down
4 changes: 4 additions & 0 deletions controllers/datadogagent/component/clusteragent/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ func defaultEnvVars(dda metav1.Object) []corev1.EnvVar {
Name: apicommon.DDClusterAgentKubeServiceName,
Value: GetClusterAgentServiceName(dda),
},
{
Name: apicommon.DDKubeResourcesNamespace,
Value: utils.GetDatadogAgentResourceNamespace(dda),
},
{
Name: apicommon.DDLeaderElection,
Value: "true",
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/utils/shared_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func GetDatadogLeaderElectionResourceName(dda metav1.Object) string {
return fmt.Sprintf("%s-leader-election", dda.GetName())
}

// GetDatadogAgentResourceNamespace returns the namespace of the Datadog Agent Resource
func GetDatadogAgentResourceNamespace(dda metav1.Object) string {
return dda.GetNamespace()
}

// GetDatadogTokenResourceName returns the name of the ConfigMap used by the cluster agent to store token
func GetDatadogTokenResourceName(dda metav1.Object) string {
return fmt.Sprintf("%stoken", dda.GetName())
Expand Down

0 comments on commit 7934e9d

Please sign in to comment.