Skip to content

Commit

Permalink
Merge pull request #53 from bouge/master
Browse files Browse the repository at this point in the history
fix: move annotations section inside metadata section [issue: #52]
  • Loading branch information
yorinasub17 authored Jan 7, 2020
2 parents 6f16e64 + 28544be commit 89bafa3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
8 changes: 4 additions & 4 deletions charts/k8s-service/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ metadata:
{{- toYaml .Values.serviceAccount.labels | nindent 4 }}
{{- end }}
{{- if .Values.serviceAccount.annotations }}
annotations:
{{ toYaml .Values.serviceAccount.annotations | indent 4 }}
{{- end }}
annotations:
{{ toYaml .Values.serviceAccount.annotations | indent 4 }}
{{- end }}
imagePullSecrets:
{{ toYaml .Values.imagePullSecrets | indent 2 }}
{{- end }}
{{- end }}
29 changes: 29 additions & 0 deletions test/k8s_service_service_account_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,32 @@ func TestK8SServiceServiceAccountOmitAutomountToken(t *testing.T) {
renderedServiceAccountTokenAutomountSetting := deployment.Spec.Template.Spec.AutomountServiceAccountToken
assert.Nil(t, renderedServiceAccountTokenAutomountSetting)
}

// Test that the Annotations of a service account are correctly rendered
func TestK8SServiceAccountAnnotationRendering(t *testing.T) {
t.Parallel()

serviceAccountAnnotationKey := "testAnnotation"
serviceAccountAnnotationValue := strings.ToLower(random.UniqueId())

helmChartPath, err := filepath.Abs(filepath.Join("..", "charts", "k8s-service"))
require.NoError(t, err)

// We make sure to pass in the linter_values.yaml values file, which we assume has all the required values defined.
// We then use SetValues to override all the defaults.
options := &helm.Options{
ValuesFiles: []string{filepath.Join("..", "charts", "k8s-service", "linter_values.yaml")},
SetValues: map[string]string{
"serviceAccount.name": "test",
"serviceAccount.create": "true",
"serviceAccount.annotations." + serviceAccountAnnotationKey: serviceAccountAnnotationValue,
},
}
out := helm.RenderTemplate(t, options, helmChartPath, []string{"templates/serviceaccount.yaml"})

// We take the output and render it to a map to validate it has the annotations desired
rendered := map[string]interface{}{}
err = yaml.Unmarshal([]byte(out), &rendered)
assert.NoError(t, err)
assert.Equal(t, serviceAccountAnnotationValue, rendered["metadata"].(map[string]interface{})["annotations"].(map[string]interface{})[serviceAccountAnnotationKey])
}

0 comments on commit 89bafa3

Please sign in to comment.