Skip to content

Instantly share code, notes, and snippets.

@miminar
Created March 15, 2019 09:26
Show Gist options
  • Save miminar/f17aa1f8bd65e27fca1e3b749d081534 to your computer and use it in GitHub Desktop.
Save miminar/f17aa1f8bd65e27fca1e3b749d081534 to your computer and use it in GitHub Desktop.
OpenShift CLI snippets

Useful snippets for OpenShift

Get a table of pods/scc/owners

Where the owners are determined recursively. Limitation: only parents of replicasets are recursively evaluated.

$ oc get -o json pod  | jq -r '.items[] | . as $i |
        "\(.metadata.name):\(.metadata.annotations["openshift.io/scc"]):"
            + ([.metadata.ownerReferences[] | "\(.kind | ascii_downcase)/\(.name)"] |
               join(","))' | while IFS=  read -r l; do
        while [[ "$l" =~ replicaset/[^,]+ ]]; do
            rs="${BASH_REMATCH[0]}"
            owners="$(oc get -o json "$rs" | jq -r '[.metadata.ownerReferences[] |
                        "\(.kind | ascii_downcase)/\(.name)"] | join(",")')"
            [[ -z "${owners:-}" ]] && continue
            l="$(printf '%s\n' "$l" | sed "s:$rs:$owners:")"
        done
        printf '%s\n' "${l:-}"
    done | column -t -s :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment