Skip to content

Instantly share code, notes, and snippets.

@kenglxn
Last active May 4, 2018 08:58
Show Gist options
  • Save kenglxn/95ad68b0af324cb3120098bf4cd9fb9a to your computer and use it in GitHub Desktop.
Save kenglxn/95ad68b0af324cb3120098bf4cd9fb9a to your computer and use it in GitHub Desktop.
fish wrapper for simplyfying oc usage against pods
function ocp
if test (count $argv) -gt 1
set podname $argv[1]
set oc_cmd $argv[2]
set pods (oc get pods | grep -i running | grep $podname | awk '{print $1}')
if test (count $pods) -eq 0
echo "=> Found no pods using filter: $podname"
oc project
oc get pods
end
if test (count $argv) -gt 2
set rest $argv[3..-1]
end
echo ""
echo "=> Running $oc_cmd on pods: $pods(set_color normal)"
echo ""
for pod in $pods
echo "=> $oc_cmd $pod $rest"
oc $oc_cmd $pod $rest
echo "command exited with status: $status"
echo ""
end
else
echo "usage:"
echo "ocp <PODNAME> <OC_CMD> [ARGS]"
end
end
@kenglxn
Copy link
Author

kenglxn commented Mar 9, 2018

usage:

ocp <PODNAME> <OC_CMD> [ARGS]

examples:

tail logs from a pod with name containing frontend:

ocp frontend tail -f

given the following list of pods:

NAME                               READY     STATUS    RESTARTS   AGE
services-5-kam7q          1/1       Running   0          19h
backend-9-haaz4                1/1       Running   0          21h
frontend-10-4aamb              1/1       Running   0          22h

will tail logs of frontend-10-4aamb

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