Skip to content

Instantly share code, notes, and snippets.

@Duologic
Last active January 21, 2021 12:20
Show Gist options
  • Select an option

  • Save Duologic/07bc4b635017f3e8d40e9a98626a74c9 to your computer and use it in GitHub Desktop.

Select an option

Save Duologic/07bc4b635017f3e8d40e9a98626a74c9 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euo pipefail
#set -x
IFS=$'\n\t'
DIRNAME=$(dirname $0)
if [ "$#" -lt 1 ]; then
echo "Usage: `basename $0` <context> [<namespace>]"
exit 1
fi
tempfile=$(mktemp)
function finish {
rm -rf ${tempfile}
}
trap finish EXIT
cluster=${1}
namespace=${2:-""}
jsonpath="{range .items[*]}{.metadata.annotations.fluxcd\.io\/sync-checksum}/${cluster}/{.metadata.namespace}/{.kind}-{.metadata.name}.yaml{\"\n\"}{end}"
namespace_arg=""
if [[ ${namespace} == "_cluster" ]]; then
types=(
"ClusterRole"
"ClusterRoleBinding"
"CustomResourceDefinition"
"MutatingWebhookConfiguration"
"Namespace" # Not all namespaces are created from jsonnet.
"PodSecurityPolicy"
"PriorityClass"
"StorageClass"
"ValidatingWebhookConfiguration"
)
else
if [[ -n ${namespace} ]]; then
namespace_arg="-n=${namespace}"
fi
types=(
"ClusterIssuer"
"ConfigMap"
"CronJob"
"DaemonSet"
"Deployment"
"EtcdCluster"
"Ingress"
"Job"
"PersistentVolumeClaim"
"Pod"
"PodDisruptionBudget"
"Role"
"RoleBinding"
#"Secret" # Not included in repository
"Service"
"ServiceAccount"
"StatefulSet"
"VerticalPodAutoscaler"
)
fi
# ignoring resources managed by GKE
ignorelabels="kubernetes.io/bootstrapping!=rbac-defaults,!addonmanager.kubernetes.io/mode"
for type in ${types[@]}; do
hasType=$(kubectl get ${type} --context ${cluster} -l ${ignorelabels} ${namespace_arg} -o=jsonpath='{.items}' 2>&1)
if [ "${hasType}" != "[]" ]; then
kubectl get ${type} \
--context ${cluster} \
-l ${ignorelabels} \
${namespace_arg} \
-o=jsonpath="${jsonpath}" | \
sed 's/^[a-z0-9]\+/.\/flux/' | \
sed 's/\/\//\/_cluster\//' | \
sed 's/^\//.\//'
fi
done > ${tempfile}
set +e
for f in $(cat ${tempfile}); do
look=$(find $f 2>&1)
if [ $? -ne 0 ]; then
echo not found: $f
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment