Skip to content

Instantly share code, notes, and snippets.

@clcollins
Created February 18, 2020 19:43
Show Gist options
  • Save clcollins/1b505d3263c4c065b9a202166bc7d20c to your computer and use it in GitHub Desktop.
Save clcollins/1b505d3263c4c065b9a202166bc7d20c to your computer and use it in GitHub Desktop.
Scripts for patching a project namespace and deploying pods onto specified nodes in OpenShift
#!/usr/bin/env bash
oc get nodes -l type=compute -o=jsonpath='{range .items[*]}{.metadata.labels.hostname}{"\n"}{end}'
#!/usr/bin/env bash
NODE=$1
if [[ -z $NODE ]]
then
echo "need a node name"
fi
echo $NODE
NS='chcollin-sre'
P_STRING="{\"metadata\": {\"annotations\": {\"openshift.io/node-selector\": \"hostname=${NODE}\"}}}"
oc patch namespace $NS -p "${P_STRING}"
# Get the node to kill
oc get --no-headers=true --namespace $NS po -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | xargs oc --namespace $NS delete po
echo "Waiting for pod to become ready:"
oc get po --namespace $NS -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.hostIP}{"\t"}{.status.phase}{"\n"}{end}'
until oc get po --namespace $NS -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.hostIP}{"\t"}{.status.phase}{"\n"}{end}' |grep Running
do
oc get po --namespace $NS -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.hostIP}{"\t"}{.status.phase}{"\n"}{end}'
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment