Skip to content

Commit

Permalink
fetch last applied config if able
Browse files Browse the repository at this point in the history
  • Loading branch information
hadar-co committed Apr 28, 2022
1 parent a082013 commit da2708c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions kubectl-datree
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit da2708c

Please sign in to comment.