Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
3690f62
[patch] First pass at approach to pinning cli image tag
tomklapiscak Feb 5, 2025
dc22030
Attempt to standardise job name generation
tomklapiscak Feb 6, 2025
a5b829d
fix
tomklapiscak Feb 6, 2025
e85245c
set-cli-image-tag.sh helper script
tomklapiscak Feb 6, 2025
8da9670
remove comment
tomklapiscak Feb 6, 2025
d49cbe0
fix for darwin
tomklapiscak Feb 6, 2025
5f94108
fix comment
tomklapiscak Feb 6, 2025
6e17e92
WIP: verify-job-definitions.sh script
tomklapiscak Feb 6, 2025
9e4f0ff
improve job validation
tomklapiscak Feb 7, 2025
c8d45f6
improve validator
tomklapiscak Feb 7, 2025
e36f63f
wip: allow naming restrictions to be relaxed for certain files
tomklapiscak Feb 7, 2025
685f830
start updating jobs to conform to new requirements
tomklapiscak Feb 7, 2025
6c25808
allow relax-list to be specified in a config file
tomklapiscak Feb 7, 2025
87ec280
Merge remote-tracking branch 'origin/main' into mascore5516
tomklapiscak Feb 10, 2025
04e41ff
updating jobs...
tomklapiscak Feb 10, 2025
62abe6f
more jobs...
tomklapiscak Feb 10, 2025
a9a052d
check that there is valid reason for a given file to be on the relax …
tomklapiscak Feb 10, 2025
721d971
determine dynamically if a naming restrictions should be applied for …
tomklapiscak Feb 10, 2025
acd0b8c
... more jobs
tomklapiscak Feb 10, 2025
f77d6dd
improve job name: {{ $_jo _name }} validation using awk
tomklapiscak Feb 10, 2025
d2ddf5e
more jobs
tomklapiscak Feb 10, 2025
595bfdf
more jobs
tomklapiscak Feb 10, 2025
58d7b92
more jobs
tomklapiscak Feb 10, 2025
3e759f3
more jobs
tomklapiscak Feb 10, 2025
eeb8103
all jobs done
tomklapiscak Feb 10, 2025
140b614
fix
tomklapiscak Feb 11, 2025
728bac9
Add verify-job-definitions.sh to lint action
tomklapiscak Feb 11, 2025
bb1a113
deliberate make job invalid to check if action fails
tomklapiscak Feb 11, 2025
1abe890
deliberate invalidate another job
tomklapiscak Feb 11, 2025
233c11c
Revert "deliberate make job invalid to check if action fails"
tomklapiscak Feb 11, 2025
a4c0724
Revert "deliberate invalidate another job"
tomklapiscak Feb 11, 2025
17aebf7
testing cli_image_tag update
tomklapiscak Feb 11, 2025
8fbaa5a
Add pre-commit hook
tomklapiscak Feb 11, 2025
9922087
docs
tomklapiscak Feb 11, 2025
494d83b
docs
tomklapiscak Feb 11, 2025
dc99a7c
break jobs on purpose
tomklapiscak Feb 11, 2025
eeef018
break jobs on purpose
tomklapiscak Feb 11, 2025
eeece3b
beak jobs on purpose
tomklapiscak Feb 11, 2025
61f8773
fix jobs
tomklapiscak Feb 11, 2025
a02028e
set-cli-image-tag 13.4.0
tomklapiscak Feb 12, 2025
5504517
cli-image-tag 13.4.1
tomklapiscak Feb 12, 2025
c41736b
cli-image-tag 13.3.0
tomklapiscak Feb 12, 2025
08d94a6
cli-image-tag 13.2.0
tomklapiscak Feb 12, 2025
7c9db74
testing argocd.argoproj.io/sync-options: Replace=true behaviour
tomklapiscak Feb 12, 2025
ebd1ebc
testing update to immutable job field with replace=True
tomklapiscak Feb 12, 2025
a7d3cfe
add job label
tomklapiscak Feb 12, 2025
971367a
testing update to immutable job field with Replace = True
tomklapiscak Feb 12, 2025
603c7ca
experimenting with helm hook annotations instead
tomklapiscak Feb 12, 2025
9624bf4
test immutable field update with helm hook annots
tomklapiscak Feb 12, 2025
f818a11
Revert "test immutable field update with helm hook annots"
tomklapiscak Feb 12, 2025
913a602
test immutable job field update with helm hook annots
tomklapiscak Feb 12, 2025
b85a2a7
update to cli 13.4.1 ahead of tonight's fvtsaas run
tomklapiscak Feb 12, 2025
06d13d0
do helm hook jobs influence app health?
tomklapiscak Feb 12, 2025
f9e0efa
experiment with ttlSecondsAfterFinished approach
tomklapiscak Feb 13, 2025
7c99453
sync not creating job when updating with ttlSecondsAfterFinished, try…
tomklapiscak Feb 13, 2025
ede350f
remove ttlSecondsAfterFinished
tomklapiscak Feb 13, 2025
26784d9
try configmap-based approach to tracking current job name
tomklapiscak Feb 13, 2025
d3a7933
update cli image tag to test configmap approach
tomklapiscak Feb 13, 2025
2ce1f83
change label
tomklapiscak Feb 13, 2025
c186798
make some orphaned jobs for testing
tomklapiscak Feb 13, 2025
3b46758
make some orphaned jobs for testing
tomklapiscak Feb 13, 2025
f1dede6
add independent $_job_cleanup_group constant
tomklapiscak Feb 13, 2025
38215e4
establish some more job-cleanup-groups for testing
tomklapiscak Feb 13, 2025
adcd1e9
fix manage post sync db2 job
tomklapiscak Feb 13, 2025
eb3b20f
make some orphaned jobs for testing
tomklapiscak Feb 13, 2025
accd527
fix
tomklapiscak Feb 13, 2025
cee96d5
fix image name
tomklapiscak Feb 13, 2025
3354001
fix image name
tomklapiscak Feb 13, 2025
31037bd
testing cli-image-tag update in fvtsaas
tomklapiscak Feb 14, 2025
567f229
Merge branch 'mascore5516' into mascore5637
tomklapiscak Feb 17, 2025
bb36df7
remove unnecessary configmap
tomklapiscak Feb 17, 2025
58726f5
improve job validation script
tomklapiscak Feb 18, 2025
0eec38d
Add cleanup-group label to all relevant jobs
tomklapiscak Feb 18, 2025
71d8165
fix
tomklapiscak Feb 18, 2025
f1f884a
fix
tomklapiscak Feb 18, 2025
d14eb0f
fix
tomklapiscak Feb 18, 2025
d08e189
Add job-cleaner CronJob
tomklapiscak Feb 18, 2025
4ba4d26
fix
tomklapiscak Feb 18, 2025
eef21c0
fix
tomklapiscak Feb 18, 2025
4d8acba
fix
tomklapiscak Feb 18, 2025
55d4b0d
fix
tomklapiscak Feb 18, 2025
71c1d38
remove --dry-run
tomklapiscak Feb 18, 2025
7310491
update cli image tag to test job-cleaner
tomklapiscak Feb 18, 2025
8a1685f
ensure db2 postsync jobs land in different cleanup groups
tomklapiscak Feb 18, 2025
139e147
inc version to update label
tomklapiscak Feb 18, 2025
5e446ae
temporarily suspend job cleaner CronJob so we can run it once after u…
tomklapiscak Feb 21, 2025
3a19a89
testing cli image tag update in fvtsaas
tomklapiscak Feb 21, 2025
f187e24
re-enable job cleaner in fvtsaas
tomklapiscak Feb 21, 2025
9d0ff59
Merge remote-tracking branch 'origin/main' into mascore5637
tomklapiscak Feb 24, 2025
6d8720d
Merge remote-tracking branch 'origin/main' into mascore5516
tomklapiscak Feb 24, 2025
d9e16b6
Merge remote-tracking branch 'origin/mascore5516' into mascore5637
tomklapiscak Feb 24, 2025
b97d8c7
suspend job-cleaner so we can choose when to run it when testing on S…
tomklapiscak Feb 24, 2025
2bf687c
updating docs
tomklapiscak Feb 24, 2025
b8fee5f
doc updates
tomklapiscak Feb 24, 2025
c3ea9dd
Merge remote-tracking branch 'origin/main' into mascore5516
tomklapiscak Mar 3, 2025
3a25e87
update job with new conventions
tomklapiscak Mar 3, 2025
6551872
Merge remote-tracking branch 'origin/mascore5516' into mascore5637
tomklapiscak Mar 3, 2025
30227a9
update new job to conform to new conventions
tomklapiscak Mar 3, 2025
230ab6f
bump job version
tomklapiscak Mar 3, 2025
ae56c98
Merge remote-tracking branch 'origin/mascore5516' into mascore5637
tomklapiscak Mar 3, 2025
92ad4e5
Merge remote-tracking branch 'origin/main' into mascore5516
tomklapiscak Mar 3, 2025
4211dc7
Merge remote-tracking branch 'origin/mascore5516' into mascore5637
tomklapiscak Mar 3, 2025
65decff
Merge remote-tracking branch 'origin/main' into mascore5516
tomklapiscak Mar 4, 2025
4a4c906
update job to conform to new conventions
tomklapiscak Mar 4, 2025
2597b62
Merge remote-tracking branch 'origin/mascore5516' into mascore5637
tomklapiscak Mar 4, 2025
b0f4836
add cleanup_group, update _cli_image_tag
tomklapiscak Mar 4, 2025
eb146e1
resume job-cleaner for SRE staging test
tomklapiscak Mar 6, 2025
3d01573
update cli image tag for test in SRE staging
tomklapiscak Mar 6, 2025
f43a8a0
Merge remote-tracking branch 'origin/main' into mascore5516
tomklapiscak Mar 20, 2025
8c9d01f
Merge branch 'mascore5516' into mascore5637
tomklapiscak Mar 20, 2025
0d42df7
Merge branch 'main' into mascore5516
tomklapiscak Mar 27, 2025
9ada068
Merge remote-tracking branch 'origin/mascore5516' into mascore5637
tomklapiscak Mar 27, 2025
ee027f1
update CLI image tag
tomklapiscak Mar 28, 2025
5ec319f
Merge remote-tracking branch 'origin/main' into mascore5516
tomklapiscak Apr 3, 2025
99acca5
Merge branch 'mascore5516' into mascore5637
tomklapiscak Apr 3, 2025
206935f
Merge remote-tracking branch 'origin/main' into mascore5516
tomklapiscak Apr 3, 2025
c1b500b
Merge branch 'mascore5516' into mascore5637
tomklapiscak Apr 3, 2025
208f840
Merge remote-tracking branch 'origin/main' into mascore5516
tomklapiscak Apr 14, 2025
8bfdd54
Merge branch 'mascore5516' into mascore5637
tomklapiscak Apr 14, 2025
b15b39f
update to latest cli release
tomklapiscak Apr 15, 2025
0f7a89c
include CLI pre-release with tactical SAAS_MODE fix
tomklapiscak Apr 15, 2025
8716178
update to latest cli image tag (+ tactical fix) ahead of merge from m…
tomklapiscak Apr 15, 2025
8d21589
Merge branch 'mascore5516' into mascore5637
tomklapiscak Apr 15, 2025
0f1778a
use CLI pre-release that contains (unreleased) jobcleaner script
tomklapiscak Apr 15, 2025
d0399f2
job cleaner cronjob runs at 00:00 UTC (once every 24 hours)
tomklapiscak Apr 16, 2025
4fc5b18
update cli image tag
tomklapiscak Apr 17, 2025
ce577ef
update cli image tag ahead of merge
tomklapiscak Apr 17, 2025
a400db6
Merge branch 'mascore5516' into mascore5637
tomklapiscak Apr 17, 2025
bc7255f
Merge remote-tracking branch 'origin/main' into mascore5637
tomklapiscak Apr 17, 2025
82d83f2
trigger linter action
tomklapiscak Apr 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ site
.venv
.DS_Store
build/bin/awktest.sh
.venv
21 changes: 21 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
Contributing to MAS Gitops
===============================================================================


