From 30764ceb2cd50491dd83fc6c7f368d6852dbabc9 Mon Sep 17 00:00:00 2001 From: Alexander Dejanovski Date: Mon, 2 Oct 2023 09:33:18 +0200 Subject: [PATCH] Add namespace label on metrics --- pkg/reconciliation/construct_podtemplatespec.go | 1 + pkg/reconciliation/construct_podtemplatespec_test.go | 1 + tests/testdata/configs/vector-config.yaml | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/pkg/reconciliation/construct_podtemplatespec.go b/pkg/reconciliation/construct_podtemplatespec.go index 6abf799f..bbea88a4 100644 --- a/pkg/reconciliation/construct_podtemplatespec.go +++ b/pkg/reconciliation/construct_podtemplatespec.go @@ -710,6 +710,7 @@ func buildContainers(dc *api.CassandraDatacenter, baseTemplate *corev1.PodTempla {Name: "CLUSTER_NAME", Value: dc.Spec.ClusterName}, {Name: "DATACENTER_NAME", Value: dc.DatacenterName()}, {Name: "RACK_NAME", ValueFrom: selectorFromFieldPath("metadata.labels['cassandra.datastax.com/rack']")}, + {Name: "NAMESPACE", Value: dc.Namespace}, } loggerContainer.Env = combineEnvSlices(loggerEnvDefaults, loggerContainer.Env) diff --git a/pkg/reconciliation/construct_podtemplatespec_test.go b/pkg/reconciliation/construct_podtemplatespec_test.go index b9886b94..7d44858d 100644 --- a/pkg/reconciliation/construct_podtemplatespec_test.go +++ b/pkg/reconciliation/construct_podtemplatespec_test.go @@ -489,6 +489,7 @@ func TestLoggerContainerEnvVars(t *testing.T) { assert.True(envVarsContains(loggerContainer.Env, rackNameEnvVar)) assert.True(envVarsContains(loggerContainer.Env, corev1.EnvVar{Name: "CLUSTER_NAME", Value: dc.Spec.ClusterName})) assert.True(envVarsContains(loggerContainer.Env, corev1.EnvVar{Name: "DATACENTER_NAME", Value: dc.DatacenterName()})) + assert.True(envVarsContains(loggerContainer.Env, corev1.EnvVar{Name: "NAMESPACE", Value: dc.Namespace})) } func TestCassandraDatacenter_buildContainers_override_other_containers(t *testing.T) { diff --git a/tests/testdata/configs/vector-config.yaml b/tests/testdata/configs/vector-config.yaml index 6f11dda4..2cf74ad3 100644 --- a/tests/testdata/configs/vector-config.yaml +++ b/tests/testdata/configs/vector-config.yaml @@ -50,6 +50,11 @@ data: if err == null { .rack = rack } + + namespace, err = get_env_var("NAMESPACE") + if err == null { + .namespace = namespace + } ''' [sinks.console]