Skip to content

Commit

Permalink
Added custom service account annotations test (#3803)
Browse files Browse the repository at this point in the history
  • Loading branch information
chan-tim-sumo authored Jul 18, 2024
1 parent 8c9a6bf commit 2ea0cff
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 1 deletion.
1 change: 1 addition & 0 deletions .changelog/3803.changed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test: Added custom service account annotation tests for global configuration attributes
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
52 changes: 51 additions & 1 deletion tests/helm/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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,
)
}
}
}
4 changes: 4 additions & 0 deletions tests/helm/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ sumologic:
customLabelKey: customLabelValue
podAnnotations:
customAnnotationsKey: customAnnotationsValue
serviceAccount:
annotations:
customServiceAccountAnnotationKey: customServiceAccountAnnotationValue

kube-prometheus-stack:
kube-state-metrics:
Expand Down

0 comments on commit 2ea0cff

Please sign in to comment.