Skip to content

Commit

Permalink
feat(charts/simple-workflow): Workflow Janitor (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
masterginger authored Nov 29, 2023
1 parent e5f886d commit 464bd6d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: v3.5.0
version: v3.12.2

- uses: actions/setup-python@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion charts/simple-workflow/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: simple-workflow
description: Default Argo Workflow Helm Chart
type: application
version: 0.0.11
version: 0.0.12
appVersion: latest
maintainers:
- name: masterginger
Expand Down
2 changes: 1 addition & 1 deletion charts/simple-workflow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Default Argo Workflow Helm Chart

![Version: 0.0.11](https://img.shields.io/badge/Version-0.0.11-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: latest](https://img.shields.io/badge/AppVersion-latest-informational?style=flat-square)
![Version: 0.0.12](https://img.shields.io/badge/Version-0.0.12-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: latest](https://img.shields.io/badge/AppVersion-latest-informational?style=flat-square)

## Values

Expand Down
39 changes: 39 additions & 0 deletions charts/simple-workflow/templates/workflow-janitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{{- if and .Values.workflowJanitor .Values.workflowJanitor.enabled }}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ .Release.Name }}-keep-recent-n-workflows
namespace: {{ .Release.Namespace }}
annotations:
argocd.argoproj.io/hook: PreSync
argocd.argoproj.io/hook-delete-policy: BeforeHookCreation
argocd.argoproj.io/sync-wave: "-1"
spec:
backoffLimit: 1
template:
metadata:
labels:
mesh.nextdoor.com/dropMetrics: 'true'
annotations:
sidecar.istio.io/inject: 'false'
spec:
serviceAccountName: {{ .Values.workflow.serviceAccount.name }}
restartPolicy: Never
activeDeadlineSeconds: 120
containers:
- name: workflow-janitor
image: bitnami/kubectl:1.28.4
command: ["/bin/bash"]
args:
- -c
- >-
kubectl get workflow --sort-by=.metadata.creationTimestamp &&
echo "Total workflows: $(kubectl get workflow --sort-by=.metadata.creationTimestamp -o go-template --template {{ "'{{" }}range .items}}{{ "{{" }}.metadata.name}}{{ "{{" }}"\n"}}{{ "{{" }}end}}' | wc -l)" &&
echo "Keeping {{ .Values.workflowJanitor.keepRecent | default 30 }}" &&
while [[ $(kubectl get workflow --sort-by=.metadata.creationTimestamp -o go-template --template {{ "'{{" }}range .items}}{{ "{{" }}.metadata.name}}{{ "{{" }}"\n"}}{{ "{{" }}end}}' | wc -l) -gt {{ .Values.workflowJanitor.keepRecent | default 30 }} ]];
do
sleep 3;
kubectl delete workflow $(kubectl get workflow --sort-by=.metadata.creationTimestamp -o go-template --template {{ "'{{" }}range .items}}{{ "{{" }}.metadata.name}}{{ "{{" }}"\n"}}{{ "{{" }}end}}' | head -n 1);
kubectl get workflow --sort-by=.metadata.creationTimestamp;
done
{{- end }}
8 changes: 7 additions & 1 deletion charts/simple-workflow/templates/workflow-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ metadata:
{{- tpl (toYaml .) $ | nindent 4 }}
{{- end }}
spec:
{{- if .Values.workflow.ttlStrategy }}
{{- if and .Values.workflowJanitor .Values.workflowJanitor.enabled }}
# Set a 30-day ttl because workflow janitor is enabled
ttlStrategy:
secondsAfterCompletion: 2592000
secondsAfterFailure: 2592000
secondsAfterSuccess: 2592000
{{- else if .Values.workflow.ttlStrategy }}
ttlStrategy:
{{- with $.Values.workflow.ttlStrategy }}
{{- tpl (toYaml .) $ | nindent 4 }}
Expand Down

0 comments on commit 464bd6d

Please sign in to comment.