Skip to content

Instantly share code, notes, and snippets.

@koenbollen
Last active February 7, 2018 07:24
Show Gist options
  • Save koenbollen/11f76bec8f2aa059072e057d731f1ebe to your computer and use it in GitHub Desktop.
Save koenbollen/11f76bec8f2aa059072e057d731f1ebe to your computer and use it in GitHub Desktop.
k8s_manual_cron — Run a configured cronjob now
#!/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 "$@"
@koenbollen
Copy link
Author

Yes! I'm using JSON in a YAML document. Sue me! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment