Last active
February 7, 2018 07:24
-
-
Save koenbollen/11f76bec8f2aa059072e057d731f1ebe to your computer and use it in GitHub Desktop.
k8s_manual_cron — Run a configured cronjob now
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
#!/bin/bash | |
# k8s_manual_cron - Run a configured cronjob now | |
set -euo pipefail | |
IFS=$'\n\t' | |
# shellcheck disable=SC2155 | |
main() { | |
readonly cronjob_name="$1" | |
local cronjob="$(kubectl get cronjob "$cronjob_name" -o json)" | |
local jobTemplate="$(printf "%s" "$cronjob" | jq -c .spec.jobTemplate.spec)" | |
local name="manualrun-$cronjob_name-$(date "+%Y%m%d%H%M")" | |
local job_yaml="$(cat <<EOM | |
apiVersion: batch/v1 | |
kind: Job | |
metadata: | |
name: $name | |
spec: $jobTemplate | |
EOM | |
)" | |
echo "$job_yaml" | kubectl apply -f - --validate | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes! I'm using JSON in a YAML document. Sue me! 😄