Documentation
-------------------------------------------------------------------------------


Versioned documentation is published automatically here: [https://ibm-mas.github.io/gitops/](https://ibm-mas.github.io/gitops/).
Documentation source is located in the `docs` folder.

To view your local documentation updates before pushing to git, run the following:

```
python3.9 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install mkdocs
pip install mkdocs-redirects
pip install mkdocs-macros-plugin
pip install mkdocs-drawio-file
mkdocs serve
```

Pre-Commit Hooks
-------------------------------------------------------------------------------

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Documentation
[https://ibm-mas.github.io/gitops/](https://ibm-mas.github.io/gitops/)

[https://github.com/ibm-mas/gitops-demo/tree/002](https://github.com/ibm-mas/gitops-demo/tree/002)

56 changes: 51 additions & 5 deletions build/bin/verify-job-definitions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ Job name accordingly:
- The \$_job_config_values constant is defined
- The \$_job_version constant is defined
- The \$_job_hash constant is defined and has the correct value
- The \$_job_name constant is defined and has the correct value
- The \$_job_name constant is used as the name of the Job
- The \$_job_name constant is defined, has the correct value and is used as the name of the Job
- The \$_job_cleanup_group is constant defined and assigned to the mas.ibm.com/job-cleanup-group Job label
- each template file contains only a single Job definition

[PATH]... can be either:
- A single directory: the script will check all files under this directory (recursive)
Expand Down Expand Up @@ -127,7 +128,7 @@ for file in ${files}; do
done <<< "$(sed -En 's/.*quay\.io\/ibmmas\/cli:(.*)/\1/p' $file)"


# Experimental: attempt to dynamically detect if we can relax job naming restrictions for this file
# Attempt to dynamically detect if we can relax job naming restrictions for this file
# The following awk commands exits 0 if and only if:
# - File does not contain a Job resource
# Jobs are currently the only resource we use where immutability of the image field is a problem.
Expand Down Expand Up @@ -219,14 +220,29 @@ for file in ${files}; do
problems=${problems}' Missing {{- $_job_name := "..." }}\n'
fi

# Check all jobs actually use $_job_name
# Check there is exactly one Job resource defined in the file
awkout=$(awk 'BEGIN { job_count=0; }
/^[[:space:]]*kind:[[:space:]]+Job/ { job_count++ }
END {
if(job_count != 1) {
printf "Exactly 1 Job should be defined in each template file, but %s were found", job_count
exit 1
}
}' $file \
)
rc=$?
if [[ $rc != 0 ]]; then
problems=${problems}' '${awkout}'\n'
fi

# Check the job actually uses $_job_name
awkout=$(awk 'BEGIN { job_count=0; valid_name_count=0; }
/^[[:space:]]*kind:[[:space:]]+Job/ { inJob=1; job_count++ }
/^---/ { inJob=0 }
inJob && /name:[[:space:]]+\{\{[[:space:]]*\$_job_name[[:space:]]*\}\}/ { valid_name_count++ }
END {
if(valid_name_count!=job_count) {
print "At least one Job does not have name: {{ $_job_name }}"
print "The Job does not have name: {{ $_job_name }}"
exit 1
}
}' $file \
Expand All @@ -235,6 +251,36 @@ for file in ${files}; do
if [[ $rc != 0 ]]; then
problems=${problems}' '${awkout}'\n'
fi



# Check $_job_cleanup_group constant is defined
grep -Eq '^[[:space:]]*\{\{-?[[:space:]]+\$_job_cleanup_group[[:space:]]*:=[^}]+\}' $file
rc=$?
if [[ $rc != 0 ]]; then
problems=${problems}' Missing {{- $_job_cleanup_group := ... }}\n'
fi

# Check mas.ibm.com/job-cleanup_group: $_job_cleanup_group label is applied to the Job
awkout=$(awk 'BEGIN { state=0; found=0 }
/^---/ { state=0 }
/^[[:space:]]*spec:/ { state=0 }
/^[[:space:]]*kind:[[:space:]]+Job/ { state=1; }
state==1 && /^[[:space:]]*metadata:/ { state=2; }
state==2 && /^[[:space:]]+labels:/ { state=3; }
state==3 && /^[[:space:]]+mas\.ibm\.com\/job-cleanup-group[[:space:]]*:[[:space:]]+\{\{[[:space:]]*\$_job_cleanup_group[[:space:]]*\}\}/ { found=1 }
END {
if(found!=1) {
print "The Job does not have the mas.ibm.com/job-cleanup-group: {{ $_job_cleanup_group }} label"
exit 1
}
}' $file \
)
rc=$?
if [[ $rc != 0 ]]; then
problems=${problems}' '${awkout}'\n'
fi

fi


Expand Down
11 changes: 11 additions & 0 deletions cluster-applications/000-job-cleaner/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v2
name: job-cleaner
description: A CronJob to delete old versions of Jobs created by ArgoCD
type: application
version: 1.0.0

dependencies:
- name: junitreporter
version: 1.0.0
repository: "file://../../sub-charts/junitreporter/"
condition: junitreporter.devops_mongo_uri != ""
11 changes: 11 additions & 0 deletions cluster-applications/000-job-cleaner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
MAS SaaS Job Cleaner
===============================================================================

Deploys the `mas-saas-job-cleaner-cron` CronJob, responsible for cleaning up orphaned Job resources in the cluster. It works by grouping Jobs in the cluster according to the `mas.ibm.com/job-cleanup-group` label, then deleting all Jobs from each group except for the one with the latest `creationTimestamp`.

For safety, the CronJob is assigned a ServiceAccount that can only list and delete Job resources (so it can never delete any other type of resource). Furthermore, the logic ensures that only Job resources with the `mas.ibm.com/job-cleanup-group` label can be deleted.

The `mas-devops-saas-job-cleaner` command executed by this CronJob is defined in [python-devops](https://github.com/ibm-mas/python-devops/blob/stable/bin/mas-devops-saas-job-cleaner).


> In MaS SaaS, Job resources are routinely orphaned (i.e. marked for deletion by ArgoCD) since, when an update is required to an immutable Job field (e.g. its image tag), a new version of the Job resource must be created with a different name. When [auto_delete: false](https://ibm-mas.github.io/gitops/main/accountrootmanifest/#auto_delete) is set, ArgoCD will (by design) not perform this cleanup for us. Over time, Job resources will accumulate and put pressure on the K8S API server.
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{{- /*
Use the build/bin/set-cli-image-tag.sh script to update this value across all charts.
*/}}
{{- $_cli_image_tag := "13.17.0" }}


{{- $ns := "job-cleaner" }}

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: mas-saas-job-cleaner-role
annotations:
argocd.argoproj.io/sync-wave: "02"
{{- if .Values.custom_labels }}
labels:
{{ .Values.custom_labels | toYaml | indent 4 }}
{{- end }}
rules:
- apiGroups:
- batch
resources:
- jobs
verbs:
- list
- delete

---
# Service account that is authorized to read k8s secrets (needed by the job)
kind: ServiceAccount
apiVersion: v1
metadata:
name: "mas-saas-job-cleaner-sa"
namespace: "{{ $ns }}"
annotations:
argocd.argoproj.io/sync-wave: "02"
{{- if .Values.custom_labels }}
labels:
{{ .Values.custom_labels | toYaml | indent 4 }}
{{- end }}


---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: mas-saas-job-cleaner-rolebinding
annotations:
argocd.argoproj.io/sync-wave: "03"
{{- if .Values.custom_labels }}
labels:
{{ .Values.custom_labels | toYaml | indent 4 }}
{{- end }}
subjects:
- kind: ServiceAccount
name: mas-saas-job-cleaner-sa
namespace: {{ $ns }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: mas-saas-job-cleaner-role



---
kind: CronJob
apiVersion: batch/v1
metadata:
name: "mas-saas-job-cleaner-cron"
namespace: "{{ $ns }}"
annotations:
argocd.argoproj.io/sync-wave: "04"
{{- if .Values.custom_labels }}
labels:
{{ .Values.custom_labels | toYaml | indent 4 }}
{{- end }}
spec:
schedule: '0 0 * * *'
suspend: false
concurrencyPolicy: Forbid
jobTemplate:
spec:
template:
metadata:
{{- if .Values.custom_labels }}
labels:
{{ .Values.custom_labels | toYaml | indent 12 }}
{{- end }}
spec:
containers:
- name: "mas-saas-job-cleaner"
image: quay.io/ibmmas/cli:{{ $_cli_image_tag }}
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- |
set -e
mas-devops-saas-job-cleaner --label mas.ibm.com/job-cleanup-group --log-level INFO
restartPolicy: OnFailure
serviceAccountName: "mas-saas-job-cleaner-sa"
1 change: 1 addition & 0 deletions cluster-applications/000-job-cleaner/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Increment this value whenever you make a change to an immutable field of the Job
E.g. passing in a new environment variable.
Included in $_job_hash (see below).
*/}}
{{- $_job_version := "v2" }}
{{- $_job_version := "v3" }}

{{- /*
10 char hash appended to the job name taking into account $_job_config_values, $_job_version and $_cli_image_tag
Expand All @@ -45,6 +45,27 @@ immutable field of any existing Job resource.

{{- $_job_name := join "-" (list $_job_name_prefix $_job_hash )}}

{{- /*
Set as the value for the mas.ibm.com/job-cleanup-group label on the Job resource.

When the auto_delete flag is not set on the root application, a CronJob in the cluster uses this label
to identify old Job resources that should be pruned on behalf of ArgoCD.

Any Job resources in the same namespace that have the mas.ibm.com/job-cleanup-group with this value
will be considered to belong to the same cleanup group. All but the most recent (i.e. with the latest "creation_timestamp")
Jobs will be automatically deleted.

$_job_cleanup_group can usually just be based on $_job_name_prefix. There are some special cases
where multiple Jobs are created in our templates using a Helm loop. In those cases, additional descriminators
must be added to $_job_cleanup_group.

By convention, we sha1sum this value to guarantee we never exceed the 63 char limit regardless of which discriminators
are required here.

*/}}
{{- $_job_cleanup_group := cat $_job_name_prefix | sha1sum }}


{{ $ns := "cert-manager-operator"}}
{{ $aws_secret := "aws"}}
{{ $role_name := "postsync-rhcm-update-sm-r" }}
Expand Down Expand Up @@ -142,8 +163,9 @@ metadata:
namespace: {{ $ns }}
annotations:
argocd.argoproj.io/sync-wave: "015"
{{- if .Values.custom_labels }}
labels:
mas.ibm.com/job-cleanup-group: {{ $_job_cleanup_group }}
{{- if .Values.custom_labels }}
{{ .Values.custom_labels | toYaml | indent 4 }}
{{- end }}
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Increment this value whenever you make a change to an immutable field of the Job
E.g. passing in a new environment variable.
Included in $_job_hash (see below).
*/}}
{{- $_job_version := "v2" }}
{{- $_job_version := "v3" }}

{{- /*
10 char hash appended to the job name taking into account $_job_config_values, $_job_version and $_cli_image_tag
Expand All @@ -37,6 +37,26 @@ immutable field of any existing Job resource.

{{- $_job_name := join "-" (list $_job_name_prefix $_job_hash )}}

{{- /*
Set as the value for the mas.ibm.com/job-cleanup-group label on the Job resource.

When the auto_delete flag is not set on the root application, a CronJob in the cluster uses this label
to identify old Job resources that should be pruned on behalf of ArgoCD.

Any Job resources in the same namespace that have the mas.ibm.com/job-cleanup-group with this value
will be considered to belong to the same cleanup group. All but the most recent (i.e. with the latest "creation_timestamp")
Jobs will be automatically deleted.

$_job_cleanup_group can usually just be based on $_job_name_prefix. There are some special cases
where multiple Jobs are created in our templates using a Helm loop. In those cases, additional descriminators
must be added to $_job_cleanup_group.

By convention, we sha1sum this value to guarantee we never exceed the 63 char limit regardless of which discriminators
are required here.

*/}}
{{- $_job_cleanup_group := cat $_job_name_prefix | sha1sum }}


{{ $ns := .Values.dro_namespace}}
{{ $aws_secret := "aws"}}
Expand Down Expand Up @@ -125,8 +145,9 @@ metadata:
namespace: {{ $ns }}
annotations:
argocd.argoproj.io/sync-wave: "028"
{{- if .Values.custom_labels }}
labels:
mas.ibm.com/job-cleanup-group: {{ $_job_cleanup_group }}
{{- if .Values.custom_labels }}
{{ .Values.custom_labels | toYaml | indent 4 }}
{{- end }}
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,26 @@ immutable field of any existing Job resource.
{{- $_job_name := join "-" (list $_job_name_prefix $_job_hash )}}


{{- /*
Set as the value for the mas.ibm.com/job-cleanup-group label on the Job resource.

When the auto_delete flag is not set on the root application, a CronJob in the cluster uses this label
to identify old Job resources that should be pruned on behalf of ArgoCD.

Any Job resources in the same namespace that have the mas.ibm.com/job-cleanup-group with this value
will be considered to belong to the same cleanup group. All but the most recent (i.e. with the latest "creation_timestamp")
Jobs will be automatically deleted.

$_job_cleanup_group can usually just be based on $_job_name_prefix. There are some special cases
where multiple Jobs are created in our templates using a Helm loop. In those cases, additional descriminators
must be added to $_job_cleanup_group.
NOTE: this is one of those cases; we need a separate cleanup group for each per-sa-key Job.

By convention, we sha1sum this value to guarantee we never exceed the 63 char limit regardless of which discriminators
are required here.

*/}}
{{- $_job_cleanup_group := cat $_job_name_prefix $key | sha1sum }}

---
apiVersion: batch/v1
Expand All @@ -47,8 +67,9 @@ metadata:
namespace: {{ $.Values.custom_sa_namespace }}
annotations:
argocd.argoproj.io/sync-wave: "064"
{{- if $.Values.custom_labels }}
labels:
mas.ibm.com/job-cleanup-group: {{ $_job_cleanup_group }}
{{- if $.Values.custom_labels }}
{{ $.Values.custom_labels | toYaml | indent 4 }}
{{- end }}
spec:
Expand Down Expand Up @@ -148,4 +169,4 @@ spec:
defaultMode: 420
optional: false
backoffLimit: 4
{{- end }}
{{- end }}
Loading
Loading