Skip to content

Instantly share code, notes, and snippets.

@therevoman
Last active April 18, 2024 15:32
Show Gist options
  • Save therevoman/26c6fab434f1192f95eb4fc7bcfec0c7 to your computer and use it in GitHub Desktop.
Save therevoman/26c6fab434f1192f95eb4fc7bcfec0c7 to your computer and use it in GitHub Desktop.
OpenShift 4 Hacks

My list of OpenShift 4 hacks

How do I list all resources in a namespace (no, really ALL of them)

adapted from https://access.redhat.com/solutions/4165791

$ oc api-resources --verbs=list --namespaced -o name | xargs  -I {} bash -c "oc get --show-kind --ignore-not-found -n openshift-storage {}"

a little faster

$ oc api-resources --verbs=list --cached --namespaced -o name | xargs  -I {} bash -c "oc get --show-kind --ignore-not-found -n openshift-storage {}"

now ignore the operator manifests and events

$ oc api-resources --verbs=list --namespaced -o name | egrep -v "packagemanifests.packages.operators.coreos.com|events" | xargs  -I {} bash -c "oc get --show-kind --ignore-not-found -n openshift-storage {}"

now ignore the operator manifests and run faster (if list previously queried)

$ oc api-resources --verbs=list --cached --namespaced -o name | egrep -iv "packagemanifests.packages.operators.coreos.com|events" | xargs  -I {} bash -c "oc get --show-kind --ignore-not-found -n openshift-storage {}"

How to sort events

borrowed from kubernetes/kubernetes#29838

$ oc get event --sort-by='.lastTimestamp'
$ oc get event --sort-by='.metadata.creationTimestamp'

How to clear a disk previously used by OSD or ODF or Ceph.

wipefs -a didn't completely wipe the disk

$ sgdisk --zap-all /dev/sda

How to clear GPT tables with DD

Here is a script that will properly wipe the GPT tables and signatures

$ cat <<EOF > ddwipe.sh
#!/bin/bash
DEV="${1}"
END="$(sudo blockdev --getsz ${DEV})"
GPT_END=$(($END - 100))
dd if=/dev/zero of=${DEV} bs=1M count=1
dd if=/dev/zero of=${DEV} bs=512 seek=${GPT_END}
EOF
$ bash -x ddwipe.sh /dev/vdb

From https://bugs.launchpad.net/ubuntu/+source/gdisk/+bug/1303903

How to send a shutdown to lab nodes. Not sure this works well with large clusters

$ for i in `oc get nodes -o name | sort -r`; do echo $i; oc debug $i -- chroot /host bash -c "sudo shutdown \\+1 \\&;exit"; done

As a last resort, here is how to clear a finalizer

$ oc patch -n <project-name> <object-kind>/<object-name> --type=merge -p '{"metadata": {"finalizers":null}}'

Markdown Cheatsheet

https://gist.github.com/benstr/8744304

Don't run these

oc delete -n openshift-storage --force --grace-period=0 cephfilesystem.ceph.rook.io/ocs-storagecluster-cephfilesystem cephcluster.ceph.rook.io/ocs-storagecluster-cephcluster cephblockpool.ceph.rook.io/ocs-storagecluster-cephblockpool secret/rook-ceph-mon configmap/rook-ceph-mon-endpoints bucketclass.noobaa.io/noobaa-default-bucket-class storagecluster.ocs.openshift.io/ocs-storagecluster noobaa.noobaa.io/noobaa storagesystem.odf.openshift.io/ocs-storagecluster-storagesystem backingstores.noobaa.io/noobaa-default-backing-store

oc patch -n openshift-storage --type=merge -p '{"metadata": {"finalizers":null}}' cephfilesystem.ceph.rook.io/ocs-storagecluster-cephfilesystem cephcluster.ceph.rook.io/ocs-storagecluster-cephcluster cephblockpool.ceph.rook.io/ocs-storagecluster-cephblockpool secret/rook-ceph-mon configmap/rook-ceph-mon-endpoints bucketclass.noobaa.io/noobaa-default-bucket-class storagecluster.ocs.openshift.io/ocs-storagecluster noobaa.noobaa.io/noobaa storagesystem.odf.openshift.io/ocs-storagecluster-storagesystem backingstores.noobaa.io/noobaa-default-backing-store
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment