-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates a managed Namespace mechanism for consistent tooling (#62)
* Moves namespace definitions to a dedicated file * Moves registry secrets into namespace definition * Moves certbot copy into managed namespaces * Adds the pod-killer to managed namespaces * Moved job cleaner to managed namespaces
- Loading branch information
Showing
11 changed files
with
412 additions
and
411 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Various templates and such for managing things that keep the cluster neat. | ||
|
||
Each namespace ships with: | ||
- A set of docker registry secrets | ||
- A `CronJob` to copy SSL certs from filesystem to Kubernetes `Secret` | ||
- A `CronJob` to kill pods whose containers have > 10 restarts | ||
- A `CronJob` to delete old manual job runs |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env sh | ||
# | ||
# Delete jobs that appear to be CronJobs that have been run manually from the | ||
# Kubernetes Dashboard. | ||
set -euf | ||
|
||
SLACK_URL="https://slackbot.internal.aleemhaji.com/message" | ||
|
||
slack() { | ||
curl -sS -X POST -H "X-SLACK-CHANNEL-ID: ${SLACK_BOT_ALERTING_CHANNEL}" -d "$@" "$SLACK_URL" | ||
} | ||
|
||
if [ $# -ne 2 ]; then | ||
echo >&2 "Usage:" | ||
echo >&2 " $0 <namespace> <age>" | ||
exit 1 | ||
fi | ||
|
||
namespace="$1" | ||
age_str="$2" | ||
|
||
MANUAL_JOB_REGEXP='-manual-[[:alnum:]]\{3,5\}[[:space:]]' | ||
ONE_MONTH_AGO="$(date -u -d "$age_str ago" '+%Y-%m-%dT%H:%M:%SZ')" | ||
JOBS_COLUMNS='custom-columns=NAME:{.metadata.name},SUCCEEDED:{.status.succeeded},COMPLETED:{.status.completionTime}' | ||
# shellcheck disable=SC2016 | ||
AWK_SCRIPT='{if ($2 == 1 && $3 < arg) print $1}' | ||
|
||
slack 'Manual job-run cleaup running on '"$(hostname)"'. | ||
Deleting successful manually run jobs in namespace "'"$namespace"'" older than '"$age_str"'.' | ||
|
||
while true; do | ||
echo "Run: $(date)" | ||
kubectl -n "$namespace" get jobs -o "$JOBS_COLUMNS" | sed '1d' | grep -- "$MANUAL_JOB_REGEXP" | awk -v "arg=$ONE_MONTH_AGO" "$AWK_SCRIPT" | while read -r job; do | ||
slack "Job monitor deleting old manually run job: $job" | ||
kubectl -n "${namespace}" delete job "$job" | ||
done | ||
|
||
sleep 3600 | ||
done |
Oops, something went wrong.