Skip to content

Commit 8779976

Browse files
committed
fix: backport serviceAccount manifest from helm.sh default
Signed-off-by: David Sabatie <[email protected]>
1 parent 215e33e commit 8779976

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

pkg/processor/pod/pod.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func processPodSpec(name string, appMeta helmify.AppMetadata, pod *corev1.PodSpe
222222
v.Secret.SecretName = appMeta.TemplatedName(v.Secret.SecretName)
223223
}
224224
}
225-
pod.ServiceAccountName = fmt.Sprintf("{{ default \"default\" (include \"%s.serviceAccountName\" .) }}", appMeta.ChartName())
225+
pod.ServiceAccountName = fmt.Sprintf(`{{ include "%s.serviceAccountName" . }}`, appMeta.ChartName())
226226

227227
for i, s := range pod.ImagePullSecrets {
228228
pod.ImagePullSecrets[i].Name = appMeta.TemplatedName(s.Name)

pkg/processor/pod/pod_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func Test_pod_Process(t *testing.T) {
170170
"tolerations": "{{- toYaml .Values.nginx.tolerations | nindent 8 }}",
171171
"topologySpreadConstraints": "{{- toYaml .Values.nginx.topologySpreadConstraints | nindent 8 }}",
172172
"nodeSelector": "{{- toYaml .Values.nginx.nodeSelector | nindent 8 }}",
173-
"serviceAccountName": "{{ default \"default\" (include \".serviceAccountName\" .) }}",
173+
"serviceAccountName": `{{ include ".serviceAccountName" . }}`,
174174
}, specMap)
175175

176176
assert.Equal(t, helmify.Values{
@@ -218,7 +218,7 @@ func Test_pod_Process(t *testing.T) {
218218
},
219219
},
220220
"nodeSelector": "{{- toYaml .Values.nginx.nodeSelector | nindent 8 }}",
221-
"serviceAccountName": "{{ default \"default\" (include \".serviceAccountName\" .) }}",
221+
"serviceAccountName": `{{ include ".serviceAccountName" . }}`,
222222
"tolerations": "{{- toYaml .Values.nginx.tolerations | nindent 8 }}",
223223
"topologySpreadConstraints": "{{- toYaml .Values.nginx.topologySpreadConstraints | nindent 8 }}",
224224
}, specMap)
@@ -264,7 +264,7 @@ func Test_pod_Process(t *testing.T) {
264264
},
265265
},
266266
"nodeSelector": "{{- toYaml .Values.nginx.nodeSelector | nindent 8 }}",
267-
"serviceAccountName": "{{ default \"default\" (include \".serviceAccountName\" .) }}",
267+
"serviceAccountName": `{{ include ".serviceAccountName" . }}`,
268268
"tolerations": "{{- toYaml .Values.nginx.tolerations | nindent 8 }}",
269269
"topologySpreadConstraints": "{{- toYaml .Values.nginx.topologySpreadConstraints | nindent 8 }}",
270270
}, specMap)
@@ -310,7 +310,7 @@ func Test_pod_Process(t *testing.T) {
310310
},
311311
},
312312
"nodeSelector": "{{- toYaml .Values.nginx.nodeSelector | nindent 8 }}",
313-
"serviceAccountName": "{{ default \"default\" (include \".serviceAccountName\" .) }}",
313+
"serviceAccountName": `{{ include ".serviceAccountName" . }}`,
314314
"tolerations": "{{- toYaml .Values.nginx.tolerations | nindent 8 }}",
315315
"topologySpreadConstraints": "{{- toYaml .Values.nginx.topologySpreadConstraints | nindent 8 }}",
316316
}, specMap)
@@ -351,7 +351,7 @@ func Test_pod_Process(t *testing.T) {
351351
},
352352
"securityContext": "{{- toYaml .Values.nginx.podSecurityContext | nindent 8 }}",
353353
"nodeSelector": "{{- toYaml .Values.nginx.nodeSelector | nindent 8 }}",
354-
"serviceAccountName": "{{ default \"default\" (include \".serviceAccountName\" .) }}",
354+
"serviceAccountName": `{{ include ".serviceAccountName" . }}`,
355355
"tolerations": "{{- toYaml .Values.nginx.tolerations | nindent 8 }}",
356356
"topologySpreadConstraints": "{{- toYaml .Values.nginx.topologySpreadConstraints | nindent 8 }}",
357357
}, specMap)

pkg/processor/rbac/serviceaccount.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ metadata:
1717
name: {{ include "%[1]s.serviceAccountName" . }}
1818
labels:
1919
{{- include "%[1]s.labels" . | nindent 4 }}
20+
{{- with .Values.serviceAccount.annotations }}
2021
annotations:
21-
{{- toYaml .Values.serviceAccount.annotations | nindent 4 }}
22+
{{- toYaml . | nindent 4 }}
23+
{{- end }}
24+
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
2225
{{- end }}`
2326
)
2427

@@ -43,6 +46,7 @@ func (sa serviceAccount) Process(appMeta helmify.AppMetadata, obj *unstructured.
4346
values := helmify.Values{}
4447
_, _ = values.Add(true, "serviceAccount", "create")
4548
_, _ = values.Add("", "serviceAccount", "name")
49+
_, _ = values.Add(true, "serviceAccount", "automount")
4650
valuesAnnotations := make(map[string]interface{})
4751
for k, v := range obj.GetAnnotations() {
4852
valuesAnnotations[k] = v

0 commit comments

Comments
 (0)