Skip to content

Commit 3ab9b21

Browse files
lee-bainesclaude
andcommitted
Add dynamic Job naming and TTL increase
Add dynamic Job name suffixes to Kubernetes Jobs due to immutable jobs causing Helm upgrade failures. Inrease ttlSecondsAfterFinished to 43200s to allow for troubleshooting now that Jobs no longer require deleting. Adds a CHANGELOG entries under "New Features/Updated functionality" describing the Release.Revision suffix applied to all three Helm Job names and the ttlSecondsAfterFinished increase to 43200 s (12 h). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b766053 commit 3ab9b21

8 files changed

Lines changed: 48 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,18 @@ You can now pass a values file to `forgeops prereqs` for cert-manager and
4343
ingress. This allows users to provide extra values as needed. See `forgeops
4444
prereqs -h` for more info.
4545

46+
### Increased TTL for Kubernetes jobs (Helm only)
47+
48+
The default `ttlSecondsAfterFinished` for all three jobs has been increased from 7200s
49+
(2 hours) to 43200s (12 hours), giving more time to inspect completed or failed jobs
50+
before they are automatically cleaned up.
51+
4652
## Bugfixes
4753

48-
## How-tos
54+
### Dynamic Kubernetes job naming (Helm only)
4955

56+
The `amster`, `ds-set-passwords`, and `keystore-create` Kubernetes job names in the
57+
`identity-platform` Helm chart now include the Helm release revision as a suffix
58+
(e.g. `amster-3`, `ds-set-passwords-3`, `keystore-create-3`). This ensures each
59+
`helm upgrade` produces a distinct job name, preventing failures caused by Kubernetes'
60+
immutability constraint on existing jobs.

bin/commands/wait

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,31 @@ waitResourceExists() {
102102
timeoutExit
103103
}
104104

105+
# Returns the name of the most recently created amster Job, polling until one exists.
106+
# Progress messages go to stderr so stdout carries only the job name for capture.
107+
getLatestAmsterJob() {
108+
local start_time=$(date +%s)
109+
local now=$(date +%s)
110+
local job_name
111+
112+
echo -n "Waiting for amster Job to exist..." >&2
113+
while [ $(($now - $start_time)) -le $TIMEOUT ] ; do
114+
job_name=$($K_GET jobs -l app.kubernetes.io/component=amster \
115+
--sort-by=.metadata.creationTimestamp \
116+
-o jsonpath='{.items[-1].metadata.name}' 2>/dev/null)
117+
if [ -n "$job_name" ] ; then
118+
echo " $job_name" >&2
119+
echo "$job_name"
120+
return 0
121+
fi
122+
echo -n '.' >&2
123+
sleep 1
124+
now=$(date +%s)
125+
done
126+
127+
timeoutExit
128+
}
129+
105130
waitForDS() {
106131
local ds=$1
107132

@@ -160,12 +185,14 @@ for c in ${COMPONENTS[@]} ; do
160185
;;
161186

162187
amster)
163-
waitForResource 'complete' job/amster
188+
amster_job=$(getLatestAmsterJob)
189+
waitForResource 'complete' "job/${amster_job}"
164190
;;
165191

166192
apps)
167193
waitForResource ready "pod -l app=am"
168-
waitForResource 'complete' job/amster
194+
amster_job=$(getLatestAmsterJob)
195+
waitForResource 'complete' "job/${amster_job}"
169196
waitForResource ready "pod -l app=idm"
170197
;;
171198

charts/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,3 @@ $ helm upgrade identity-platform . \
5757
```bash
5858
$ helm delete identity-platform -n identity-platform
5959
```
60-

charts/identity-platform/templates/amster-job.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
apiVersion: batch/v1
33
kind: Job
44
metadata:
5-
name: amster
5+
name: amster-{{ .Release.Revision }}
66
annotations:
77
"helm.sh/hook": post-install,post-upgrade
88
{{- if .Values.amster.deleteOnSuccess }}

charts/identity-platform/templates/ds-set-passwords-job.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
apiVersion: batch/v1
33
kind: Job
44
metadata:
5-
name: ds-set-passwords
5+
name: ds-set-passwords-{{ .Release.Revision }}
66
labels:
77
{{- include "identity-platform.labels" . | nindent 4 }}
88
{{- with .Values.ds_set_passwords.podLabels }}

charts/identity-platform/templates/keystore-create-job.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
apiVersion: batch/v1
33
kind: Job
44
metadata:
5-
name: keystore-create
5+
name: keystore-create-{{ .Release.Revision }}
66
labels:
77
{{- include "identity-platform.labels" . | nindent 4 }}
88
{{- with .Values.keystore_create.podLabels }}

charts/identity-platform/values.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ amster:
301301
backoffLimit: 6
302302
restartPolicy: OnFailure
303303
deleteOnSuccess: false
304-
ttlSecondsAfterFinished: 7200
304+
ttlSecondsAfterFinished: 43200
305305

306306
image:
307307
repository: us-docker.pkg.dev/forgeops-public/images/amster
@@ -350,7 +350,7 @@ ds_set_passwords:
350350
force: false
351351
backoffLimit: 6
352352
restartPolicy: OnFailure
353-
ttlSecondsAfterFinished: 7200
353+
ttlSecondsAfterFinished: 43200
354354

355355
image:
356356
repository: us-docker.pkg.dev/forgeops-public/images/ds
@@ -499,7 +499,7 @@ keystore_create:
499499
backoffLimit: 6
500500
restartPolicy: OnFailure
501501
deleteOnSuccess: false
502-
ttlSecondsAfterFinished: 7200
502+
ttlSecondsAfterFinished: 43200
503503
clusterRoleName: identity-platform-keystore-create
504504
appendNSToRole: true
505505

lib/python/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ def get_secret_value(ns, secret, key):
503503
# Clean up amster resources.
504504
def clean_amster_job(ns):
505505
message(f'Cleaning up amster components.')
506-
run('kubectl', f'-n {ns} delete --ignore-not-found=true job amster')
506+
run('kubectl', f'-n {ns} delete --ignore-not-found=true job -l app.kubernetes.io/component=amster')
507507
run('kubectl', f'-n {ns} delete --wait=true --ignore-not-found=true cm amster-scripts')
508508
run('kubectl', f'-n {ns} delete --wait=true --ignore-not-found=true cm amster-function')
509509
run('kubectl', f'-n {ns} delete --wait=true --ignore-not-found=true cm amster-config')

0 commit comments

Comments
 (0)