From 30764ceb2cd50491dd83fc6c7f368d6852dbabc9 Mon Sep 17 00:00:00 2001 From: Alexander Dejanovski Date: Mon, 2 Oct 2023 09:33:18 +0200 Subject: [PATCH 1/3] 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] From faa5948cf2a876a293dc965ba36a8c62c00260e8 Mon Sep 17 00:00:00 2001 From: Alexander Dejanovski Date: Mon, 2 Oct 2023 10:08:30 +0200 Subject: [PATCH 2/3] Add changelog entry --- CHANGELOG.md | 2 ++ config/manager/image_config.yaml | 2 +- config/manager/kustomization.yaml | 2 +- pkg/reconciliation/construct_podtemplatespec_test.go | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0d94f05..44d97332 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ Changelog for Cass Operator, new PRs should update the `main / unreleased` secti ## unreleased +* [CHANGE] [#573](https://github.com/k8ssandra/cass-operator/issues/573) Add the namespace as env variable in the server-system-logger container to label metrics with. + ## v1.17.2 * [ENHANCEMENT] [#571](https://github.com/k8ssandra/cass-operator/issues/571) Ensure both "server-config-init" as well as "server-config-init-base" are always created in the initContainers if 4.1.x is used. diff --git a/config/manager/image_config.yaml b/config/manager/image_config.yaml index 115e9cd1..27a78f66 100644 --- a/config/manager/image_config.yaml +++ b/config/manager/image_config.yaml @@ -3,7 +3,7 @@ kind: ImageConfig metadata: name: image-config images: - system-logger: "k8ssandra/system-logger:latest" + system-logger: "k8ssandra/system-logger:v1.18.0-dev.30764ce-20231002" config-builder: "datastax/cass-config-builder:1.0-ubi7" k8ssandra-client: "k8ssandra/k8ssandra-client:v0.2.0" # cassandra: diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 7621efda..75978fd5 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -14,4 +14,4 @@ kind: Kustomization images: - name: controller newName: k8ssandra/cass-operator - newTag: latest + newTag: v1.18.0-dev.30764ce-20231002 diff --git a/pkg/reconciliation/construct_podtemplatespec_test.go b/pkg/reconciliation/construct_podtemplatespec_test.go index 7d44858d..4a9bf76a 100644 --- a/pkg/reconciliation/construct_podtemplatespec_test.go +++ b/pkg/reconciliation/construct_podtemplatespec_test.go @@ -482,7 +482,7 @@ func TestLoggerContainerEnvVars(t *testing.T) { loggerContainer := findContainer(templateSpec.Spec.Containers, SystemLoggerContainerName) assert.Equal(SystemLoggerContainerName, loggerContainer.Name) - assert.Equal(5, len(loggerContainer.Env)) + assert.Equal(6, len(loggerContainer.Env)) assert.True(envVarsContains(loggerContainer.Env, podNameEnvVar)) assert.True(envVarsContains(loggerContainer.Env, nodeNameEnvVar)) From 7e210b0576d5c1bd26133ffbc8bbdd1e8d0f5a0e Mon Sep 17 00:00:00 2001 From: Alexander Dejanovski Date: Mon, 2 Oct 2023 14:11:08 +0200 Subject: [PATCH 3/3] Address Michael's comment --- config/manager/image_config.yaml | 2 +- config/manager/kustomization.yaml | 2 +- pkg/reconciliation/construct_podtemplatespec.go | 2 +- pkg/reconciliation/construct_podtemplatespec_test.go | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/config/manager/image_config.yaml b/config/manager/image_config.yaml index 27a78f66..115e9cd1 100644 --- a/config/manager/image_config.yaml +++ b/config/manager/image_config.yaml @@ -3,7 +3,7 @@ kind: ImageConfig metadata: name: image-config images: - system-logger: "k8ssandra/system-logger:v1.18.0-dev.30764ce-20231002" + system-logger: "k8ssandra/system-logger:latest" config-builder: "datastax/cass-config-builder:1.0-ubi7" k8ssandra-client: "k8ssandra/k8ssandra-client:v0.2.0" # cassandra: diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 75978fd5..7621efda 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -14,4 +14,4 @@ kind: Kustomization images: - name: controller newName: k8ssandra/cass-operator - newTag: v1.18.0-dev.30764ce-20231002 + newTag: latest 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) {