Addon Manager: Fix bug in generate_prune_whitelist_flags

The bug seems to be currently dormant but I managed to trigger it in
some manual tests.

When the bug is triggered it appends empty --prune-whitelist without any
value which in turn can capture the next flag and can cause addon
manager to fail.

E.g. when bug is not triggered the kubectl command looks like this

```
kubectl ... --prune-whitelist extensions/v1beta1/Ingress --recursive ...
```

When it's triggered it will be

```
kubectl ... --prune-whitelist --recursive ...
```

which will capture the --recursive flag and will make addon-manager to
fail as there are no yamls in the top directory.
This commit is contained in:
Matt Matejczyk 2019-10-23 12:02:53 +02:00
parent 5f03d33fc9
commit d87e700f9b

View File

@ -108,7 +108,11 @@ function log() {
function generate_prune_whitelist_flags() {
local -r resources=( "$@" )
for resource in "${resources[@]}"; do
printf "%s" "--prune-whitelist ${resource} "
# Check if $resource isn't composed just of whitespaces by replacing ' '
# with '' and checking whether the resulting string is not empty.
if [[ -n "${resource// /}" ]]; then
printf "%s" "--prune-whitelist ${resource} "
fi
done
}