Last active
May 17, 2018 12:41
-
-
Save JeffreyVdb/c77e67ece883185655a3a54e633f0d10 to your computer and use it in GitHub Desktop.
Extract a job from a kubernetes cronjob
This file contains hidden or 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
function kcrongetjob() { | |
local cronjob_name="$1" | |
local namespace="${2:-default}" | |
local _json | |
_json=$(kubectl -n $namespace get cronjob $cronjob_name -o json --export 2>&1) | |
if [ $? -eq 0 ]; then | |
echo "{ | |
\"apiVersion\": \"batch/v1\", | |
\"kind\": \"Job\", | |
\"metadata\": { | |
\"name\": \"$cronjob_name\", | |
\"namespace\": \"$namespace\" | |
}, | |
\"spec\": " | |
jq --indent 2 .spec.jobTemplate.spec <<< "$_json" | perl -pe 's/^/ /g' | |
echo '}' | |
else | |
echo $_json | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment