diff --git a/cluster/gce/upgrade.sh b/cluster/gce/upgrade.sh index 9422548799..62594ba0e1 100755 --- a/cluster/gce/upgrade.sh +++ b/cluster/gce/upgrade.sh @@ -267,7 +267,7 @@ function prepare-node-upgrade() { # TODO(zmerlynn): Get configure-vm script from ${version}. (Must plumb this # through all create-linux-node-instance-template implementations). - local template_name=$(get-template-name-from-version ${SANITIZED_VERSION}) + local template_name=$(get-template-name-from-version ${SANITIZED_VERSION} ${NODE_INSTANCE_PREFIX}) create-linux-node-instance-template "${template_name}" # The following is echo'd so that callers can get the template name. echo "Instance template name: ${template_name}" @@ -373,7 +373,7 @@ function do-node-upgrade() { # Do the actual upgrade. # NOTE(zmerlynn): If you are changing this gcloud command, update # test/e2e/cluster_upgrade.go to match this EXACTLY. - local template_name=$(get-template-name-from-version ${SANITIZED_VERSION}) + local template_name=$(get-template-name-from-version ${SANITIZED_VERSION} ${NODE_INSTANCE_PREFIX}) local old_templates=() local updates=() for group in ${INSTANCE_GROUPS[@]}; do diff --git a/cluster/gce/util.sh b/cluster/gce/util.sh index 99ea09119f..d253a1183f 100755 --- a/cluster/gce/util.sh +++ b/cluster/gce/util.sh @@ -112,7 +112,10 @@ if [[ "${ENABLE_CLUSTER_AUTOSCALER}" == "true" ]]; then fi fi +# These prefixes must not be prefixes of each other, so that they can be used to +# detect mutually exclusive sets of nodes. NODE_INSTANCE_PREFIX=${NODE_INSTANCE_PREFIX:-"${INSTANCE_PREFIX}-minion"} +WINDOWS_NODE_INSTANCE_PREFIX=${WINDOWS_NODE_INSTANCE_PREFIX:-"${INSTANCE_PREFIX}-windows-node"} NODE_TAGS="${NODE_TAG}" @@ -373,9 +376,12 @@ function upload-tars() { # # Assumed vars: # NODE_INSTANCE_PREFIX +# WINDOWS_NODE_INSTANCE_PREFIX # Vars set: # NODE_NAMES # INSTANCE_GROUPS +# WINDOWS_NODE_NAMES +# WINDOWS_INSTANCE_GROUPS function detect-node-names() { detect-project INSTANCE_GROUPS=() @@ -383,6 +389,12 @@ function detect-node-names() { --project "${PROJECT}" \ --filter "name ~ '${NODE_INSTANCE_PREFIX}-.+' AND zone:(${ZONE})" \ --format='value(name)' || true)) + WINDOWS_INSTANCE_GROUPS=() + WINDOWS_INSTANCE_GROUPS+=($(gcloud compute instance-groups managed list \ + --project "${PROJECT}" \ + --filter "name ~ '${WINDOWS_NODE_INSTANCE_PREFIX}-.+' AND zone:(${ZONE})" \ + --format='value(name)' || true)) + NODE_NAMES=() if [[ -n "${INSTANCE_GROUPS[@]:-}" ]]; then for group in "${INSTANCE_GROUPS[@]}"; do @@ -395,6 +407,14 @@ function detect-node-names() { if [[ -n "${HEAPSTER_MACHINE_TYPE:-}" ]]; then NODE_NAMES+=("${NODE_INSTANCE_PREFIX}-heapster") fi + WINDOWS_NODE_NAMES=() + if [[ -n "${WINDOWS_INSTANCE_GROUPS[@]:-}" ]]; then + for group in "${WINDOWS_INSTANCE_GROUPS[@]}"; do + WINDOWS_NODE_NAMES+=($(gcloud compute instance-groups managed \ + list-instances "${group}" --zone "${ZONE}" --project "${PROJECT}" \ + --format='value(instance)')) + done + fi echo "INSTANCE_GROUPS=${INSTANCE_GROUPS[*]:-}" >&2 echo "NODE_NAMES=${NODE_NAMES[*]:-}" >&2 @@ -1403,6 +1423,7 @@ function build-windows-kube-env { build-linux-kube-env false $file cat >>$file </dev/null; then gcloud compute instance-groups managed delete \ --project "${PROJECT}" \ @@ -3087,7 +3113,7 @@ function kube-down() { local -a minions minions=( $(gcloud compute instances list \ --project "${PROJECT}" \ - --filter="name ~ '${NODE_INSTANCE_PREFIX}-.+' AND zone:(${ZONE})" \ + --filter="(name ~ '${NODE_INSTANCE_PREFIX}-.+' OR name ~ '${WINDOWS_NODE_INSTANCE_PREFIX}-.+') AND zone:(${ZONE})" \ --format='value(name)') ) # If any minions are running, delete them in batches. while (( "${#minions[@]}" > 0 )); do @@ -3242,15 +3268,19 @@ function set-replica-name() { REPLICA_NAME="${MASTER_NAME}-${suffix}" } -# Gets the instance template for given NODE_INSTANCE_PREFIX. It echos the template name so that the function -# output can be used. +# Gets the instance templates in use by the cluster. It echos the template names +# so that the function output can be used. # Assumed vars: # NODE_INSTANCE_PREFIX +# WINDOWS_NODE_INSTANCE_PREFIX # # $1: project function get-template() { + local linux_filter="${NODE_INSTANCE_PREFIX}-template(-(${KUBE_RELEASE_VERSION_DASHED_REGEX}|${KUBE_CI_VERSION_DASHED_REGEX}))?" + local windows_filter="${WINDOWS_NODE_INSTANCE_PREFIX}-template(-(${KUBE_RELEASE_VERSION_DASHED_REGEX}|${KUBE_CI_VERSION_DASHED_REGEX}))?" + gcloud compute instance-templates list \ - --filter="name ~ '${NODE_INSTANCE_PREFIX}-template(-(${KUBE_RELEASE_VERSION_DASHED_REGEX}|${KUBE_CI_VERSION_DASHED_REGEX}))?'" \ + --filter="name ~ '${linux_filter}' OR name ~ '${windows_filter}'" \ --project="${1}" --format='value(name)' } @@ -3259,6 +3289,7 @@ function get-template() { # Assumed vars: # MASTER_NAME # NODE_INSTANCE_PREFIX +# WINDOWS_NODE_INSTANCE_PREFIX # ZONE # REGION # Vars set: @@ -3274,11 +3305,19 @@ function check-resources() { KUBE_RESOURCE_FOUND="Managed instance groups ${INSTANCE_GROUPS[@]}" return 1 fi + if [[ -n "${WINDOWS_INSTANCE_GROUPS[@]:-}" ]]; then + KUBE_RESOURCE_FOUND="Managed instance groups ${WINDOWS_INSTANCE_GROUPS[@]}" + return 1 + fi if gcloud compute instance-templates describe --project "${PROJECT}" "${NODE_INSTANCE_PREFIX}-template" &>/dev/null; then KUBE_RESOURCE_FOUND="Instance template ${NODE_INSTANCE_PREFIX}-template" return 1 fi + if gcloud compute instance-templates describe --project "${PROJECT}" "${WINDOWS_NODE_INSTANCE_PREFIX}-template" &>/dev/null; then + KUBE_RESOURCE_FOUND="Instance template ${WINDOWS_NODE_INSTANCE_PREFIX}-template" + return 1 + fi if gcloud compute instances describe --project "${PROJECT}" "${MASTER_NAME}" --zone "${ZONE}" &>/dev/null; then KUBE_RESOURCE_FOUND="Kubernetes master ${MASTER_NAME}" @@ -3294,10 +3333,10 @@ function check-resources() { local -a minions minions=( $(gcloud compute instances list \ --project "${PROJECT}" \ - --filter="name ~ '${NODE_INSTANCE_PREFIX}-.+' AND zone:(${ZONE})" \ + --filter="(name ~ '${NODE_INSTANCE_PREFIX}-.+' OR name ~ '${WINDOWS_NODE_INSTANCE_PREFIX}-.+') AND zone:(${ZONE})" \ --format='value(name)') ) if (( "${#minions[@]}" > 0 )); then - KUBE_RESOURCE_FOUND="${#minions[@]} matching matching ${NODE_INSTANCE_PREFIX}-.+" + KUBE_RESOURCE_FOUND="${#minions[@]} matching ${NODE_INSTANCE_PREFIX}-.+ or ${WINDOWS_NODE_INSTANCE_PREFIX}-.+" return 1 fi diff --git a/cluster/validate-cluster.sh b/cluster/validate-cluster.sh index 3f7cd3d29c..c28dcb0df5 100755 --- a/cluster/validate-cluster.sh +++ b/cluster/validate-cluster.sh @@ -56,7 +56,7 @@ if [[ "${KUBERNETES_PROVIDER:-}" == "gce" ]]; then # In multizone mode we need to add instances for all nodes in the region. if [[ "${MULTIZONE:-}" == "true" ]]; then EXPECTED_NUM_NODES=$(gcloud -q compute instances list --project="${PROJECT}" --format=[no-heading] \ - --filter="name ~ '${NODE_INSTANCE_PREFIX}.*' AND zone:($(gcloud -q compute zones list --project="${PROJECT}" --filter=region=${REGION} --format=csv[no-heading]\(name\) | tr "\n" "," | sed "s/,$//"))" | wc -l) + --filter="(name ~ '${NODE_INSTANCE_PREFIX}.*' OR name ~ '${WINDOWS_NODE_INSTANCE_PREFIX}.*') AND zone:($(gcloud -q compute zones list --project="${PROJECT}" --filter=region=${REGION} --format=csv[no-heading]\(name\) | tr "\n" "," | sed "s/,$//"))" | wc -l) echo "Computing number of nodes, NODE_INSTANCE_PREFIX=${NODE_INSTANCE_PREFIX}, REGION=${REGION}, EXPECTED_NUM_NODES=${EXPECTED_NUM_NODES}" fi else