Skip to content

Instantly share code, notes, and snippets.

@JeffreyVdb
Last active May 17, 2018 12:41
Show Gist options
  • Save JeffreyVdb/c77e67ece883185655a3a54e633f0d10 to your computer and use it in GitHub Desktop.
Save JeffreyVdb/c77e67ece883185655a3a54e633f0d10 to your computer and use it in GitHub Desktop.
Extract a job from a kubernetes cronjob
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