Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #14684 #14689 #14690 #16719 upstream release 1.1 #16886

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cluster/gce/config-test.sh
Expand Up @@ -118,7 +118,7 @@ if [[ "${ENABLE_HORIZONTAL_POD_AUTOSCALER}" == "true" ]]; then
fi

# Optional: Enable deployment experimental feature, not ready for production use.
ENABLE_DEPLOYMENTS="${KUBE_ENABLE_DEPLOYMENTS:-false}"
ENABLE_DEPLOYMENTS="${KUBE_ENABLE_DEPLOYMENTS:-true}"
if [[ "${ENABLE_DEPLOYMENTS}" == "true" ]]; then
ENABLE_EXPERIMENTAL_API=true
fi
Expand Down
11 changes: 3 additions & 8 deletions cluster/gce/coreos/helper.sh
Expand Up @@ -148,15 +148,10 @@ function create-master-instance {

# TODO(dawnchen): Check $CONTAINER_RUNTIME to decide which
# cloud_config yaml file should be passed
# TODO(zmerlynn): Make $1 required.
# TODO(zmerlynn): Document required vars (for this and call chain).
# $1 version
# $1: template name (required)
function create-node-instance-template {
local suffix=""
if [[ -n ${1:-} ]]; then
suffix="-${1}"
fi
create-node-template "${NODE_INSTANCE_PREFIX}-template${suffix}" "${scope_flags}" \
local template_name="$1"
create-node-template "$template_name" "${scope_flags}" \
"kube-env=${KUBE_TEMP}/node-kube-env.yaml" \
"user-data=${KUBE_ROOT}/cluster/gce/coreos/node.yaml"
}
11 changes: 3 additions & 8 deletions cluster/gce/debian/helper.sh
Expand Up @@ -167,15 +167,10 @@ function create-master-instance {
--disk "name=${MASTER_NAME}-pd,device-name=master-pd,mode=rw,boot=no,auto-delete=no"
}

# TODO(zmerlynn): Make $1 required.
# TODO(zmerlynn): Document required vars (for this and call chain).
# $1 version
# $1: template name (required)
function create-node-instance-template {
local suffix=""
if [[ -n ${1:-} ]]; then
suffix="-${1}"
fi
create-node-template "${NODE_INSTANCE_PREFIX}-template${suffix}" "${scope_flags}" \
local template_name="$1"
create-node-template "$template_name" "${scope_flags}" \
"startup-script=${KUBE_ROOT}/cluster/gce/configure-vm.sh" \
"kube-env=${KUBE_TEMP}/node-kube-env.yaml"
}
11 changes: 3 additions & 8 deletions cluster/gce/trusty/helper.sh 100644 → 100755
Expand Up @@ -27,15 +27,10 @@
# create-node-instance-template function to use Ubuntu.
source "${KUBE_ROOT}/cluster/gce/debian/helper.sh"

# TODO(andyzheng0831): Make $1 required.
# TODO(andyzheng0831): Document required vars (for this and call chain).
# $1 version
# $1: template name (required)
function create-node-instance-template {
local suffix=""
if [[ -n ${1:-} ]]; then
suffix="-${1}"
fi
create-node-template "${NODE_INSTANCE_PREFIX}-template${suffix}" "${scope_flags[*]}" \
local template_name="$1"
create-node-template "$template_name" "${scope_flags[*]}" \
"kube-env=${KUBE_TEMP}/node-kube-env.yaml" \
"user-data=${KUBE_ROOT}/cluster/gce/trusty/node.yaml"
}
10 changes: 6 additions & 4 deletions cluster/gce/upgrade.sh
Expand Up @@ -173,7 +173,7 @@ function upgrade-nodes() {
# KUBELET_KEY_BASE64
function prepare-node-upgrade() {
echo "== Preparing node upgrade (to ${KUBE_VERSION}). ==" >&2
SANITIZED_VERSION=$(echo ${KUBE_VERSION} | sed s/"\."/-/g)
SANITIZED_VERSION=$(echo ${KUBE_VERSION} | sed 's/[\.\+]/-/g')

detect-minion-names

Expand All @@ -200,9 +200,10 @@ function prepare-node-upgrade() {

# TODO(zmerlynn): Get configure-vm script from ${version}. (Must plumb this
# through all create-node-instance-template implementations).
create-node-instance-template ${SANITIZED_VERSION}
local template_name=$(get-template-name-from-version ${SANITIZED_VERSION})
create-node-instance-template "${template_name}"
# The following is echo'd so that callers can get the template name.
echo "${NODE_INSTANCE_PREFIX}-template-${SANITIZED_VERSION}"
echo $template_name
echo "== Finished preparing node upgrade (to ${KUBE_VERSION}). ==" >&2
}

Expand All @@ -220,12 +221,13 @@ function do-node-upgrade() {
if [[ "${exists}" != "0" ]]; then
subgroup="alpha compute"
fi
local template_name=$(get-template-name-from-version ${SANITIZED_VERSION})
gcloud ${subgroup} rolling-updates \
--project="${PROJECT}" \
--zone="${ZONE}" \
start \
--group="${NODE_INSTANCE_PREFIX}-group" \
--template="${NODE_INSTANCE_PREFIX}-template-${SANITIZED_VERSION}" \
--template="${template_name}" \
--instance-startup-timeout=300s \
--max-num-concurrent-instances=1 \
--max-num-failed-instances=0 \
Expand Down
38 changes: 25 additions & 13 deletions cluster/gce/util.sh
Expand Up @@ -345,21 +345,28 @@ function create-firewall-rule {
done
}

# $1: version (required)
function get-template-name-from-version {
# trim template name to pass gce name validation
echo "${NODE_INSTANCE_PREFIX}-template-${1}" | cut -c 1-63 | sed 's/[\.\+]/-/g;s/-*$//g'
}

# Robustly try to create an instance template.
# $1: The name of the instance template.
# $2: The scopes flag.
# $3: The minion start script metadata from file.
# $4: The kube-env metadata.
function create-node-template {
detect-project
local template_name="$1"

# First, ensure the template doesn't exist.
# TODO(zmerlynn): To make this really robust, we need to parse the output and
# add retries. Just relying on a non-zero exit code doesn't
# distinguish an ephemeral failed call from a "not-exists".
if gcloud compute instance-templates describe "$1" --project "${PROJECT}" &>/dev/null; then
if gcloud compute instance-templates describe "$template_name" --project "${PROJECT}" &>/dev/null; then
echo "Instance template ${1} already exists; deleting." >&2
if ! gcloud compute instance-templates delete "$1" --project "${PROJECT}" &>/dev/null; then
if ! gcloud compute instance-templates delete "$template_name" --project "${PROJECT}" &>/dev/null; then
echo -e "${color_yellow}Failed to delete existing instance template${color_norm}" >&2
exit 2
fi
Expand All @@ -372,7 +379,7 @@ function create-node-template {
fi
while true; do
echo "Attempt ${attempt} to create ${1}" >&2
if ! gcloud compute instance-templates create "$1" \
if ! gcloud compute instance-templates create "$template_name" \
--project "${PROJECT}" \
--machine-type "${MINION_SIZE}" \
--boot-disk-type "${MINION_DISK_TYPE}" \
Expand All @@ -386,10 +393,10 @@ function create-node-template {
--can-ip-forward \
--metadata-from-file "$3","$4" >&2; then
if (( attempt > 5 )); then
echo -e "${color_red}Failed to create instance template $1 ${color_norm}" >&2
echo -e "${color_red}Failed to create instance template $template_name ${color_norm}" >&2
exit 2
fi
echo -e "${color_yellow}Attempt ${attempt} failed to create instance template $1. Retrying.${color_norm}" >&2
echo -e "${color_yellow}Attempt ${attempt} failed to create instance template $template_name. Retrying.${color_norm}" >&2
attempt=$(($attempt+1))
else
break
Expand Down Expand Up @@ -663,15 +670,18 @@ function kube-up {
fi

write-node-env
create-node-instance-template

local template_name="${NODE_INSTANCE_PREFIX}-template"

create-node-instance-template $template_name

gcloud compute instance-groups managed \
create "${NODE_INSTANCE_PREFIX}-group" \
--project "${PROJECT}" \
--zone "${ZONE}" \
--base-instance-name "${NODE_INSTANCE_PREFIX}" \
--size "${NUM_MINIONS}" \
--template "${NODE_INSTANCE_PREFIX}-template" || true;
--template "$template_name" || true;
gcloud compute instance-groups managed wait-until-stable \
"${NODE_INSTANCE_PREFIX}-group" \
--zone "${ZONE}" \
Expand Down Expand Up @@ -1034,31 +1044,33 @@ function prepare-push() {

# Ugly hack: Since it is not possible to delete instance-template that is currently
# being used, create a temp one, then delete the old one and recreate it once again.
create-node-instance-template "tmp"
local tmp_template_name="${NODE_INSTANCE_PREFIX}-template-tmp"
create-node-instance-template $tmp_template_name

local template_name="${NODE_INSTANCE_PREFIX}-template"
gcloud compute instance-groups managed \
set-instance-template "${NODE_INSTANCE_PREFIX}-group" \
--template "${NODE_INSTANCE_PREFIX}-template-tmp" \
--template "$tmp_template_name" \
--zone "${ZONE}" \
--project "${PROJECT}" || true;

gcloud compute instance-templates delete \
--project "${PROJECT}" \
--quiet \
"${NODE_INSTANCE_PREFIX}-template" || true
"$template_name" || true

create-node-instance-template
create-node-instance-template "$template_name"

gcloud compute instance-groups managed \
set-instance-template "${NODE_INSTANCE_PREFIX}-group" \
--template "${NODE_INSTANCE_PREFIX}-template" \
--template "$template_name" \
--zone "${ZONE}" \
--project "${PROJECT}" || true;

gcloud compute instance-templates delete \
--project "${PROJECT}" \
--quiet \
"${NODE_INSTANCE_PREFIX}-template-tmp" || true
"$tmp_template_name" || true
fi
}

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/cluster_upgrade.go
Expand Up @@ -522,8 +522,8 @@ func migTemplate() (string, error) {
// An `instance-groups managed describe` call outputs what we want to stdout.
output, _, err := retryCmd("gcloud", "compute", "instance-groups", "managed",
fmt.Sprintf("--project=%s", testContext.CloudConfig.ProjectID),
fmt.Sprintf("--zone=%s", testContext.CloudConfig.Zone),
"describe",
fmt.Sprintf("--zone=%s", testContext.CloudConfig.Zone),
testContext.CloudConfig.NodeInstanceGroup)
if err != nil {
errLast = fmt.Errorf("gcloud compute instance-groups managed describe call failed with err: %v", err)
Expand Down