Skip to content

Instantly share code, notes, and snippets.

@sudhirpandey
Last active January 29, 2025 21:26
Show Gist options
  • Select an option

  • Save sudhirpandey/d13baf9bdaeb5f50db73d123e1197eb7 to your computer and use it in GitHub Desktop.

Select an option

Save sudhirpandey/d13baf9bdaeb5f50db73d123e1197eb7 to your computer and use it in GitHub Desktop.
openshift command line with Go templating and others
#to get all the tags of is
oc get is name -n namespace --template='{{ range $index, $element :=.status.tags }}{{ $element.tag }}{{"\n"}}{{end}}'
#To get all the projects
`oc get projects -o name |xargs -i oc get {} --template '{{ .metadata.name }}{{"\n"}}`
#To get all the routes
`oc get projects -o name |xargs -i oc get {} --template '{{ .metadata.name }}{{"\n"}}'|xargs -i oc get routes --template '{{range .items}}{{ .spec.host}}{{"\n"}}{{end}}' -n {}`
#Get firts message from the status
oc get dc service-name --template='{{ range $index, $element :=.status.conditions }}{{ if eq $index 0 }}{{ $element.message }} {{end}}{{end}}'
#Get the outputs from desired keys
oc get svc svcname -o json |jq '.metadata.annotations."prometheus.io/probe"'
oc get svc svcname --template='{{ index .metadata.annotations "prometheus.io/probe" }}
#Patch all the services to have prometheus tags
PATCH='{"metadata":{"labels":{"team":"xxxx"}}}'
oc get svc | awk '{print $1}'| tail -n +2 |xargs -i oc patch svc {} -p "$PATCH"
PATCH='{"metadata":{"annotations":{"prometheus.io/probe":"true"}}}'
repeat
#capablity check
oc adm policy who-can create buildConfigs
oc adm policy who-can create build
oc adm policy who-can update build
oc adm policy who-can update buildConfigs
oc adm policy who-can create builds
oc policy who-can get imagestreams/layers -n
#Peak into elastic search openshift logging
oc get secret logging-fluentd --template='{{.data.ca}}' | base64 -d > ca
oc get secret logging-fluentd --template='{{.data.key}}' | base64 -d > key
oc get secret logging-fluentd --template='{{.data.cert}}' | base64 -d > cert
oc port-forward <es pod name> 9200:9200
curl -s --cacert ca --key key --cert cert https://localhost:9200/_cluster/health | python -mjson.tool
#Test port is open in container without network tools
cat < /dev/tcp/127.0.0.1/22
#haproxy debug the request errors
echo "show errors"|socat unix-connect:/var/lib/haproxy/run/haproxy.sock stdio
#see contianer interface with host
cat /sys/class/net/eth0/iflink
#temporarily allow traffic in cluster
iptables -I OS_FIREWALL_ALLOW -p udp -m state --state NEW -m udp --dport <port> -j ACCEPT
iptables -I OS_FIREWALL_ALLOW -p udp -m state --state NEW -m tcp --dport <port> -j ACCEPT
#Api usage with token
curl -k -H "Authorization: Bearer <token>" https://cluster.xxx.xxx.xxx/api/v1/namespaces/monitoring/configmaps
#hacking dc to do sed and launch entry point
- args:
- -c
- /bin/sed -i '/^command=clair/ s/$/ -insecure-tls/' /supervisord.conf &&
/boot.sh
command:
- /bin/sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment