From e82c3fbd73c0857ff238345e8a623c8bcbd7faac Mon Sep 17 00:00:00 2001 From: Ben Breslauer Date: Wed, 10 Aug 2016 18:08:01 -0700 Subject: [PATCH] Add user-specified kubectl arguments to addons start script --- cluster/addons/addon-manager/kube-addon-update.sh | 9 +++++---- cluster/addons/addon-manager/kube-addons.sh | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cluster/addons/addon-manager/kube-addon-update.sh b/cluster/addons/addon-manager/kube-addon-update.sh index 87d47869ce2..481eb6f943e 100755 --- a/cluster/addons/addon-manager/kube-addon-update.sh +++ b/cluster/addons/addon-manager/kube-addon-update.sh @@ -49,6 +49,7 @@ if [[ ! -x ${KUBECTL} ]]; then echo "ERROR: kubectl command (${KUBECTL}) not found or is not executable" 1>&2 exit 1 fi +KUBECTL_OPTS=${KUBECTL_OPTS:-} # If an add-on definition is incorrect, or a definition has just disappeared # from the local directory, the script will still keep on retrying. @@ -196,7 +197,7 @@ function run-until-success() { # returns a list of / pairs (nsnames) function get-addon-nsnames-from-server() { local -r obj_type=$1 - "${KUBECTL}" get "${obj_type}" --all-namespaces -o go-template="{{range.items}}{{.metadata.namespace}}/{{.metadata.name}} {{end}}" -l kubernetes.io/cluster-service=true | sed 's///g' + "${KUBECTL}" "${KUBECTL_OPTS}" get "${obj_type}" --all-namespaces -o go-template="{{range.items}}{{.metadata.namespace}}/{{.metadata.name}} {{end}}" -l kubernetes.io/cluster-service=true | sed 's///g' } # returns the characters after the last separator (including) @@ -242,7 +243,7 @@ function delete-object() { local -r obj_name=$3 log INFO "Deleting ${obj_type} ${namespace}/${obj_name}" - run-until-success "${KUBECTL} delete --namespace=${namespace} ${obj_type} ${obj_name}" ${NUM_TRIES} ${DELAY_AFTER_ERROR_SEC} + run-until-success "${KUBECTL} ${KUBECTL_OPTS} delete --namespace=${namespace} ${obj_type} ${obj_name}" ${NUM_TRIES} ${DELAY_AFTER_ERROR_SEC} } function create-object() { @@ -261,9 +262,9 @@ function create-object() { # this will keep on failing if the ${file_path} disappeared in the meantime. # Do not use too many retries. if [[ -n "${namespace}" ]]; then - run-until-success "${KUBECTL} create --namespace=${namespace} -f ${file_path}" ${NUM_TRIES} ${DELAY_AFTER_ERROR_SEC} + run-until-success "${KUBECTL} ${KUBECTL_OPTS} create --namespace=${namespace} -f ${file_path}" ${NUM_TRIES} ${DELAY_AFTER_ERROR_SEC} else - run-until-success "${KUBECTL} create -f ${file_path}" ${NUM_TRIES} ${DELAY_AFTER_ERROR_SEC} + run-until-success "${KUBECTL} ${KUBECTL_OPTS} create -f ${file_path}" ${NUM_TRIES} ${DELAY_AFTER_ERROR_SEC} fi } diff --git a/cluster/addons/addon-manager/kube-addons.sh b/cluster/addons/addon-manager/kube-addons.sh index f62a192512d..fccc38c905c 100755 --- a/cluster/addons/addon-manager/kube-addons.sh +++ b/cluster/addons/addon-manager/kube-addons.sh @@ -18,6 +18,7 @@ # was already enforced by salt, and /etc/kubernetes/addons is the # managed result is of that. Start everything below that directory. KUBECTL=${KUBECTL_BIN:-/usr/local/bin/kubectl} +KUBECTL_OPTS=${KUBECTL_OPTS:-} ADDON_CHECK_INTERVAL_SEC=${TEST_ADDON_CHECK_INTERVAL_SEC:-60} @@ -49,7 +50,7 @@ function create-resource-from-string() { local -r config_name=$4; local -r namespace=$5; while [ ${tries} -gt 0 ]; do - echo "${config_string}" | ${KUBECTL} --namespace="${namespace}" apply -f - && \ + echo "${config_string}" | ${KUBECTL} ${KUBECTL_OPTS} --namespace="${namespace}" apply -f - && \ echo "== Successfully started ${config_name} in namespace ${namespace} at $(date -Is)" && \ return 0; let tries=tries-1; @@ -71,7 +72,7 @@ start_addon /opt/namespace.yaml 100 10 "" & token_found="" while [ -z "${token_found}" ]; do sleep .5 - token_found=$(${KUBECTL} get --namespace="${SYSTEM_NAMESPACE}" serviceaccount default -o go-template="{{with index .secrets 0}}{{.name}}{{end}}" || true) + token_found=$(${KUBECTL} ${KUBECTL_OPTS} get --namespace="${SYSTEM_NAMESPACE}" serviceaccount default -o go-template="{{with index .secrets 0}}{{.name}}{{end}}" || true) done echo "== default service account in the ${SYSTEM_NAMESPACE} namespace has token ${token_found} =="