Skip to content

Instantly share code, notes, and snippets.

@juandspy
Last active October 19, 2023 15:32
Show Gist options
  • Save juandspy/7a6a151e679603a2826f5d37018e9694 to your computer and use it in GitHub Desktop.
Save juandspy/7a6a151e679603a2826f5d37018e9694 to your computer and use it in GitHub Desktop.
Get OpenShift resources including the Helm release

Compare Helm chart with deployed workflows

Get all the Helm resources that are deployed in the cluster

echo "KIND,NAME,NAMESPACE,HELM_RELEASE" > resources.csv
source main.sh
namespaces=("ccx-prod" "ccx-qa" "ccx-supplementary"); for ns in "${namespaces[@]}";
    get_resources "$ns" | awk '{$1=$1; OFS=",";} 1' |
    grep -v -E 'Pod|Job|ReplicationController|ReplicaSet' | awk -F, '$1 != "Build"' >> resources.csv

I'm ignoring pods, jobs, builds, replica sets and replication controllers because they are managed by parent resources and contains no helm release in the labels. That would be just noise in the output CSV.

#!/bin/bash
function get_resources() {
NAMESPACE="$1"
oc get all,serviceaccounts,roles,rolebindings,pvc \
-n $NAMESPACE \
--no-headers \
-o custom-columns="KIND:.kind,NAME:.metadata.name,NAMESPACE:.metadata.namespace,HELM_RELEASE:.metadata.annotations.meta\.helm\.sh/release-name"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment