Merge pull request #30372 from bbreslauer/addons-kubectl-opts

Automatic merge from submit-queue

Add user-specified kubectl arguments to addons start script

This is a simple way, using the same environment variable paradigm used throughout these scripts, to let a user specify kubectl arguments to the addons script.

fixes #30371
pull/6/head
Kubernetes Submit Queue 2016-08-13 00:20:33 -07:00 committed by GitHub
commit 9f8625fb2c
2 changed files with 8 additions and 6 deletions

View File

@ -49,6 +49,7 @@ if [[ ! -x ${KUBECTL} ]]; then
echo "ERROR: kubectl command (${KUBECTL}) not found or is not executable" 1>&2 echo "ERROR: kubectl command (${KUBECTL}) not found or is not executable" 1>&2
exit 1 exit 1
fi fi
KUBECTL_OPTS=${KUBECTL_OPTS:-}
# If an add-on definition is incorrect, or a definition has just disappeared # If an add-on definition is incorrect, or a definition has just disappeared
# from the local directory, the script will still keep on retrying. # from the local directory, the script will still keep on retrying.
@ -196,7 +197,7 @@ function run-until-success() {
# returns a list of <namespace>/<name> pairs (nsnames) # returns a list of <namespace>/<name> pairs (nsnames)
function get-addon-nsnames-from-server() { function get-addon-nsnames-from-server() {
local -r obj_type=$1 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/<no value>//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/<no value>//g'
} }
# returns the characters after the last separator (including) # returns the characters after the last separator (including)
@ -242,7 +243,7 @@ function delete-object() {
local -r obj_name=$3 local -r obj_name=$3
log INFO "Deleting ${obj_type} ${namespace}/${obj_name}" 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() { function create-object() {
@ -261,9 +262,9 @@ function create-object() {
# this will keep on failing if the ${file_path} disappeared in the meantime. # this will keep on failing if the ${file_path} disappeared in the meantime.
# Do not use too many retries. # Do not use too many retries.
if [[ -n "${namespace}" ]]; then 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 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 fi
} }

View File

@ -18,6 +18,7 @@
# was already enforced by salt, and /etc/kubernetes/addons is the # was already enforced by salt, and /etc/kubernetes/addons is the
# managed result is of that. Start everything below that directory. # managed result is of that. Start everything below that directory.
KUBECTL=${KUBECTL_BIN:-/usr/local/bin/kubectl} KUBECTL=${KUBECTL_BIN:-/usr/local/bin/kubectl}
KUBECTL_OPTS=${KUBECTL_OPTS:-}
ADDON_CHECK_INTERVAL_SEC=${TEST_ADDON_CHECK_INTERVAL_SEC:-60} 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 config_name=$4;
local -r namespace=$5; local -r namespace=$5;
while [ ${tries} -gt 0 ]; do 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)" && \ echo "== Successfully started ${config_name} in namespace ${namespace} at $(date -Is)" && \
return 0; return 0;
let tries=tries-1; let tries=tries-1;
@ -71,7 +72,7 @@ start_addon /opt/namespace.yaml 100 10 "" &
token_found="" token_found=""
while [ -z "${token_found}" ]; do while [ -z "${token_found}" ]; do
sleep .5 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 done
echo "== default service account in the ${SYSTEM_NAMESPACE} namespace has token ${token_found} ==" echo "== default service account in the ${SYSTEM_NAMESPACE} namespace has token ${token_found} =="