Skip to content

Commit

Permalink
Adding extra pod labels to post-upgrade and post-delete hook job pods (
Browse files Browse the repository at this point in the history
…#46029)

* Adding extra pod labels to post-upgrade and post-delete hook job pods

* Update examples/chart/teleport-kube-agent/templates/delete_hook.yaml

Co-authored-by: Tiago Silva <tiago.silva@goteleport.com>

* Update snapshot to include app label in delete hook job

* Correct snapshot app label to be in delete hook job, not the role

* Correct snapshot app label to be in spec metadata

* Adding a test for extraLabels.pod

* Adding back hook.yaml

---------

Co-authored-by: Matt Brock <mattbrock@Matts-MBP.attlocal.net>
Co-authored-by: Tiago Silva <tiago.silva@goteleport.com>
  • Loading branch information
3 people authored Sep 4, 2024
1 parent 3dd8f3f commit c128c3a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
9 changes: 9 additions & 0 deletions examples/chart/teleport-kube-agent/templates/delete_hook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ spec:
template:
metadata:
name: {{ .Release.Name }}-delete-hook
{{- if .Values.annotations.pod }}
annotations:
{{- toYaml .Values.annotations.pod | nindent 8 }}
{{- end }}
labels:
app: {{ .Release.Name }}
{{- if .Values.extraLabels.pod }}
{{- toYaml .Values.extraLabels.pod | nindent 8 }}
{{- end }}
spec:
{{- if .Values.imagePullSecrets }}
imagePullSecrets:
Expand Down
9 changes: 9 additions & 0 deletions examples/chart/teleport-kube-agent/templates/hook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ spec:
template:
metadata:
name: {{ .Release.Name }}-hook
{{- if .Values.annotations.pod }}
annotations:
{{- toYaml .Values.annotations.pod | nindent 8 }}
{{- end }}
labels:
app: {{ .Release.Name }}
{{- if .Values.extraLabels.pod }}
{{- toYaml .Values.extraLabels.pod | nindent 8 }}
{{- end }}
spec:
{{- if .Values.priorityClassName }}
priorityClassName: {{ .Values.priorityClassName }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ should not create ServiceAccount for post-delete hook if serviceAccount.create i
spec:
template:
metadata:
labels:
app: RELEASE-NAME
name: RELEASE-NAME-delete-hook
spec:
containers:
Expand Down
18 changes: 18 additions & 0 deletions examples/chart/teleport-kube-agent/tests/job_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,21 @@ tests:
apiVersion: rbac.authorization.k8s.io/v1
- matchSnapshot:
path: spec.template.spec

- it: should contain pod labels in the Job's pod spec if extraLabels.pod is set
template: delete_hook.yaml
# documentIndex: 0=ServiceAccount 1=Role 2=RoleBinding 3=Job
documentIndex: 3
values:
- ../.lint/backwards-compatibility.yaml
set:
extraLabels:
pod:
testLabel: testValue
asserts:
- equal:
path: spec.template.metadata.labels
value:
app: RELEASE-NAME
testLabel: testValue

2 changes: 1 addition & 1 deletion examples/chart/teleport-kube-agent/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ extraLabels:
# extraLabels.job(object) -- are labels to set on the post-delete Job created by the chart.
job: {}
# extraLabels.pod(object) -- are labels to set on the Pods created by the
# Deployment or StatefulSet.
# Deployment, StatefulSet, or Job.
pod: {}
# extraLabels.podDisruptionBudget(object) -- are labels to set on the podDisruptionBudget.
podDisruptionBudget: {}
Expand Down

0 comments on commit c128c3a

Please sign in to comment.