diff --git a/.changelog/3803.changed.txt b/.changelog/3803.changed.txt new file mode 100644 index 0000000000..e22c905c98 --- /dev/null +++ b/.changelog/3803.changed.txt @@ -0,0 +1 @@ +test: Added custom service account annotation tests for global configuration attributes \ No newline at end of file diff --git a/deploy/helm/sumologic/templates/logs/collector/common/serviceaccount.yaml b/deploy/helm/sumologic/templates/logs/collector/common/serviceaccount.yaml index e4279a7547..65a374fa94 100644 --- a/deploy/helm/sumologic/templates/logs/collector/common/serviceaccount.yaml +++ b/deploy/helm/sumologic/templates/logs/collector/common/serviceaccount.yaml @@ -7,6 +7,10 @@ metadata: labels: app: {{ template "sumologic.labels.app.logs.collector.serviceaccount" . }} {{- include "sumologic.labels.common" . | nindent 4 }} + {{- if .Values.sumologic.serviceAccount.annotations }} + annotations: + {{ toYaml .Values.sumologic.serviceAccount.annotations | indent 2 }} + {{- end }} {{- if .Values.sumologic.pullSecrets }} imagePullSecrets: {{ toYaml .Values.sumologic.pullSecrets | indent 2 }} diff --git a/deploy/helm/sumologic/templates/metrics/collector/otelcol/serviceaccount-targetallocator.yaml b/deploy/helm/sumologic/templates/metrics/collector/otelcol/serviceaccount-targetallocator.yaml index 0e565e87f9..b3a14677ae 100644 --- a/deploy/helm/sumologic/templates/metrics/collector/otelcol/serviceaccount-targetallocator.yaml +++ b/deploy/helm/sumologic/templates/metrics/collector/otelcol/serviceaccount-targetallocator.yaml @@ -7,6 +7,10 @@ metadata: labels: {{- include "sumologic.labels.metrics.serviceaccount" . | nindent 4 }} {{- include "sumologic.labels.common" . | nindent 4 }} + {{- if .Values.sumologic.serviceAccount.annotations }} + annotations: + {{ toYaml .Values.sumologic.serviceAccount.annotations | indent 2 }} + {{- end }} {{- if .Values.sumologic.pullSecrets }} imagePullSecrets: {{ toYaml .Values.sumologic.pullSecrets | indent 2 }} diff --git a/deploy/helm/sumologic/templates/metrics/collector/otelcol/serviceaccount.yaml b/deploy/helm/sumologic/templates/metrics/collector/otelcol/serviceaccount.yaml index 8646a2329d..0681f8ba38 100644 --- a/deploy/helm/sumologic/templates/metrics/collector/otelcol/serviceaccount.yaml +++ b/deploy/helm/sumologic/templates/metrics/collector/otelcol/serviceaccount.yaml @@ -7,6 +7,10 @@ metadata: labels: {{- include "sumologic.labels.metrics.serviceaccount" . | nindent 4 }} {{- include "sumologic.labels.common" . | nindent 4 }} + {{- if .Values.sumologic.serviceAccount.annotations }} + annotations: + {{ toYaml .Values.sumologic.serviceAccount.annotations | indent 2 }} + {{- end }} {{- if .Values.sumologic.pullSecrets }} imagePullSecrets: {{ toYaml .Values.sumologic.pullSecrets | indent 2 }} diff --git a/tests/helm/common_test.go b/tests/helm/common_test.go index ff347818fe..d8ed4f9a20 100644 --- a/tests/helm/common_test.go +++ b/tests/helm/common_test.go @@ -563,7 +563,7 @@ func TestServiceAccountPullSecrets(t *testing.T) { // tests podLabels and podAnnotations func TestCustomPodData(t *testing.T) { t.Parallel() - valuesFilePath := path.Join(testDataDirectory, "custom-podData.yaml") + valuesFilePath := path.Join(testDataDirectory, "custom-global-config-attributes.yaml") renderedYamlString := RenderTemplate( t, &helm.Options{ @@ -642,3 +642,53 @@ func TestCustomPodData(t *testing.T) { ) } } + +func TestCustomServiceAccountAnnotations(t *testing.T) { + t.Parallel() + valuesFilePath := path.Join(testDataDirectory, "custom-global-config-attributes.yaml") + renderedYamlString := RenderTemplate( + t, + &helm.Options{ + ValuesFiles: []string{valuesFilePath}, + SetStrValues: map[string]string{ + "sumologic.accessId": "accessId", + "sumologic.accessKey": "accessKey", + }, + Logger: logger.Discard, // the log output is noisy and doesn't help much + }, + chartDirectory, + releaseName, + []string{}, + true, + "--namespace", + defaultNamespace, + ) + + renderedObjects, err := UnmarshalMultipleK8sObjectsFromYaml(renderedYamlString) + require.NoError(t, err) + + for _, object := range renderedObjects { + kind := object.GetObjectKind().GroupVersionKind().Kind + if kind != "ServiceAccount" { + continue + } + serviceAccount := object.(*corev1.ServiceAccount) + if isSubchartObject(serviceAccount) { + continue + } + + for key, expectedValue := range expectedAnnotations { + actualValue, exists := serviceAccount.Annotations[key] + require.True(t, exists, "Annotation %s not found in service account %s", key, serviceAccount.Name) + + assert.Equal( + t, + expectedValue, + actualValue, + "Annotation %s value mismatch in service account %s", + key, + serviceAccount.Name, + ) + } + } +} diff --git a/tests/helm/const.go b/tests/helm/const.go index f93336c113..c43b3e027d 100644 --- a/tests/helm/const.go +++ b/tests/helm/const.go @@ -36,6 +36,10 @@ var subChartNames []string = []string{ "opentelemetry-operator", } +var expectedAnnotations = map[string]string{ + "customServiceAccountAnnotationKey": "customServiceAccountAnnotationValue", +} + var toleration = corev1.Toleration{ Key: "key", Value: "value", diff --git a/tests/helm/testdata/custom-podData.yaml b/tests/helm/testdata/custom-global-config-attributes.yaml similarity index 91% rename from tests/helm/testdata/custom-podData.yaml rename to tests/helm/testdata/custom-global-config-attributes.yaml index fb89222eb0..864e18330f 100644 --- a/tests/helm/testdata/custom-podData.yaml +++ b/tests/helm/testdata/custom-global-config-attributes.yaml @@ -7,6 +7,9 @@ sumologic: customLabelKey: customLabelValue podAnnotations: customAnnotationsKey: customAnnotationsValue + serviceAccount: + annotations: + customServiceAccountAnnotationKey: customServiceAccountAnnotationValue kube-prometheus-stack: kube-state-metrics: