diff --git a/pkg/reconciliation/construct_podtemplatespec.go b/pkg/reconciliation/construct_podtemplatespec.go index bbea88a4..0ab215bc 100644 --- a/pkg/reconciliation/construct_podtemplatespec.go +++ b/pkg/reconciliation/construct_podtemplatespec.go @@ -710,7 +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}, + {Name: "NAMESPACE", ValueFrom: selectorFromFieldPath("metadata.namespace")}, } loggerContainer.Env = combineEnvSlices(loggerEnvDefaults, loggerContainer.Env) diff --git a/pkg/reconciliation/construct_podtemplatespec_test.go b/pkg/reconciliation/construct_podtemplatespec_test.go index 4a9bf76a..6e923ccd 100644 --- a/pkg/reconciliation/construct_podtemplatespec_test.go +++ b/pkg/reconciliation/construct_podtemplatespec_test.go @@ -461,6 +461,7 @@ func TestLoggerContainerEnvVars(t *testing.T) { podNameEnvVar := corev1.EnvVar{Name: "POD_NAME", ValueFrom: selectorFromFieldPath("metadata.name")} nodeNameEnvVar := corev1.EnvVar{Name: "NODE_NAME", ValueFrom: selectorFromFieldPath("spec.nodeName")} rackNameEnvVar := corev1.EnvVar{Name: "RACK_NAME", ValueFrom: selectorFromFieldPath("metadata.labels['cassandra.datastax.com/rack']")} + namespaceEnvVar := corev1.EnvVar{Name: "NAMESPACE", ValueFrom: selectorFromFieldPath("metadata.namespace")} templateSpec := &corev1.PodTemplateSpec{} dc := &api.CassandraDatacenter{ @@ -487,9 +488,9 @@ func TestLoggerContainerEnvVars(t *testing.T) { assert.True(envVarsContains(loggerContainer.Env, podNameEnvVar)) assert.True(envVarsContains(loggerContainer.Env, nodeNameEnvVar)) assert.True(envVarsContains(loggerContainer.Env, rackNameEnvVar)) + assert.True(envVarsContains(loggerContainer.Env, namespaceEnvVar)) 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) {