Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(integration): Added custom service account annotations test #3803

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }}
Copy link
Contributor

@rnishtala-sumo rnishtala-sumo Jul 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the values.yaml already updated with this key? Also we probably need this for other resources that have service accounts too.

{{- 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
Loading