diff --git a/cluster/gce/upgrade.sh b/cluster/gce/upgrade.sh index 6f129dff923f2..88a809e994972 100755 --- a/cluster/gce/upgrade.sh +++ b/cluster/gce/upgrade.sh @@ -79,23 +79,7 @@ function upgrade-master() { --zone "${ZONE}" \ "${MASTER_NAME}" - write-master-env - gcloud compute instances create "${MASTER_NAME}" \ - --address "${MASTER_NAME}-ip" \ - --project "${PROJECT}" \ - --zone "${ZONE}" \ - --machine-type "${MASTER_SIZE}" \ - --image-project="${IMAGE_PROJECT}" \ - --image "${IMAGE}" \ - --tags "${MASTER_TAG}" \ - --network "${NETWORK}" \ - --scopes "storage-ro" "compute-rw" \ - --can-ip-forward \ - --metadata-from-file \ - "startup-script=${KUBE_ROOT}/cluster/gce/configure-vm.sh" \ - "kube-env=${KUBE_TEMP}/master-kube-env.yaml" \ - --disk name="${MASTER_NAME}-pd" device-name=master-pd mode=rw boot=no auto-delete=no - + create-master-instance "${MASTER_NAME}-ip" wait-for-master } diff --git a/cluster/gce/util.sh b/cluster/gce/util.sh index 19b564aac78dd..c15631fccfd20 100755 --- a/cluster/gce/util.sh +++ b/cluster/gce/util.sh @@ -487,6 +487,42 @@ function write-node-env { build-kube-env false "${KUBE_TEMP}/node-kube-env.yaml" } +# create-master-instance creates the master instance. If called with +# an argument, the argument is used as the name to a reserved IP +# address for the master. (In the case of upgrade/repair, we re-use +# the same IP.) +# +# It requires a whole slew of assumed variables, partially due to to +# the call to write-master-env. Listing them would be rather +# futile. Instead, we list the required calls to ensure any additional +# variables are set: +# ensure-temp-dir +# detect-project +# get-password +# set-master-htpasswd +# +function create-master-instance { + local address_opt="" + [[ -n ${1:-} ]] && address_opt="--address ${1}" + + write-master-env + gcloud compute instances create "${MASTER_NAME}" \ + ${address_opt} \ + --project "${PROJECT}" \ + --zone "${ZONE}" \ + --machine-type "${MASTER_SIZE}" \ + --image-project="${IMAGE_PROJECT}" \ + --image "${IMAGE}" \ + --tags "${MASTER_TAG}" \ + --network "${NETWORK}" \ + --scopes "storage-ro" "compute-rw" \ + --can-ip-forward \ + --metadata-from-file \ + "startup-script=${KUBE_ROOT}/cluster/gce/configure-vm.sh" \ + "kube-env=${KUBE_TEMP}/master-kube-env.yaml" \ + --disk name="${MASTER_NAME}-pd" device-name=master-pd mode=rw boot=no auto-delete=no +} + # Instantiate a kubernetes cluster # # Assumed vars @@ -546,21 +582,7 @@ function kube-up { # https://github.com/GoogleCloudPlatform/kubernetes/issues/3168 KUBELET_TOKEN=$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64 | tr -d "=+/" | dd bs=32 count=1 2>/dev/null) - write-master-env - gcloud compute instances create "${MASTER_NAME}" \ - --project "${PROJECT}" \ - --zone "${ZONE}" \ - --machine-type "${MASTER_SIZE}" \ - --image-project="${IMAGE_PROJECT}" \ - --image "${IMAGE}" \ - --tags "${MASTER_TAG}" \ - --network "${NETWORK}" \ - --scopes "storage-ro" "compute-rw" \ - --can-ip-forward \ - --metadata-from-file \ - "startup-script=${KUBE_ROOT}/cluster/gce/configure-vm.sh" \ - "kube-env=${KUBE_TEMP}/master-kube-env.yaml" \ - --disk name="${MASTER_NAME}-pd" device-name=master-pd mode=rw boot=no auto-delete=no & + create-master-instance & # Create a single firewall rule for all minions. create-firewall-rule "${MINION_TAG}-all" "${CLUSTER_IP_RANGE}" "${MINION_TAG}" &