Skip to content

Commit

Permalink
charts/karmada: automatically clean up the static-resource Job after …
Browse files Browse the repository at this point in the history
…it completes
  • Loading branch information
iawia002 committed Aug 28, 2024
1 parent 295dee8 commit 84fedfc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions charts/karmada/templates/karmada-static-resource-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ metadata:
spec:
parallelism: 1
completions: 1
{{- if semverCompare ">=1.23.0-0" .Capabilities.KubeVersion.GitVersion }}
ttlSecondsAfterFinished: {{ .Values.staticResourceJob.ttlSecondsAfterFinished }}
{{- end }}
template:
metadata:
name: {{ $name }}
Expand Down
6 changes: 4 additions & 2 deletions charts/karmada/templates/post-install-job.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if semverCompare "<1.23.0-0" .Capabilities.KubeVersion.GitVersion }}
{{- $name := include "karmada.name" . -}}
{{- $namespace := include "karmada.namespace" . -}}
{{- if eq .Values.installMode "host" }}
Expand Down Expand Up @@ -51,8 +52,8 @@ spec:
bash <<'EOF'
set -ex
# The `post-install hook job` may be applied before all karmada components are ready that rely on `static-resource job` and `hook-job secret`.
# So, we have to postpone the deletion of the `static-resource job` and `hook-job secret` until all karmada components are up and running.
# The `post-install hook job` may be applied before all karmada components are ready that rely on `static-resource job`.
# So, we have to postpone the deletion of the `static-resource job` until all karmada components are up and running.
while [[ $(kubectl get pods -n {{ $namespace }} --field-selector=status.phase!=Running,status.phase!=Succeeded -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | grep -v static-resource | wc -l) > 0 ]];
do
echo "waiting for all pods of karmada control plane ready..."; sleep 1;
Expand All @@ -61,3 +62,4 @@ spec:
kubectl delete job {{ $name }}-static-resource -n {{ $namespace }}
EOF
{{- end }}
{{- end }}
3 changes: 3 additions & 0 deletions charts/karmada/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ preInstallJob:
staticResourceJob:
tolerations: []
nodeSelector: {}
## Set a TTL for the static-resource Job, the Job will be automatically cleaned up after this time.
## This only works on Kubernetes version 1.23 or higher.
ttlSecondsAfterFinished: 10

## post-install job config
postInstallJob:
Expand Down

0 comments on commit 84fedfc

Please sign in to comment.