Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎉 Add variable to customize airbyte-pod-sweeper delete pod action #17985

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
43 changes: 0 additions & 43 deletions charts/airbyte-pod-sweeper/files/sweep-pod.sh

This file was deleted.

41 changes: 40 additions & 1 deletion charts/airbyte-pod-sweeper/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,43 @@ metadata:

data:
sweep-pod.sh: |
{{- (.Files.Get "files/sweep-pod.sh") | nindent 4 }}
#!/bin/bash
get_worker_pods () {
kubectl -n ${KUBE_NAMESPACE} -L airbyte -l airbyte=worker-pod \
--field-selector status.phase!=Running get pods \
-o=jsonpath='{range .items[*]} {.metadata.name} {.status.phase} {.status.conditions[0].lastTransitionTime} {.status.startTime}{"\n"}{end}'
}
delete_worker_pod() {
printf "From status '%s' since '%s', " $2 $3
echo "$1" | grep -v "STATUS" | awk '{print $1}' | xargs --no-run-if-empty kubectl -n ${KUBE_NAMESPACE} delete pod
}
while :
do
# Shorter time window for completed pods
SUCCESS_DATE_STR=`date -d 'now - {{ .Values.timeToDeletePods.completed }} minutes' --utc -Ins`
SUCCESS_DATE=`date -d $SUCCESS_DATE_STR +%s`
# Longer time window for pods in error (to debug)
NON_SUCCESS_DATE_STR=`date -d 'now - {{ .Values.timeToDeletePods.error }} minutes' --utc -Ins`
NON_SUCCESS_DATE=`date -d $NON_SUCCESS_DATE_STR +%s`
(
IFS=$'\n'
for POD in `get_worker_pods`; do
IFS=' '
POD_NAME=`echo $POD | cut -d " " -f 1`
POD_STATUS=`echo $POD | cut -d " " -f 2`
POD_DATE_STR=`echo $POD | cut -d " " -f 3`
POD_START_DATE_STR=`echo $POD | cut -d " " -f 4`
POD_DATE=`date -d ${POD_DATE_STR:-$POD_START_DATE_STR} '+%s'`
if [ "$POD_STATUS" = "Succeeded" ]; then
if [ "$POD_DATE" -lt "$SUCCESS_DATE" ]; then
delete_worker_pod "$POD_NAME" "$POD_STATUS" "$POD_DATE_STR"
fi
else
if [ "$POD_DATE" -lt "$NON_SUCCESS_DATE" ]; then
delete_worker_pod "$POD_NAME" "$POD_STATUS" "$POD_DATE_STR"
fi
fi
done
)
sleep 60
done
5 changes: 2 additions & 3 deletions charts/airbyte-pod-sweeper/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ metadata:
name: {{ include "common.names.fullname" . }}-pod-sweeper
labels:
{{- include "airbyte.labels" . | nindent 4 }}
annotations:
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
spec:
replicas: 1
selector:
Expand All @@ -16,8 +14,9 @@ spec:
metadata:
labels:
{{- include "airbyte.selectorLabels" . | nindent 8 }}
{{- if .Values.podAnnotations }}
annotations:
checksum/sweep-pod-script: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
{{- if .Values.podAnnotations }}
{{- include "common.tplvalues.render" (dict "value" .Values.podAnnotations "context" $) | nindent 8 }}
{{- end }}
spec:
Expand Down
6 changes: 6 additions & 0 deletions charts/airbyte-pod-sweeper/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,9 @@ extraVolumeMounts: []
## emptyDir: {}
##
extraVolumes: []

## podSweeper.timeToDeletePods.completed Time to remove pods on completed status (minutes).
## podSweeper.timeToDeletePods.error Time to remove pods on error status (minutes).
timeToDeletePods:
completed: 120
error: 1440