From d87e700f9bdade96a3115660a8c150d0a75569ad Mon Sep 17 00:00:00 2001 From: Matt Matejczyk Date: Wed, 23 Oct 2019 12:02:53 +0200 Subject: [PATCH] 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. --- cluster/addons/addon-manager/kube-addons.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cluster/addons/addon-manager/kube-addons.sh b/cluster/addons/addon-manager/kube-addons.sh index 95b0262e958..acabd0191e6 100755 --- a/cluster/addons/addon-manager/kube-addons.sh +++ b/cluster/addons/addon-manager/kube-addons.sh @@ -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 }