Skip to content

Commit

Permalink
Merge pull request #3 from thecloudnatives/add-prune-unused-dry-run
Browse files Browse the repository at this point in the history
Add --dry-run flag instead of prompt
  • Loading branch information
etiennetremel authored Aug 15, 2019
2 parents eddd6e7 + 0b2eed4 commit ea34896
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Usage:
Options:
-n, --namespace='': If present, the namespace scope for this CLI request
--dry-run: If true, only print the object that would be pruned, without deleting it.
-h, --help: Display this help
```

Expand Down
24 changes: 14 additions & 10 deletions prune-unused/kubectl-prune_unused.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function usage() {
echo ""
echo "Options:"
echo " -n, --namespace='': If present, the namespace scope for this CLI request"
echo " --dry-run: If true, only print the object that would be pruned, without deleting it."
echo " -h, --help: Display this help"
exit 0
}
Expand All @@ -26,6 +27,7 @@ then
fi

resource=$1
dry_run="false"

while test $# -gt 1
do
Expand All @@ -40,6 +42,10 @@ do
fi
shift
;;
--dry-run)
dry_run="true"
shift
;;
-h|--help)
usage
;;
Expand Down Expand Up @@ -138,14 +144,12 @@ then
exit 0
fi

echo "About to delete the following $resource: ${resource_name_list}"

# confirmation prompt
read -p "Delete listed resource(s)? [yes/no]: " -r
if [[ $REPLY =~ ^[Yy]es$ ]]
then
for resource_name in $resource_name_list
do
for resource_name in $resource_name_list
do
if [ "$dry_run" == "true" ]
then
echo "${resource} ${resource_name} deleted (dry run)"
else
kubectl delete $resource $resource_name $namespace_arg
done
fi
fi
done

0 comments on commit ea34896

Please sign in to comment.