From da2708c54ac60c6ff067b7f59b3edd5bdcbb8d31 Mon Sep 17 00:00:00 2001 From: hadar-co Date: Thu, 28 Apr 2022 18:44:51 +0300 Subject: [PATCH] fetch last applied config if able --- kubectl-datree | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/kubectl-datree b/kubectl-datree index 7ac8428..8629225 100755 --- a/kubectl-datree +++ b/kubectl-datree @@ -86,7 +86,13 @@ mkdir -p $DST_DIR get_yamls(){ while read line do - kubectl get $line -n $NAMESPACE -o yaml > $DST_DIR/"kubectl-${line%%/*}-${line##*/}".yaml & + FILENAME="kubectl-${line%%/*}-${line##*/}.yaml" + + kubectl apply view-last-applied $line -n $NAMESPACE > $DST_DIR/$FILENAME + if [ ! -s $DST_DIR/$FILENAME ]; then + kubectl get $line -n $NAMESPACE -o yaml > $DST_DIR/$FILENAME & + fi + scanned_files+=("$line") done } @@ -99,7 +105,13 @@ get_common_resources(){ continue fi - kubectl get $line -n $NAMESPACE -o yaml > $DST_DIR/"kubectl-${line%%/*}-${line##*/}".yaml & + FILENAME="kubectl-${line%%/*}-${line##*/}.yaml" + + kubectl apply view-last-applied $line -n $NAMESPACE > $DST_DIR/$FILENAME + if [ ! -s $DST_DIR/$FILENAME ]; then + kubectl get $line -n $NAMESPACE -o yaml > $DST_DIR/$FILENAME & + fi + scanned_files+=("$line") done } @@ -151,7 +163,7 @@ if [ "$wereFilesScanned" != 0 ]; then printf "\nThe following cluster resources in namespace '$NAMESPACE' were checked:\n\n" for file in "${scanned_files[@]}" do - echo $file + echo "$file" done printf "\n" fi