Skip to content

Instantly share code, notes, and snippets.

@shivanshs9
Created March 27, 2025 09:26
Show Gist options
  • Save shivanshs9/a55f2766c1f5e139a2d6b089ba66046e to your computer and use it in GitHub Desktop.
Save shivanshs9/a55f2766c1f5e139a2d6b089ba66046e to your computer and use it in GitHub Desktop.
Function to edit kubenetes job (vim) by replace
# requires kubectl-neat (https://github.com/itaysk/kubectl-neat)
function k8s_edit_job
if test (count $argv) -lt 2
echo "Usage: k8s_edit_job <namespace> <job_name>"
return 1
end
set NAMESPACE $argv[1]
set JOB_NAME $argv[2]
set jobYaml (mktemp)
# Get the job YAML and edit it
kubectl get -n $NAMESPACE job $JOB_NAME -o yaml | kubectl neat | sed '/uid:/d' > $jobYaml
cp $jobYaml $jobYaml.bak
echo "Backed up to $jobYaml.bak"
vim $jobYaml
if ! diff $jobYaml $jobYaml.bak > /dev/null;
echo "Changes detected, applying..."
kubectl delete job $JOB_NAME -n $NAMESPACE
kubectl apply -f $jobYaml
else
echo "No changes detected, skipping apply."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment