From 3742cc6f27d1a83d89611976b24007a404541394 Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Wed, 5 Oct 2016 10:09:28 +0200 Subject: [PATCH 01/17] Run integration tests with 3.0.10 etcd underneath --- build/build-image/cross/Dockerfile | 2 +- build/build-image/cross/VERSION | 2 +- hack/lib/etcd.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/build-image/cross/Dockerfile b/build/build-image/cross/Dockerfile index 8f5c117abec36..384dff23b0987 100644 --- a/build/build-image/cross/Dockerfile +++ b/build/build-image/cross/Dockerfile @@ -72,7 +72,7 @@ RUN mkdir $TMPDIR \ github.com/jteeuwen/go-bindata/go-bindata # Download and symlink etcd. We need this for our integration tests. -RUN export ETCD_VERSION=v2.2.1; \ +RUN export ETCD_VERSION=v3.0.10; \ mkdir -p /usr/local/src/etcd \ && cd /usr/local/src/etcd \ && curl -fsSL https://github.com/coreos/etcd/releases/download/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-amd64.tar.gz | tar -xz \ diff --git a/build/build-image/cross/VERSION b/build/build-image/cross/VERSION index 23f60f9010d30..38e95fa75935b 100644 --- a/build/build-image/cross/VERSION +++ b/build/build-image/cross/VERSION @@ -1 +1 @@ -v1.6.3-8 +v1.6.3-9 diff --git a/hack/lib/etcd.sh b/hack/lib/etcd.sh index 0996228950378..c99dcebeb8825 100644 --- a/hack/lib/etcd.sh +++ b/hack/lib/etcd.sh @@ -16,7 +16,7 @@ # A set of helpers for starting/running etcd for tests -ETCD_VERSION=${ETCD_VERSION:-2.2.1} +ETCD_VERSION=${ETCD_VERSION:-3.0.10} ETCD_HOST=${ETCD_HOST:-127.0.0.1} ETCD_PORT=${ETCD_PORT:-2379} From 4b4bbff739e5c88fc4d9bbcea04ad2a11b638200 Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Wed, 5 Oct 2016 10:13:23 +0200 Subject: [PATCH 02/17] Start testing etcd2->etcd3 migration in test-update-storage-objects --- hack/test-update-storage-objects.sh | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/hack/test-update-storage-objects.sh b/hack/test-update-storage-objects.sh index 9885aeacad3a1..bcb98f271d74c 100755 --- a/hack/test-update-storage-objects.sh +++ b/hack/test-update-storage-objects.sh @@ -157,15 +157,14 @@ killApiServer # We always perform offline migration, so we need to stop etcd. ####################################################### -# TODO: Uncomment once we support migration. -#kube::etcd::stop -#TARGET_STORAGE="etcd3" \ -# DATA_DIRECTORY="${ETCD_DIR}" \ -# ETCD=$(which etcd) \ -# ETCDCTL=$(which etcdctl) \ -# ATTACHLEASE="${KUBE_OUTPUT_HOSTBIN}/attachlease" \ -# ${KUBE_ROOT}/cluster/images/etcd/migrate-if-needed.sh -#kube::etcd::start +kube::etcd::stop +TARGET_STORAGE="etcd3" \ + DATA_DIRECTORY="${ETCD_DIR}" \ + ETCD=$(which etcd) \ + ETCDCTL=$(which etcdctl) \ + ATTACHLEASE="${KUBE_OUTPUT_HOSTBIN}/attachlease" \ + ${KUBE_ROOT}/cluster/images/etcd/migrate-if-needed.sh +kube::etcd::start ####################################################### @@ -176,8 +175,7 @@ killApiServer KUBE_API_VERSIONS="${KUBE_NEW_API_VERSION},${KUBE_OLD_API_VERSION}" RUNTIME_CONFIG="api/all=false,api/${KUBE_OLD_API_VERSION}=true,api/${KUBE_NEW_API_VERSION}=true" -# TODO: Switch to STORAGE_BACKEND_ETCD3 once we support it. -startApiServer ${STORAGE_BACKEND_ETCD2} ${KUBE_NEW_STORAGE_VERSIONS} ${KUBE_STORAGE_MEDIA_TYPE_JSON} +startApiServer ${STORAGE_BACKEND_ETCD3} ${KUBE_NEW_STORAGE_VERSIONS} ${KUBE_STORAGE_MEDIA_TYPE_JSON} # Update etcd objects, so that will now be stored in the new api version. kube::log::status "Updating storage versions in etcd" @@ -192,8 +190,7 @@ for test in ${tests[@]}; do new_storage_version=${test_data[5]} kube::log::status "Verifying ${resource}/${namespace}/${name} has updated storage version ${new_storage_version} in etcd" - # note that should use flag --endpoints for etcdctl 3 - ${ETCDCTL} --endpoint="${ETCD_HOST}:${ETCD_PORT}" get "/${ETCD_PREFIX}/${resource}/${namespace}/${name}" | grep ${new_storage_version} + ETCDCTL_API=3 ${ETCDCTL} --endpoints="${ETCD_HOST}:${ETCD_PORT}" get "/${ETCD_PREFIX}/${resource}/${namespace}/${name}" | grep ${new_storage_version} done killApiServer @@ -209,8 +206,7 @@ RUNTIME_CONFIG="api/all=false,api/${KUBE_NEW_API_VERSION}=true" # This seems to reduce flakiness. sleep 1 -# TODO: Switch to STORAGE_BACKEND_ETCD3 once we support it. -startApiServer ${STORAGE_BACKEND_ETCD2} ${KUBE_NEW_STORAGE_VERSIONS} ${KUBE_STORAGE_MEDIA_TYPE_PROTOBUF} +startApiServer ${STORAGE_BACKEND_ETCD3} ${KUBE_NEW_STORAGE_VERSIONS} ${KUBE_STORAGE_MEDIA_TYPE_PROTOBUF} for test in ${tests[@]}; do IFS=',' read -ra test_data <<<"$test" From 8493d376e7ee660d255a7705a17e6e43943b4f1b Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Tue, 4 Oct 2016 10:15:12 +0200 Subject: [PATCH 03/17] Support upgrade/downgrade in etcd image. --- cluster/images/etcd/migrate-if-needed.sh | 184 +++++++++++++++++------ hack/test-update-storage-objects.sh | 2 + 2 files changed, 137 insertions(+), 49 deletions(-) diff --git a/cluster/images/etcd/migrate-if-needed.sh b/cluster/images/etcd/migrate-if-needed.sh index 4b4abe1701ae4..42508a3588d92 100755 --- a/cluster/images/etcd/migrate-if-needed.sh +++ b/cluster/images/etcd/migrate-if-needed.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Copyright 2016 The Kubernetes Authors. # @@ -14,49 +14,93 @@ # See the License for the specific language governing permissions and # limitations under the License. -# This script performs data migration between etcd2 and etcd3 versions -# if needed. -# Expected usage of it is: -# ./migrate_if_needed -# It will look into the contents of file /version.txt to -# determine the current storage version (no file means etcd2). +# NOTES +# This script performs etcd upgrade based on the following environmental +# variables: +# TARGET_STORAGE - API of etcd to be used (supported: 'etcd2', 'etcd3') +# TARGET_VERSION - etcd release to be used (supported: '2.2.1', '2.3.7', '3.0.10') +# DATA_DIRECTORY - directory with etcd data +# +# The current etcd version and storage format is detected based on the +# contents of "${DATA_DIRECTORY}/version.txt" file (if the file doesn't +# exist, we default it to "2.2.1/etcd2". +# +# The update workflow support the following upgrade steps: +# - 2.2.1/etcd2 -> 2.3.7/etcd2 +# - 2.3.7/etcd2 -> 3.0.10/etcd2 +# - 3.0.10/etcd2 -> 3.0.10/etcd3 +# +# NOTE: The releases supported in this script has to match release binaries +# present in the etcd image (to make this script work correctly). +# +# Based on the current etcd version and storage format we detect what +# upgrade step from this should be done to get reach target configuration set -o errexit set -o nounset if [ -z "${TARGET_STORAGE:-}" ]; then - echo "TARGET_USAGE variable unset - skipping migration" + echo "TARGET_STORAGE variable unset - skipping migration" + exit 0 +fi +if [ -z "${TARGET_VERSION:-}" ]; then + echo "TARGET_VERSION variable unset - skipping migration" exit 0 fi - if [ -z "${DATA_DIRECTORY:-}" ]; then echo "DATA_DIRECTORY variable unset - skipping migration" exit 0 fi -ETCD="${ETCD:-/usr/local/bin/etcd}" -ETCDCTL="${ETCDCTL:-/usr/local/bin/etcdctl}" -ATTACHLEASE="${ATTACHLEASE:-/usr/local/bin/attachlease}" +if [ "${TARGET_STORAGE}" != "etcd2" -a "${TARGET_STORAGE}" != "etcd3" ]; then + echo "Not supported version of storage: ${TARGET_STORAGE}" + exit 1 +fi + +# NOTE: SUPPORTED_VERSION has to match release binaries present in the +# etcd image (to make this script work correctly). +SUPPORTED_VERSIONS=("2.2.1" "2.3.7" "3.0.10") + VERSION_FILE="version.txt" -CURRENT_STORAGE='etcd2' +CURRENT_STORAGE="etcd2" +CURRENT_VERSION="2.2.1" if [ -e "${DATA_DIRECTORY}/${VERSION_FILE}" ]; then - CURRENT_STORAGE="$(cat ${DATA_DIRECTORY}/${VERSION_FILE})" + VERSION_CONTENTS="$(cat ${DATA_DIRECTORY}/${VERSION_FILE})" + # Example usage: if contents of VERSION_FILE is 2.3.7/etcd2, then + # - CURRENT_VERSION would be '2.3.7' + # - CURRENT_STORAGE would be 'etcd2' + CURRENT_VERSION="$(echo $VERSION_CONTENTS | cut -d '/' -f 1)" + CURRENT_STORAGE="$(echo $VERSION_CONTENTS | cut -d '/' -f 2)" fi +# Starts 'etcd' version ${START_VERSION} and writes to it: +# 'etcd_version' -> "${START_VERSION}" +# Successful write confirms that etcd is up and running. +# Sets ETCD_PID at the end. +# Returns 0 if etcd was successfully started, non-0 otherwise. start_etcd() { + # Use random ports, so that apiserver cannot connect to etcd. ETCD_PORT=18629 ETCD_PEER_PORT=18630 - ${ETCD} --data-dir=${DATA_DIRECTORY} \ + local ETCD_CMD="${ETCD:-/usr/local/bin/etcd-${START_VERSION}}" + local ETCDCTL_CMD="${ETCDCTL:-/usr/local/bin/etcdctl-${START_VERSION}}" + if [ "${START_VERSION:0:2}" == "2." ]; then + ETCDCTL_CMD="${ETCDCTL_CMD} --endpoint=http://127.0.0.1:${ETCD_PORT} set" + else + ETCDCTL_CMD="${ETCDCTL_CMD} --endpoints=http://127.0.0.1:${ETCD_PORT} put" + fi + ${ETCD_CMD} --data-dir=${DATA_DIRECTORY} \ --listen-client-urls http://127.0.0.1:${ETCD_PORT} \ --advertise-client-urls http://127.0.0.1:${ETCD_PORT} \ --listen-peer-urls http://127.0.0.1:${ETCD_PEER_PORT} \ --initial-advertise-peer-urls http://127.0.01:${ETCD_PEER_PORT} \ 1>>/dev/null 2>&1 & ETCD_PID=$! - # Wait until etcd is up. - for i in $(seq 30); do - local out - if out=$(wget -q --timeout=1 http://127.0.0.1:${ETCD_PORT}/v2/machines 2> /dev/null); then + local API_VERSION="${START_STORAGE:4:4}" + # Wait until we can write to etcd. + for i in $(seq 240); do + ETCDCTL_API="${API_VERSION}" ${ETCDCTL_CMD} 'etcd_version' ${START_VERSION} + if [ "$?" -eq "0" ]; then echo "Etcd on port ${ETCD_PORT} is up." return 0 fi @@ -66,43 +110,85 @@ start_etcd() { return 1 } +# Stops etcd with ${ETCD_PID} pid. stop_etcd() { kill "${ETCD_PID-}" >/dev/null 2>&1 || : wait "${ETCD_PID-}" >/dev/null 2>&1 || : } -if [ "${CURRENT_STORAGE}" = "etcd2" -a "${TARGET_STORAGE}" = "etcd3" ]; then - # If directory doesn't exist or is empty, this means that there aren't any - # data for migration, which means we can skip this step. +ATTACHLEASE="${ATTACHLEASE:-/usr/local/bin/attachlease}" +ROLLBACK="${ROLLBACK:-/usr/local/bin/rollback}" + +# Do the roll-forward migration if needed. +for step in "${SUPPORTED_VERSIONS[@]}"; do + if [ "${step}" == "${CURRENT_VERSION}" -a "${CURRENT_VERSION}" != "${TARGET_VERSION}" ]; then + # Do the migration step, by just starting etcd in this version. + START_VERSION="${step}" + START_STORAGE="${CURRENT_STORAGE}" + if ! start_etcd; then + # Migration failed. + echo "Starting etcd ${step} failed" + exit 1 + fi + # Kill etcd and wait until this is down. + stop_etcd + fi + CURRENT_VERSION=${step} + echo "${CURRENT_VERSION}/${CURRENT_STORAGE}" > "${DATA_DIRECTORY}/${VERSION_FILE}" + if [ "${CURRENT_VERSION:0:2}" == "3." -a "${CURRENT_STORAGE}" == "etcd2" -a "${TARGET_STORAGE}" == "etcd3" ]; then + # If it is the first 3.x release in the list and we are migrating + # also from 'etcd2' to 'etcd3', do the migration now. + if [ -d "${DATA_DIRECTORY}" ]; then + if [ "$(ls -A ${DATA_DIRECTORY})" ]; then + echo "Performing etcd2 -> etcd3 migration" + START_VERSION="${step}" + START_STORAGE="etcd3" + ETCDCTL_CMD="${ETCDCTL:-/usr/local/bin/etcdctl-${START_VERSION}}" + ETCDCTL_API=3 ${ETCDCTL_CMD} migrate --data-dir=${DATA_DIRECTORY} + echo "Attaching leases to TTL entries" + # Now attach lease to all keys. + # To do it, we temporarily start etcd on a random port (so that + # apiserver actually cannot access it). + if ! start_etcd; then + echo "Starting etcd ${step} in v3 mode failed" + exit 1 + fi + # Create a lease and attach all keys to it. + ${ATTACHLEASE} \ + --etcd-address http://127.0.0.1:${ETCD_PORT} \ + --ttl-keys-prefix "${TTL_KEYS_DIRECTORY:-/registry/events}" \ + --lease-duration 1h + # Kill etcd and wait until this is down. + stop_etcd + fi + fi + CURRENT_STORAGE="etcd3" + echo "${CURRENT_VERSION}/${CURRENT_STORAGE}" > "${DATA_DIRECTORY}/${VERSION_FILE}" + fi + if [ "${CURRENT_VERSION}" == "${TARGET_VERSION}" -a "${CURRENT_STORAGE}" == "${TARGET_STORAGE}" ]; then + break + fi +done + +# Do the rollback of needed. +# NOTE: Rollback is only supported from "3.0.x" version in 'etcd3' mode to +# "2.3.7" version in 'etcd2' mode. +if [ "${CURRENT_STORAGE}" == "etcd3" -a "${TARGET_STORAGE}" == "etcd2" ]; then + if [ "${CURRENT_VERSION:0:4}" != "3.0." -o "${TARGET_VERSION}" != "2.3.7" ]; then + echo "etcd3 -> etcd2 downgrade is supported only between 3.0.x and 2.3.7" + return 0 + fi if [ -d "${DATA_DIRECTORY}" ]; then if [ "$(ls -A ${DATA_DIRECTORY})" ]; then - echo "Performing etcd2 -> etcd3 migration" - ETCDCTL_API=3 ${ETCDCTL} migrate --data-dir=${DATA_DIRECTORY} - echo "Attaching leases to TTL entries" - # Now attach lease to all keys. - # To do it, we temporarily start etcd on a random port (so that - # apiserver actually cannot access it). - start_etcd - # Create a lease and attach all keys to it. - ${ATTACHLEASE} \ - --etcd-address http://127.0.0.1:${ETCD_PORT} \ - --ttl-keys-prefix "${TTL_KEYS_DIRECTORY:-/registry/events}" \ - --lease-duration 1h - # Kill etcd and wait until this is down. - stop_etcd + echo "Performing etcd3 -> etcd2 rollback" + ${ROLLBACK} --data-dir "${DATA_DIRECTORY}" + if [ "$?" -ne "0" ]; then + echo "Rollback to etcd2 failed" + exit 1 + fi fi fi + CURRENT_STORAGE="etcd2" + CURRENT_VERSION="2.3.7" + echo "${CURRENT_VERSION}/${CURRENT_STORAGE}" > "${DATA_DIRECTORY}/${VERSION_FILE}" fi - -if [ "${CURRENT_STORAGE}" = "etcd3" -a "${TARGET_STORAGE}" = "etcd2" ]; then - echo "Performing etcd3 -> etcd2 migration" - # TODO: Implement rollback once this will be supported. - echo "etcd3 -> etcd2 downgrade is NOT supported." - # FIXME: On rollback, we will not support TTLs - we will simply clear - # all events. -fi - -# Write current storage version to avoid future migrations. -# If directory doesn't exist, we need to create it first. -mkdir -p "${DATA_DIRECTORY}" -echo "${TARGET_STORAGE}" > "${DATA_DIRECTORY}/${VERSION_FILE}" diff --git a/hack/test-update-storage-objects.sh b/hack/test-update-storage-objects.sh index bcb98f271d74c..97edb7838be96 100755 --- a/hack/test-update-storage-objects.sh +++ b/hack/test-update-storage-objects.sh @@ -103,6 +103,7 @@ make -C "${KUBE_ROOT}" WHAT=cmd/kube-apiserver make -C "${KUBE_ROOT}" WHAT=cluster/images/etcd/attachlease kube::etcd::start +echo "${ETCD_VERSION}/${STORAGE_BACKEND_ETCD2}" > "${ETCD_DIR}/version.txt" ### BEGIN TEST DEFINITION CUSTOMIZATION ### @@ -159,6 +160,7 @@ killApiServer kube::etcd::stop TARGET_STORAGE="etcd3" \ + TARGET_VERSION="3.0.10" \ DATA_DIRECTORY="${ETCD_DIR}" \ ETCD=$(which etcd) \ ETCDCTL=$(which etcdctl) \ From 5cfb67f822e5d040d63b0a046fde6f5f38088bdf Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Mon, 31 Oct 2016 08:40:13 +0100 Subject: [PATCH 04/17] Increase etcd3 compaction frequency --- pkg/storage/etcd3/compact.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/storage/etcd3/compact.go b/pkg/storage/etcd3/compact.go index 39b21c1c6e760..b9f626d3ba47c 100644 --- a/pkg/storage/etcd3/compact.go +++ b/pkg/storage/etcd3/compact.go @@ -27,7 +27,7 @@ import ( ) const ( - compactInterval = 10 * time.Minute + compactInterval = 5 * time.Minute compactRevKey = "compact_rev_key" ) From 5bf9e049f86328db195255d08b8a685da3267855 Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Wed, 12 Oct 2016 14:11:23 +0200 Subject: [PATCH 05/17] Set target version env in etcd manifest --- cluster/saltbase/salt/etcd/etcd.manifest | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cluster/saltbase/salt/etcd/etcd.manifest b/cluster/saltbase/salt/etcd/etcd.manifest index 9368b05f26d5d..8fc7f7a64d603 100644 --- a/cluster/saltbase/salt/etcd/etcd.manifest +++ b/cluster/saltbase/salt/etcd/etcd.manifest @@ -43,6 +43,9 @@ { "name": "TARGET_STORAGE", "value": "{{ storage_backend }}" }, + { "name": "TARGET_VERSION", + "value": "{{ pillar.get('etcd_docker_tag', '2.2.1') }}" + }, { "name": "DATA_DIRECTORY", "value": "/var/etcd/data{{ suffix }}" } From fcbc813b6feeb5c47f7defecaeb4dc93a9109f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20K=C3=A4ldstr=C3=B6m?= Date: Fri, 9 Sep 2016 20:25:15 +0300 Subject: [PATCH 06/17] Make it possible to compile both etcd2 and etcd3 in the Makefile and compile attachlease for multiple arches as well --- cluster/images/etcd/Makefile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cluster/images/etcd/Makefile b/cluster/images/etcd/Makefile index 7f55fb594242f..4d79e4c19b3d7 100644 --- a/cluster/images/etcd/Makefile +++ b/cluster/images/etcd/Makefile @@ -15,7 +15,7 @@ # Build the etcd image # # Usage: -# [TAG=2.2.1] [REGISTRY=gcr.io/google_containers] [ARCH=amd64] [BASEIMAGE=busybox] make (build|push) +# [TAG=3.0.4] [REGISTRY=gcr.io/google_containers] [ARCH=amd64] [BASEIMAGE=busybox] make (build|push) TAG?=3.0.4 ARCH?=amd64 @@ -42,8 +42,9 @@ build: # without copying the subdirectories. find ./ -maxdepth 1 -type f | xargs cp -t $(TEMP_DIR) - make -C ../../../ WHAT=cluster/images/etcd/attachlease KUBE_STATIC_OVERRIDES="etcd"; - cp "../../../_output/bin/attachlease" $(TEMP_DIR) + # Compile attachlease + docker run -it -v $(shell pwd)/../../../:/go/src/k8s.io/kubernetes -v $(TEMP_DIR):/build -e GOARCH=$(ARCH) golang:$(GOLANG_VERSION) \ + /bin/bash -c "CGO_ENABLED=0 go build -o /build/attachlease k8s.io/kubernetes/cluster/images/etcd/attachlease" ifeq ($(ARCH),amd64) @@ -57,7 +58,7 @@ else && cd /go/src/github.com/coreos/etcd \ && git checkout v$(TAG) \ && GOARM=$(GOARM) GOARCH=$(ARCH) ./build \ - && cp bin/$(ARCH)/* /etcdbin" + && cp -f bin/$(ARCH)/etcd* bin/etcd* /etcdbin; echo 'done'" # Add this ENV variable in order to workaround an unsupported arch blocker # The multiarch feature is in an limited and experimental state right now, and etcd should work fine on arm64 From 5cc3af71520495fad4c6aebc52b387c9f80bc5d3 Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Tue, 27 Sep 2016 15:26:13 +0200 Subject: [PATCH 07/17] Allow building experimenta etcd images --- cluster/images/etcd/Makefile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cluster/images/etcd/Makefile b/cluster/images/etcd/Makefile index 4d79e4c19b3d7..241d7c1b4a2af 100644 --- a/cluster/images/etcd/Makefile +++ b/cluster/images/etcd/Makefile @@ -18,6 +18,7 @@ # [TAG=3.0.4] [REGISTRY=gcr.io/google_containers] [ARCH=amd64] [BASEIMAGE=busybox] make (build|push) TAG?=3.0.4 +REGISTRY_TAG?=$(TAG) ARCH?=amd64 REGISTRY?=gcr.io/google_containers GOLANG_VERSION?=1.6.3 @@ -71,15 +72,15 @@ endif cd $(TEMP_DIR) && sed -i.bak 's|BASEIMAGE|$(BASEIMAGE)|g' Dockerfile # And build the image - docker build -t $(REGISTRY)/etcd-$(ARCH):$(TAG) $(TEMP_DIR) + docker build -t $(REGISTRY)/etcd-$(ARCH):$(REGISTRY_TAG) $(TEMP_DIR) push: build - gcloud docker -- push $(REGISTRY)/etcd-$(ARCH):$(TAG) + gcloud docker -- push $(REGISTRY)/etcd-$(ARCH):$(REGISTRY_TAG) ifeq ($(ARCH),amd64) # Backward compatibility. TODO: deprecate this image tag - docker tag $(REGISTRY)/etcd-$(ARCH):$(TAG) $(REGISTRY)/etcd:$(TAG) - gcloud docker -- push $(REGISTRY)/etcd:$(TAG) + docker tag $(REGISTRY)/etcd-$(ARCH):$(REGISTRY_TAG) $(REGISTRY)/etcd:$(REGISTRY_TAG) + gcloud docker -- push $(REGISTRY)/etcd:$(REGISTRY_TAG) endif all: build From 0e2bdaded9e1c25e4a981333dab8aa7c438dbcf8 Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Tue, 4 Oct 2016 11:13:23 +0200 Subject: [PATCH 08/17] Grab different etcd versions in etcd image. --- cluster/images/etcd/Dockerfile | 3 ++- cluster/images/etcd/Makefile | 43 ++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/cluster/images/etcd/Dockerfile b/cluster/images/etcd/Dockerfile index a72c303edfaf4..94d2abeffa9ac 100644 --- a/cluster/images/etcd/Dockerfile +++ b/cluster/images/etcd/Dockerfile @@ -16,4 +16,5 @@ FROM BASEIMAGE MAINTAINER Dawn Chen EXPOSE 2379 2380 4001 7001 -COPY etcd etcdctl migrate-if-needed.sh attachlease /usr/local/bin/ +COPY etcd* etcdctl* /usr/local/bin/ +COPY migrate-if-needed.sh attachlease /usr/local/bin/ diff --git a/cluster/images/etcd/Makefile b/cluster/images/etcd/Makefile index 241d7c1b4a2af..2c8954330fb3e 100644 --- a/cluster/images/etcd/Makefile +++ b/cluster/images/etcd/Makefile @@ -15,10 +15,19 @@ # Build the etcd image # # Usage: -# [TAG=3.0.4] [REGISTRY=gcr.io/google_containers] [ARCH=amd64] [BASEIMAGE=busybox] make (build|push) +# [TAGS=2.2.1 2.3.7 3.0.10] [REGISTRY=gcr.io/google_containers] [ARCH=amd64] [BASEIMAGE=busybox] make (build|push) -TAG?=3.0.4 -REGISTRY_TAG?=$(TAG) +# The image contains different etcd versions to simplify +# upgrades. Thus be careful when removing any tag from here. +# +# NOTE: The etcd upgrade rules are that you can upgrade only 1 minor +# version at a time, and patch release don't matter. +# +# Except from etcd-$(tag) and etcdctl-$(tag) binaries, we also +# need etcd and etcdctl binaries for backward compatibility reasons. +# That binary will be set to the last tag from $(TAGS). +TAGS?=2.2.1 2.3.7 3.0.10 +REGISTRY_TAG?=3.0.10 ARCH?=amd64 REGISTRY?=gcr.io/google_containers GOLANG_VERSION?=1.6.3 @@ -50,16 +59,30 @@ build: ifeq ($(ARCH),amd64) # Do not compile if we should make an image for amd64, use the official etcd binaries instead - curl -sSL --retry 5 https://github.com/coreos/etcd/releases/download/v$(TAG)/etcd-v$(TAG)-linux-amd64.tar.gz | tar -xz -C $(TEMP_DIR) --strip-components=1 + # For each release create a tmp dir 'etcd_release_tmp_dir' and unpack the release tar there. + for tag in $(TAGS); do \ + etcd_release_tmp_dir=$(shell mktemp -d); \ + curl -sSL --retry 5 https://github.com/coreos/etcd/releases/download/v$$tag/etcd-v$$tag-linux-amd64.tar.gz | tar -xz -C $$etcd_release_tmp_dir --strip-components=1; \ + cp $$etcd_release_tmp_dir/etcd $$etcd_release_tmp_dir/etcdctl $(TEMP_DIR)/; \ + cp $(TEMP_DIR)/etcd $(TEMP_DIR)/etcd-$$tag; \ + cp $(TEMP_DIR)/etcdctl $(TEMP_DIR)/etcdctl-$$tag; \ + done else # Download etcd in a golang container and cross-compile it statically - docker run -it -v $(TEMP_DIR):/etcdbin golang:$(GOLANG_VERSION) /bin/bash -c \ - "git clone https://github.com/coreos/etcd /go/src/github.com/coreos/etcd \ - && cd /go/src/github.com/coreos/etcd \ - && git checkout v$(TAG) \ - && GOARM=$(GOARM) GOARCH=$(ARCH) ./build \ - && cp -f bin/$(ARCH)/etcd* bin/etcd* /etcdbin; echo 'done'" + # For each release create a tmp dir 'etcd_release_tmp_dir' and unpack the release tar there. + for tag in $(TAGS); do \ + etcd_release_tmp_dir=$(shell mktemp -d); \ + docker run -it -v $$etcd_release_tmp_dir:/etcdbin golang:$(GOLANG_VERSION) /bin/bash -c \ + "git clone https://github.com/coreos/etcd /go/src/github.com/coreos/etcd \ + && cd /go/src/github.com/coreos/etcd \ + && git checkout v$$tag \ + && GOARM=$(GOARM) GOARCH=$(ARCH) ./build \ + && cp -f bin/$(ARCH)/etcd* bin/etcd* /etcdbin; echo 'done'"; \ + cp $$etcd_release_tmp_dir/etcd $$etcd_release_tmp_dir/etcdctl $(TEMP_DIR)/; \ + cp $(TEMP_DIR)/etcd $(TEMP_DIR)/etcd-$$tag; \ + cp $(TEMP_DIR)/etcdctl $(TEMP_DIR)/etcdctl-$$tag; \ + done # Add this ENV variable in order to workaround an unsupported arch blocker # The multiarch feature is in an limited and experimental state right now, and etcd should work fine on arm64 From 5d927cc34ab21206ef507a9327f9429de8996dba Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Mon, 10 Oct 2016 10:26:17 +0200 Subject: [PATCH 09/17] Minor fixed to migrate-if-needed script --- cluster/images/etcd/Makefile | 6 +- cluster/images/etcd/migrate-if-needed.sh | 76 +++++++++++++----------- 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/cluster/images/etcd/Makefile b/cluster/images/etcd/Makefile index 2c8954330fb3e..9f1da0747df6a 100644 --- a/cluster/images/etcd/Makefile +++ b/cluster/images/etcd/Makefile @@ -15,7 +15,7 @@ # Build the etcd image # # Usage: -# [TAGS=2.2.1 2.3.7 3.0.10] [REGISTRY=gcr.io/google_containers] [ARCH=amd64] [BASEIMAGE=busybox] make (build|push) +# [TAGS=2.2.1 2.3.7 3.0.12] [REGISTRY=gcr.io/google_containers] [ARCH=amd64] [BASEIMAGE=busybox] make (build|push) # The image contains different etcd versions to simplify # upgrades. Thus be careful when removing any tag from here. @@ -26,8 +26,8 @@ # Except from etcd-$(tag) and etcdctl-$(tag) binaries, we also # need etcd and etcdctl binaries for backward compatibility reasons. # That binary will be set to the last tag from $(TAGS). -TAGS?=2.2.1 2.3.7 3.0.10 -REGISTRY_TAG?=3.0.10 +TAGS?=2.2.1 2.3.7 3.0.12 +REGISTRY_TAG?=3.0.12 ARCH?=amd64 REGISTRY?=gcr.io/google_containers GOLANG_VERSION?=1.6.3 diff --git a/cluster/images/etcd/migrate-if-needed.sh b/cluster/images/etcd/migrate-if-needed.sh index 42508a3588d92..3f86cf9adf516 100755 --- a/cluster/images/etcd/migrate-if-needed.sh +++ b/cluster/images/etcd/migrate-if-needed.sh @@ -18,7 +18,7 @@ # This script performs etcd upgrade based on the following environmental # variables: # TARGET_STORAGE - API of etcd to be used (supported: 'etcd2', 'etcd3') -# TARGET_VERSION - etcd release to be used (supported: '2.2.1', '2.3.7', '3.0.10') +# TARGET_VERSION - etcd release to be used (supported: '2.2.1', '2.3.7', '3.0.12') # DATA_DIRECTORY - directory with etcd data # # The current etcd version and storage format is detected based on the @@ -27,8 +27,8 @@ # # The update workflow support the following upgrade steps: # - 2.2.1/etcd2 -> 2.3.7/etcd2 -# - 2.3.7/etcd2 -> 3.0.10/etcd2 -# - 3.0.10/etcd2 -> 3.0.10/etcd3 +# - 2.3.7/etcd2 -> 3.0.12/etcd2 +# - 3.0.12/etcd2 -> 3.0.12/etcd3 # # NOTE: The releases supported in this script has to match release binaries # present in the etcd image (to make this script work correctly). @@ -59,7 +59,7 @@ fi # NOTE: SUPPORTED_VERSION has to match release binaries present in the # etcd image (to make this script work correctly). -SUPPORTED_VERSIONS=("2.2.1" "2.3.7" "3.0.10") +SUPPORTED_VERSIONS=("2.2.1" "2.3.7" "3.0.12") VERSION_FILE="version.txt" CURRENT_STORAGE="etcd2" @@ -73,6 +73,18 @@ if [ -e "${DATA_DIRECTORY}/${VERSION_FILE}" ]; then CURRENT_STORAGE="$(echo $VERSION_CONTENTS | cut -d '/' -f 2)" fi +# If there is no data in DATA_DIRECTORY, this means that we are +# starting etcd from scratch. In that case, we don't need to do +# any migration. +if [ ! -d "${DATA_DIRECTORY}" ]; then + mkdir -p "${DATA_DIRECTORY}" +fi +if [ ! "$(ls -A ${DATA_DIRECTORY})" ]; then + echo "${DATA_DIRECTORY} is empty - skipping migration" + echo "${TARGET_VERSION}/${TARGET_STORAGE}" > "${DATA_DIRECTORY}/${VERSION_FILE}" + exit 0 +fi + # Starts 'etcd' version ${START_VERSION} and writes to it: # 'etcd_version' -> "${START_VERSION}" # Successful write confirms that etcd is up and running. @@ -138,30 +150,26 @@ for step in "${SUPPORTED_VERSIONS[@]}"; do if [ "${CURRENT_VERSION:0:2}" == "3." -a "${CURRENT_STORAGE}" == "etcd2" -a "${TARGET_STORAGE}" == "etcd3" ]; then # If it is the first 3.x release in the list and we are migrating # also from 'etcd2' to 'etcd3', do the migration now. - if [ -d "${DATA_DIRECTORY}" ]; then - if [ "$(ls -A ${DATA_DIRECTORY})" ]; then - echo "Performing etcd2 -> etcd3 migration" - START_VERSION="${step}" - START_STORAGE="etcd3" - ETCDCTL_CMD="${ETCDCTL:-/usr/local/bin/etcdctl-${START_VERSION}}" - ETCDCTL_API=3 ${ETCDCTL_CMD} migrate --data-dir=${DATA_DIRECTORY} - echo "Attaching leases to TTL entries" - # Now attach lease to all keys. - # To do it, we temporarily start etcd on a random port (so that - # apiserver actually cannot access it). - if ! start_etcd; then - echo "Starting etcd ${step} in v3 mode failed" - exit 1 - fi - # Create a lease and attach all keys to it. - ${ATTACHLEASE} \ - --etcd-address http://127.0.0.1:${ETCD_PORT} \ - --ttl-keys-prefix "${TTL_KEYS_DIRECTORY:-/registry/events}" \ - --lease-duration 1h - # Kill etcd and wait until this is down. - stop_etcd - fi + echo "Performing etcd2 -> etcd3 migration" + START_VERSION="${step}" + START_STORAGE="etcd3" + ETCDCTL_CMD="${ETCDCTL:-/usr/local/bin/etcdctl-${START_VERSION}}" + ETCDCTL_API=3 ${ETCDCTL_CMD} migrate --data-dir=${DATA_DIRECTORY} + echo "Attaching leases to TTL entries" + # Now attach lease to all keys. + # To do it, we temporarily start etcd on a random port (so that + # apiserver actually cannot access it). + if ! start_etcd; then + echo "Starting etcd ${step} in v3 mode failed" + exit 1 fi + # Create a lease and attach all keys to it. + ${ATTACHLEASE} \ + --etcd-address http://127.0.0.1:${ETCD_PORT} \ + --ttl-keys-prefix "${TTL_KEYS_DIRECTORY:-/registry/events}" \ + --lease-duration 1h + # Kill etcd and wait until this is down. + stop_etcd CURRENT_STORAGE="etcd3" echo "${CURRENT_VERSION}/${CURRENT_STORAGE}" > "${DATA_DIRECTORY}/${VERSION_FILE}" fi @@ -178,15 +186,11 @@ if [ "${CURRENT_STORAGE}" == "etcd3" -a "${TARGET_STORAGE}" == "etcd2" ]; then echo "etcd3 -> etcd2 downgrade is supported only between 3.0.x and 2.3.7" return 0 fi - if [ -d "${DATA_DIRECTORY}" ]; then - if [ "$(ls -A ${DATA_DIRECTORY})" ]; then - echo "Performing etcd3 -> etcd2 rollback" - ${ROLLBACK} --data-dir "${DATA_DIRECTORY}" - if [ "$?" -ne "0" ]; then - echo "Rollback to etcd2 failed" - exit 1 - fi - fi + echo "Performing etcd3 -> etcd2 rollback" + ${ROLLBACK} --data-dir "${DATA_DIRECTORY}" + if [ "$?" -ne "0" ]; then + echo "Rollback to etcd2 failed" + exit 1 fi CURRENT_STORAGE="etcd2" CURRENT_VERSION="2.3.7" From 9ed22d942be902fd4be4e13badb16e334646878f Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Mon, 10 Oct 2016 13:20:50 +0200 Subject: [PATCH 10/17] Add rollback tool to etcd image --- cluster/images/etcd/Dockerfile | 4 ++-- cluster/images/etcd/Makefile | 4 ++++ cluster/images/etcd/migrate-if-needed.sh | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cluster/images/etcd/Dockerfile b/cluster/images/etcd/Dockerfile index 94d2abeffa9ac..8e14e77636216 100644 --- a/cluster/images/etcd/Dockerfile +++ b/cluster/images/etcd/Dockerfile @@ -13,8 +13,8 @@ # limitations under the License. FROM BASEIMAGE -MAINTAINER Dawn Chen +MAINTAINER Wojciech Tyczynski EXPOSE 2379 2380 4001 7001 COPY etcd* etcdctl* /usr/local/bin/ -COPY migrate-if-needed.sh attachlease /usr/local/bin/ +COPY migrate-if-needed.sh attachlease rollback /usr/local/bin/ diff --git a/cluster/images/etcd/Makefile b/cluster/images/etcd/Makefile index 9f1da0747df6a..3c2fd2805b2d5 100644 --- a/cluster/images/etcd/Makefile +++ b/cluster/images/etcd/Makefile @@ -55,6 +55,10 @@ build: # Compile attachlease docker run -it -v $(shell pwd)/../../../:/go/src/k8s.io/kubernetes -v $(TEMP_DIR):/build -e GOARCH=$(ARCH) golang:$(GOLANG_VERSION) \ /bin/bash -c "CGO_ENABLED=0 go build -o /build/attachlease k8s.io/kubernetes/cluster/images/etcd/attachlease" + # Compile rollback + docker run -it -v $(shell pwd)/../../../:/go/src/k8s.io/kubernetes -v $(TEMP_DIR):/build -e GOARCH=$(ARCH) golang:$(GOLANG_VERSION) \ + /bin/bash -c "CGO_ENABLED=0 go build -o /build/rollback k8s.io/kubernetes/cluster/images/etcd/rollback" + ifeq ($(ARCH),amd64) diff --git a/cluster/images/etcd/migrate-if-needed.sh b/cluster/images/etcd/migrate-if-needed.sh index 3f86cf9adf516..f42011425af45 100755 --- a/cluster/images/etcd/migrate-if-needed.sh +++ b/cluster/images/etcd/migrate-if-needed.sh @@ -79,7 +79,7 @@ fi if [ ! -d "${DATA_DIRECTORY}" ]; then mkdir -p "${DATA_DIRECTORY}" fi -if [ ! "$(ls -A ${DATA_DIRECTORY})" ]; then +if [ -z "$(ls -A ${DATA_DIRECTORY})" ]; then echo "${DATA_DIRECTORY} is empty - skipping migration" echo "${TARGET_VERSION}/${TARGET_STORAGE}" > "${DATA_DIRECTORY}/${VERSION_FILE}" exit 0 From 55f2d2f1cc3e713fe0c2501dea3a91c616e4c54b Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Tue, 25 Oct 2016 10:01:49 +0200 Subject: [PATCH 11/17] Fix migration script --- cluster/images/etcd/migrate-if-needed.sh | 34 ++++++++++++++++-------- hack/test-update-storage-objects.sh | 2 +- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/cluster/images/etcd/migrate-if-needed.sh b/cluster/images/etcd/migrate-if-needed.sh index f42011425af45..14d6ab96a8d77 100755 --- a/cluster/images/etcd/migrate-if-needed.sh +++ b/cluster/images/etcd/migrate-if-needed.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Copyright 2016 The Kubernetes Authors. # @@ -59,7 +59,9 @@ fi # NOTE: SUPPORTED_VERSION has to match release binaries present in the # etcd image (to make this script work correctly). -SUPPORTED_VERSIONS=("2.2.1" "2.3.7" "3.0.12") +# We cannot use array since sh doesn't support it. +SUPPORTED_VERSIONS_STRING="2.2.1 2.3.7 3.0.12" +SUPPORTED_VERSIONS=$(echo "${SUPPORTED_VERSIONS_STRING}" | tr " " "\n") VERSION_FILE="version.txt" CURRENT_STORAGE="etcd2" @@ -82,7 +84,7 @@ fi if [ -z "$(ls -A ${DATA_DIRECTORY})" ]; then echo "${DATA_DIRECTORY} is empty - skipping migration" echo "${TARGET_VERSION}/${TARGET_STORAGE}" > "${DATA_DIRECTORY}/${VERSION_FILE}" - exit 0 + exit 0 fi # Starts 'etcd' version ${START_VERSION} and writes to it: @@ -96,7 +98,8 @@ start_etcd() { ETCD_PEER_PORT=18630 local ETCD_CMD="${ETCD:-/usr/local/bin/etcd-${START_VERSION}}" local ETCDCTL_CMD="${ETCDCTL:-/usr/local/bin/etcdctl-${START_VERSION}}" - if [ "${START_VERSION:0:2}" == "2." ]; then + local API_VERSION="$(echo ${START_STORAGE} | cut -c5-5)" + if [ "${API_VERSION}" = "2" ]; then ETCDCTL_CMD="${ETCDCTL_CMD} --endpoint=http://127.0.0.1:${ETCD_PORT} set" else ETCDCTL_CMD="${ETCDCTL_CMD} --endpoints=http://127.0.0.1:${ETCD_PORT} put" @@ -108,7 +111,6 @@ start_etcd() { --initial-advertise-peer-urls http://127.0.01:${ETCD_PEER_PORT} \ 1>>/dev/null 2>&1 & ETCD_PID=$! - local API_VERSION="${START_STORAGE:4:4}" # Wait until we can write to etcd. for i in $(seq 240); do ETCDCTL_API="${API_VERSION}" ${ETCDCTL_CMD} 'etcd_version' ${START_VERSION} @@ -132,8 +134,18 @@ ATTACHLEASE="${ATTACHLEASE:-/usr/local/bin/attachlease}" ROLLBACK="${ROLLBACK:-/usr/local/bin/rollback}" # Do the roll-forward migration if needed. -for step in "${SUPPORTED_VERSIONS[@]}"; do - if [ "${step}" == "${CURRENT_VERSION}" -a "${CURRENT_VERSION}" != "${TARGET_VERSION}" ]; then +# The migration goes as following: +# 1. for all versions starting one after the current version of etcd +# we do "start, wait until healthy and stop etcd". This is the +# procedure that etcd documentation suggests for upgrading binaries. +# 2. For the first 3.0.x version that we encounter, if we are still in +# v2 API, we do upgrade to v3 API using the "etcdct migrate" and +# attachlease commands. +SKIP_STEP=true +for step in ${SUPPORTED_VERSIONS}; do + if [ "${step}" = "${CURRENT_VERSION}" ]; then + SKIP_STEP=false + elif [ "${SKIP_STEP}" != "true" ]; then # Do the migration step, by just starting etcd in this version. START_VERSION="${step}" START_STORAGE="${CURRENT_STORAGE}" @@ -147,7 +159,7 @@ for step in "${SUPPORTED_VERSIONS[@]}"; do fi CURRENT_VERSION=${step} echo "${CURRENT_VERSION}/${CURRENT_STORAGE}" > "${DATA_DIRECTORY}/${VERSION_FILE}" - if [ "${CURRENT_VERSION:0:2}" == "3." -a "${CURRENT_STORAGE}" == "etcd2" -a "${TARGET_STORAGE}" == "etcd3" ]; then + if [ "$(echo ${CURRENT_VERSION} | cut -c1-2)" = "3." -a "${CURRENT_STORAGE}" = "etcd2" -a "${TARGET_STORAGE}" = "etcd3" ]; then # If it is the first 3.x release in the list and we are migrating # also from 'etcd2' to 'etcd3', do the migration now. echo "Performing etcd2 -> etcd3 migration" @@ -173,7 +185,7 @@ for step in "${SUPPORTED_VERSIONS[@]}"; do CURRENT_STORAGE="etcd3" echo "${CURRENT_VERSION}/${CURRENT_STORAGE}" > "${DATA_DIRECTORY}/${VERSION_FILE}" fi - if [ "${CURRENT_VERSION}" == "${TARGET_VERSION}" -a "${CURRENT_STORAGE}" == "${TARGET_STORAGE}" ]; then + if [ "${CURRENT_VERSION}" = "${TARGET_VERSION}" -a "${CURRENT_STORAGE}" = "${TARGET_STORAGE}" ]; then break fi done @@ -181,8 +193,8 @@ done # Do the rollback of needed. # NOTE: Rollback is only supported from "3.0.x" version in 'etcd3' mode to # "2.3.7" version in 'etcd2' mode. -if [ "${CURRENT_STORAGE}" == "etcd3" -a "${TARGET_STORAGE}" == "etcd2" ]; then - if [ "${CURRENT_VERSION:0:4}" != "3.0." -o "${TARGET_VERSION}" != "2.3.7" ]; then +if [ "${CURRENT_STORAGE}" = "etcd3" -a "${TARGET_STORAGE}" = "etcd2" ]; then + if [ "$(echo ${CURRENT_VERSION} | cut -c1-4)" != "3.0." -o "${TARGET_VERSION}" != "2.3.7" ]; then echo "etcd3 -> etcd2 downgrade is supported only between 3.0.x and 2.3.7" return 0 fi diff --git a/hack/test-update-storage-objects.sh b/hack/test-update-storage-objects.sh index 97edb7838be96..e2c6bcb8bc0ad 100755 --- a/hack/test-update-storage-objects.sh +++ b/hack/test-update-storage-objects.sh @@ -160,7 +160,7 @@ killApiServer kube::etcd::stop TARGET_STORAGE="etcd3" \ - TARGET_VERSION="3.0.10" \ + TARGET_VERSION="3.0.12" \ DATA_DIRECTORY="${ETCD_DIR}" \ ETCD=$(which etcd) \ ETCDCTL=$(which etcdctl) \ From 6fd883f7de87b38a386843410755bf4f6f4026c3 Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Thu, 27 Oct 2016 16:45:04 +0200 Subject: [PATCH 12/17] Correctly support custom etcd migration --- cluster/images/etcd/migrate-if-needed.sh | 10 ++++++++-- cluster/saltbase/salt/etcd/etcd.manifest | 2 +- hack/test-update-storage-objects.sh | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cluster/images/etcd/migrate-if-needed.sh b/cluster/images/etcd/migrate-if-needed.sh index 14d6ab96a8d77..bc241dcbb8694 100755 --- a/cluster/images/etcd/migrate-if-needed.sh +++ b/cluster/images/etcd/migrate-if-needed.sh @@ -57,6 +57,12 @@ if [ "${TARGET_STORAGE}" != "etcd2" -a "${TARGET_STORAGE}" != "etcd3" ]; then exit 1 fi +# Correctly support upgrade and rollback to non-default version. +if [ "${DO_NOT_MOVE_BINARIES:-}" != "true" ]; then + cp "/usr/local/bin/etcd-${TARGET_VERSION}" "/usr/local/bin/etcd" + cp "/usr/local/bin/etcdctl-${TARGET_VERSION}" "/usr/local/bin/etcdctl" +fi + # NOTE: SUPPORTED_VERSION has to match release binaries present in the # etcd image (to make this script work correctly). # We cannot use array since sh doesn't support it. @@ -156,9 +162,9 @@ for step in ${SUPPORTED_VERSIONS}; do fi # Kill etcd and wait until this is down. stop_etcd + CURRENT_VERSION=${step} + echo "${CURRENT_VERSION}/${CURRENT_STORAGE}" > "${DATA_DIRECTORY}/${VERSION_FILE}" fi - CURRENT_VERSION=${step} - echo "${CURRENT_VERSION}/${CURRENT_STORAGE}" > "${DATA_DIRECTORY}/${VERSION_FILE}" if [ "$(echo ${CURRENT_VERSION} | cut -c1-2)" = "3." -a "${CURRENT_STORAGE}" = "etcd2" -a "${TARGET_STORAGE}" = "etcd3" ]; then # If it is the first 3.x release in the list and we are migrating # also from 'etcd2' to 'etcd3', do the migration now. diff --git a/cluster/saltbase/salt/etcd/etcd.manifest b/cluster/saltbase/salt/etcd/etcd.manifest index 8fc7f7a64d603..d41f4f73cf1de 100644 --- a/cluster/saltbase/salt/etcd/etcd.manifest +++ b/cluster/saltbase/salt/etcd/etcd.manifest @@ -37,7 +37,7 @@ "command": [ "/bin/sh", "-c", - "if [ -e /usr/local/bin/migrate-if-needed.sh ]; then /usr/local/bin/migrate-if-needed.sh; fi; /usr/local/bin/etcd --name etcd-{{ hostname }} --listen-peer-urls http://127.0.0.1:{{ server_port }} --advertise-client-urls http://127.0.0.1:{{ port }} --listen-client-urls http://127.0.0.1:{{ port }} --data-dir /var/etcd/data{{ suffix }} 1>>/var/log/etcd{{ suffix }}.log 2>&1" + "if [ -e /usr/local/bin/migrate-if-needed.sh ]; then /usr/local/bin/migrate-if-needed.sh 1>>/var/log/etcd{{ suffix }}.log 2>&1; fi; /usr/local/bin/etcd --name etcd-{{ hostname }} --listen-peer-urls http://127.0.0.1:{{ server_port }} --advertise-client-urls http://127.0.0.1:{{ port }} --listen-client-urls http://127.0.0.1:{{ port }} --data-dir /var/etcd/data{{ suffix }} 1>>/var/log/etcd{{ suffix }}.log 2>&1" ], "env": [ { "name": "TARGET_STORAGE", diff --git a/hack/test-update-storage-objects.sh b/hack/test-update-storage-objects.sh index e2c6bcb8bc0ad..090b266d85964 100755 --- a/hack/test-update-storage-objects.sh +++ b/hack/test-update-storage-objects.sh @@ -165,6 +165,7 @@ TARGET_STORAGE="etcd3" \ ETCD=$(which etcd) \ ETCDCTL=$(which etcdctl) \ ATTACHLEASE="${KUBE_OUTPUT_HOSTBIN}/attachlease" \ + DO_NOT_MOVE_BINARIES="true" \ ${KUBE_ROOT}/cluster/images/etcd/migrate-if-needed.sh kube::etcd::start From 7ced8ac9958325ee621b04f3b3ba7bd5acfdbfdb Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Mon, 31 Oct 2016 10:40:41 +0100 Subject: [PATCH 13/17] Expose etcd version. --- cluster/common.sh | 13 +++++++++++-- cluster/gce/config-test.sh | 6 ++++-- cluster/gce/configure-vm.sh | 11 ++++++++--- cluster/gce/gci/configure-helper.sh | 9 +++++++-- cluster/gce/trusty/configure-helper.sh | 9 +++++++-- cluster/kubemark/config-default.sh | 7 +++++++ cluster/saltbase/salt/etcd/etcd.manifest | 2 +- 7 files changed, 45 insertions(+), 12 deletions(-) diff --git a/cluster/common.sh b/cluster/common.sh index fd9370949ddd5..f5f3ce747e88a 100755 --- a/cluster/common.sh +++ b/cluster/common.sh @@ -688,9 +688,18 @@ NUM_NODES: $(yaml-quote ${NUM_NODES}) STORAGE_BACKEND: $(yaml-quote ${STORAGE_BACKEND:-}) ENABLE_GARBAGE_COLLECTOR: $(yaml-quote ${ENABLE_GARBAGE_COLLECTOR:-}) EOF - if [ -n "${TEST_ETCD_VERSION:-}" ]; then + # ETCD_IMAGE (if set) allows to use a custom etcd image. + if [ -n "${ETCD_IMAGE:-}" ]; then cat >>$file <>$file <>/srv/salt-overlay/pillar/cluster-params.sls -etcd_docker_tag: '$(echo "$TEST_ETCD_VERSION" | sed -e "s/'/''/g")' +etcd_docker_tag: '$(echo "$ETCD_IMAGE" | sed -e "s/'/''/g")' EOF fi + if [ -n "${ETCD_VERSION:-}" ]; then + cat <>/srv/salt-overlay/pillar/cluster-params.sls +etcd_version: '$(echo "$ETCD_VERSION" | sed -e "s/'/''/g")' +EOF + fi + # Configuration changes for test clusters if [ -n "${APISERVER_TEST_ARGS:-}" ]; then cat <>/srv/salt-overlay/pillar/cluster-params.sls apiserver_test_args: '$(echo "$APISERVER_TEST_ARGS" | sed -e "s/'/''/g")' diff --git a/cluster/gce/gci/configure-helper.sh b/cluster/gce/gci/configure-helper.sh index 12d3ae9e09864..61a652ca53931 100644 --- a/cluster/gce/gci/configure-helper.sh +++ b/cluster/gce/gci/configure-helper.sh @@ -632,11 +632,16 @@ function prepare-etcd-manifest { sed -i -e "s@{{ *etcd_cluster *}}@$etcd_cluster@g" "${temp_file}" sed -i -e "s@{{ *storage_backend *}}@${STORAGE_BACKEND:-}@g" "${temp_file}" sed -i -e "s@{{ *cluster_state *}}@$cluster_state@g" "${temp_file}" - if [[ -n "${TEST_ETCD_VERSION:-}" ]]; then - sed -i -e "s@{{ *pillar\.get('etcd_docker_tag', '\(.*\)') *}}@${TEST_ETCD_VERSION}@g" "${temp_file}" + if [[ -n "${ETCD_IMAGE:-}" ]]; then + sed -i -e "s@{{ *pillar\.get('etcd_docker_tag', '\(.*\)') *}}@${ETCD_IMAGE}@g" "${temp_file}" else sed -i -e "s@{{ *pillar\.get('etcd_docker_tag', '\(.*\)') *}}@\1@g" "${temp_file}" fi + if [[ -n "${ETCD_VERSION:-}" ]]; then + sed -i -e "s@{{ *pillar\.get('etcd_version', '\(.*\)') *}}@${ETCD_VERSION}@g" "${temp_file}" + else + sed -i -e "s@{{ *pillar\.get('etcd_version', '\(.*\)') *}}@\1@g" "${temp_file}" + fi # Replace the volume host path. sed -i -e "s@/mnt/master-pd/var/etcd@/mnt/disks/master-pd/var/etcd@g" "${temp_file}" mv "${temp_file}" /etc/kubernetes/manifests diff --git a/cluster/gce/trusty/configure-helper.sh b/cluster/gce/trusty/configure-helper.sh index 262289f32b533..c46e195255d9b 100644 --- a/cluster/gce/trusty/configure-helper.sh +++ b/cluster/gce/trusty/configure-helper.sh @@ -461,11 +461,16 @@ prepare_etcd_manifest() { sed -i -e "s@{{ *etcd_cluster *}}@$etcd_cluster@g" "${etcd_temp_file}" sed -i -e "s@{{ *storage_backend *}}@${STORAGE_BACKEND:-}@g" "${temp_file}" sed -i -e "s@{{ *cluster_state *}}@$cluster_state@g" "${etcd_temp_file}" - if [[ -n "${TEST_ETCD_VERSION:-}" ]]; then - sed -i -e "s@{{ *pillar\.get('etcd_docker_tag', '\(.*\)') *}}@${TEST_ETCD_VERSION}@g" "${etcd_temp_file}" + if [[ -n "${ETCD_IMAGE:-}" ]]; then + sed -i -e "s@{{ *pillar\.get('etcd_docker_tag', '\(.*\)') *}}@${ETCD_IMAGE}@g" "${etcd_temp_file}" else sed -i -e "s@{{ *pillar\.get('etcd_docker_tag', '\(.*\)') *}}@\1@g" "${etcd_temp_file}" fi + if [[ -n "${ETCD_VERSION:-}" ]]; then + sed -i -e "s@{{ *pillar\.get('etcd_version', '\(.*\)') *}}@${ETCD_VERSION}@g" "${etcd_temp_file}" + else + sed -i -e "s@{{ *pillar\.get('etcd_version', '\(.*\)') *}}@\1@g" "${etcd_temp_file}" + fi # Replace the volume host path sed -i -e "s@/mnt/master-pd/var/etcd@/mnt/disks/master-pd/var/etcd@g" "${etcd_temp_file}" mv "${etcd_temp_file}" /etc/kubernetes/manifests diff --git a/cluster/kubemark/config-default.sh b/cluster/kubemark/config-default.sh index fa92b50f391b8..02389ffac775e 100644 --- a/cluster/kubemark/config-default.sh +++ b/cluster/kubemark/config-default.sh @@ -45,6 +45,13 @@ CLUSTER_IP_RANGE="${CLUSTER_IP_RANGE:-10.240.0.0/13}" RUNTIME_CONFIG="${KUBE_RUNTIME_CONFIG:-}" TERMINATED_POD_GC_THRESHOLD=${TERMINATED_POD_GC_THRESHOLD:-100} +# Set etcd image (e.g. 3.0.13-experimental.1) version (e.g. 3.0.13) if you need +# non-default version. +ETCD_IMAGE="${TEST_ETCD_IMAGE:-}" +ETCD_VERSION="${TEST_ETCD_VERSION:-}" +# Storage backend. 'etcd2' supported, 'etcd3' experimental. +STORAGE_BACKEND=${STORAGE_BACKEND:-etcd2} + # Default Log level for all components in test clusters and variables to override it in specific components. TEST_CLUSTER_LOG_LEVEL="${TEST_CLUSTER_LOG_LEVEL:---v=2}" KUBELET_TEST_LOG_LEVEL="${KUBELET_TEST_LOG_LEVEL:-$TEST_CLUSTER_LOG_LEVEL}" diff --git a/cluster/saltbase/salt/etcd/etcd.manifest b/cluster/saltbase/salt/etcd/etcd.manifest index d41f4f73cf1de..ae6a57e7655f3 100644 --- a/cluster/saltbase/salt/etcd/etcd.manifest +++ b/cluster/saltbase/salt/etcd/etcd.manifest @@ -44,7 +44,7 @@ "value": "{{ storage_backend }}" }, { "name": "TARGET_VERSION", - "value": "{{ pillar.get('etcd_docker_tag', '2.2.1') }}" + "value": "{{ pillar.get('etcd_version', '2.2.1') }}" }, { "name": "DATA_DIRECTORY", "value": "/var/etcd/data{{ suffix }}" From bf46a914e7d36ff1b631a63b7976e611034a4635 Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Thu, 27 Oct 2016 13:40:05 +0200 Subject: [PATCH 14/17] Update etcd Godeps to 3.0.13 --- Godeps/Godeps.json | 208 +++++++++--------- vendor/github.com/coreos/etcd/auth/store.go | 5 + .../coreos/etcd/etcdserver/server.go | 20 +- vendor/github.com/coreos/etcd/mvcc/kvstore.go | 7 + vendor/github.com/coreos/etcd/raft/node.go | 2 +- .../coreos/etcd/raft/raftpb/raft.pb.go | 2 +- .../coreos/etcd/raft/raftpb/raft.proto | 4 +- .../github.com/coreos/etcd/version/version.go | 2 +- 8 files changed, 128 insertions(+), 122 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 7eea1d88c670c..e36927c8a277d 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -353,263 +353,263 @@ }, { "ImportPath": "github.com/coreos/etcd/alarm", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/auth", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/auth/authpb", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/client", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/clientv3", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/compactor", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/discovery", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/error", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/etcdserver", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/etcdserver/api", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/etcdserver/api/v2http", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/etcdserver/api/v2http/httptypes", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/etcdserver/api/v3rpc", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/etcdserver/auth", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/etcdserver/etcdserverpb", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/etcdserver/membership", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/etcdserver/stats", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/integration", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/lease", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/lease/leasehttp", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/lease/leasepb", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/mvcc", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/mvcc/backend", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/mvcc/mvccpb", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/pkg/adt", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/pkg/contention", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/pkg/crc", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/pkg/fileutil", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/pkg/httputil", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/pkg/idutil", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/pkg/ioutil", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/pkg/logutil", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/pkg/netutil", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/pkg/pathutil", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/pkg/pbutil", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/pkg/runtime", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/pkg/schedule", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/pkg/testutil", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/pkg/tlsutil", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/pkg/transport", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/pkg/types", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/pkg/wait", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/raft", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/raft/raftpb", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/rafthttp", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/snap", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/snap/snappb", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/store", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/version", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/wal", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/etcd/wal/walpb", - "Comment": "v3.0.12", - "Rev": "2d1e2e8e646e65f73ca0d9ee905a5343d6135a50" + "Comment": "v3.0.13", + "Rev": "c99d0d4b255f0dfc117b59555c89933192237c27" }, { "ImportPath": "github.com/coreos/go-oidc/http", diff --git a/vendor/github.com/coreos/etcd/auth/store.go b/vendor/github.com/coreos/etcd/auth/store.go index 01c6c9905c8bc..0c210acb0b373 100644 --- a/vendor/github.com/coreos/etcd/auth/store.go +++ b/vendor/github.com/coreos/etcd/auth/store.go @@ -603,6 +603,11 @@ func (as *authStore) isOpPermitted(userName string, key, rangeEnd []byte, permTy return false } + // root role should have permission on all ranges + if hasRootRole(user) { + return true + } + if as.isRangeOpPermitted(tx, userName, key, rangeEnd, permTyp) { return true } diff --git a/vendor/github.com/coreos/etcd/etcdserver/server.go b/vendor/github.com/coreos/etcd/etcdserver/server.go index dd232d5ef2ae6..d2324e57c2d64 100644 --- a/vendor/github.com/coreos/etcd/etcdserver/server.go +++ b/vendor/github.com/coreos/etcd/etcdserver/server.go @@ -154,13 +154,13 @@ type Server interface { // EtcdServer is the production implementation of the Server interface type EtcdServer struct { - // r and inflightSnapshots must be the first elements to keep 64-bit alignment for atomic - // access to fields - - // count the number of inflight snapshots. - // MUST use atomic operation to access this field. - inflightSnapshots int64 - Cfg *ServerConfig + // inflightSnapshots holds count the number of snapshots currently inflight. + inflightSnapshots int64 // must use atomic operations to access; keep 64-bit aligned. + appliedIndex uint64 // must use atomic operations to access; keep 64-bit aligned. + // consistIndex used to hold the offset of current executing entry + // It is initialized to 0 before executing any entry. + consistIndex consistentIndex // must use atomic operations to access; keep 64-bit aligned. + Cfg *ServerConfig readych chan struct{} r raftNode @@ -195,10 +195,6 @@ type EtcdServer struct { // compactor is used to auto-compact the KV. compactor *compactor.Periodic - // consistent index used to hold the offset of current executing entry - // It is initialized to 0 before executing any entry. - consistIndex consistentIndex - // peerRt used to send requests (version, lease) to peers. peerRt http.RoundTripper reqIDGen *idutil.Generator @@ -212,8 +208,6 @@ type EtcdServer struct { // wg is used to wait for the go routines that depends on the server state // to exit when stopping the server. wg sync.WaitGroup - - appliedIndex uint64 } // NewServer creates a new EtcdServer from the supplied configuration. The diff --git a/vendor/github.com/coreos/etcd/mvcc/kvstore.go b/vendor/github.com/coreos/etcd/mvcc/kvstore.go index adc1fb7661eda..6819c69a16d12 100644 --- a/vendor/github.com/coreos/etcd/mvcc/kvstore.go +++ b/vendor/github.com/coreos/etcd/mvcc/kvstore.go @@ -408,6 +408,13 @@ func (s *store) restore() error { s.currentRev = rev } + // keys in the range [compacted revision -N, compaction] might all be deleted due to compaction. + // the correct revision should be set to compaction revision in the case, not the largest revision + // we have seen. + if s.currentRev.main < s.compactMainRev { + s.currentRev.main = s.compactMainRev + } + for key, lid := range keyToLease { if s.le == nil { panic("no lessor to attach lease") diff --git a/vendor/github.com/coreos/etcd/raft/node.go b/vendor/github.com/coreos/etcd/raft/node.go index 59d61284d890a..22332be6bad66 100644 --- a/vendor/github.com/coreos/etcd/raft/node.go +++ b/vendor/github.com/coreos/etcd/raft/node.go @@ -38,7 +38,7 @@ var ( // SoftState provides state that is useful for logging and debugging. // The state is volatile and does not need to be persisted to the WAL. type SoftState struct { - Lead uint64 + Lead uint64 // must use atomic operations to access; keep 64-bit aligned. RaftState StateType } diff --git a/vendor/github.com/coreos/etcd/raft/raftpb/raft.pb.go b/vendor/github.com/coreos/etcd/raft/raftpb/raft.pb.go index 664b5b8289c91..e60fb88df34b4 100644 --- a/vendor/github.com/coreos/etcd/raft/raftpb/raft.pb.go +++ b/vendor/github.com/coreos/etcd/raft/raftpb/raft.pb.go @@ -183,9 +183,9 @@ func (x *ConfChangeType) UnmarshalJSON(data []byte) error { func (ConfChangeType) EnumDescriptor() ([]byte, []int) { return fileDescriptorRaft, []int{2} } type Entry struct { - Type EntryType `protobuf:"varint,1,opt,name=Type,json=type,enum=raftpb.EntryType" json:"Type"` Term uint64 `protobuf:"varint,2,opt,name=Term,json=term" json:"Term"` Index uint64 `protobuf:"varint,3,opt,name=Index,json=index" json:"Index"` + Type EntryType `protobuf:"varint,1,opt,name=Type,json=type,enum=raftpb.EntryType" json:"Type"` Data []byte `protobuf:"bytes,4,opt,name=Data,json=data" json:"Data,omitempty"` XXX_unrecognized []byte `json:"-"` } diff --git a/vendor/github.com/coreos/etcd/raft/raftpb/raft.proto b/vendor/github.com/coreos/etcd/raft/raftpb/raft.proto index 42f10d269f09b..8cd630046ef3e 100644 --- a/vendor/github.com/coreos/etcd/raft/raftpb/raft.proto +++ b/vendor/github.com/coreos/etcd/raft/raftpb/raft.proto @@ -15,9 +15,9 @@ enum EntryType { } message Entry { + optional uint64 Term = 2 [(gogoproto.nullable) = false]; // must be 64-bit aligned for atomic operations + optional uint64 Index = 3 [(gogoproto.nullable) = false]; // must be 64-bit aligned for atomic operations optional EntryType Type = 1 [(gogoproto.nullable) = false]; - optional uint64 Term = 2 [(gogoproto.nullable) = false]; - optional uint64 Index = 3 [(gogoproto.nullable) = false]; optional bytes Data = 4; } diff --git a/vendor/github.com/coreos/etcd/version/version.go b/vendor/github.com/coreos/etcd/version/version.go index 6934905ba051f..fd3dcd5661fd3 100644 --- a/vendor/github.com/coreos/etcd/version/version.go +++ b/vendor/github.com/coreos/etcd/version/version.go @@ -29,7 +29,7 @@ import ( var ( // MinClusterVersion is the min cluster version this etcd binary is compatible with. MinClusterVersion = "2.3.0" - Version = "3.0.12" + Version = "3.0.13" // Git SHA Value will be set during build GitSHA = "Not provided (use ./build instead of go build)" From b4d42cc7da25c3ca9d35f422b00766ee02388031 Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Thu, 27 Oct 2016 13:47:52 +0200 Subject: [PATCH 15/17] Update etcd in tests to 3.0.13 --- build/build-image/cross/Dockerfile | 2 +- cluster/images/etcd/Makefile | 6 +++--- cluster/images/etcd/migrate-if-needed.sh | 8 ++++---- hack/lib/etcd.sh | 2 +- hack/test-update-storage-objects.sh | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build/build-image/cross/Dockerfile b/build/build-image/cross/Dockerfile index 384dff23b0987..4fc8f06d217ab 100644 --- a/build/build-image/cross/Dockerfile +++ b/build/build-image/cross/Dockerfile @@ -72,7 +72,7 @@ RUN mkdir $TMPDIR \ github.com/jteeuwen/go-bindata/go-bindata # Download and symlink etcd. We need this for our integration tests. -RUN export ETCD_VERSION=v3.0.10; \ +RUN export ETCD_VERSION=v3.0.13; \ mkdir -p /usr/local/src/etcd \ && cd /usr/local/src/etcd \ && curl -fsSL https://github.com/coreos/etcd/releases/download/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-amd64.tar.gz | tar -xz \ diff --git a/cluster/images/etcd/Makefile b/cluster/images/etcd/Makefile index 3c2fd2805b2d5..b37270fa8b0fb 100644 --- a/cluster/images/etcd/Makefile +++ b/cluster/images/etcd/Makefile @@ -15,7 +15,7 @@ # Build the etcd image # # Usage: -# [TAGS=2.2.1 2.3.7 3.0.12] [REGISTRY=gcr.io/google_containers] [ARCH=amd64] [BASEIMAGE=busybox] make (build|push) +# [TAGS=2.2.1 2.3.7 3.0.13] [REGISTRY=gcr.io/google_containers] [ARCH=amd64] [BASEIMAGE=busybox] make (build|push) # The image contains different etcd versions to simplify # upgrades. Thus be careful when removing any tag from here. @@ -26,8 +26,8 @@ # Except from etcd-$(tag) and etcdctl-$(tag) binaries, we also # need etcd and etcdctl binaries for backward compatibility reasons. # That binary will be set to the last tag from $(TAGS). -TAGS?=2.2.1 2.3.7 3.0.12 -REGISTRY_TAG?=3.0.12 +TAGS?=2.2.1 2.3.7 3.0.13 +REGISTRY_TAG?=3.0.13 ARCH?=amd64 REGISTRY?=gcr.io/google_containers GOLANG_VERSION?=1.6.3 diff --git a/cluster/images/etcd/migrate-if-needed.sh b/cluster/images/etcd/migrate-if-needed.sh index bc241dcbb8694..84199ee4904ef 100755 --- a/cluster/images/etcd/migrate-if-needed.sh +++ b/cluster/images/etcd/migrate-if-needed.sh @@ -18,7 +18,7 @@ # This script performs etcd upgrade based on the following environmental # variables: # TARGET_STORAGE - API of etcd to be used (supported: 'etcd2', 'etcd3') -# TARGET_VERSION - etcd release to be used (supported: '2.2.1', '2.3.7', '3.0.12') +# TARGET_VERSION - etcd release to be used (supported: '2.2.1', '2.3.7', '3.0.13') # DATA_DIRECTORY - directory with etcd data # # The current etcd version and storage format is detected based on the @@ -27,8 +27,8 @@ # # The update workflow support the following upgrade steps: # - 2.2.1/etcd2 -> 2.3.7/etcd2 -# - 2.3.7/etcd2 -> 3.0.12/etcd2 -# - 3.0.12/etcd2 -> 3.0.12/etcd3 +# - 2.3.7/etcd2 -> 3.0.13/etcd2 +# - 3.0.13/etcd2 -> 3.0.13/etcd3 # # NOTE: The releases supported in this script has to match release binaries # present in the etcd image (to make this script work correctly). @@ -66,7 +66,7 @@ fi # NOTE: SUPPORTED_VERSION has to match release binaries present in the # etcd image (to make this script work correctly). # We cannot use array since sh doesn't support it. -SUPPORTED_VERSIONS_STRING="2.2.1 2.3.7 3.0.12" +SUPPORTED_VERSIONS_STRING="2.2.1 2.3.7 3.0.13" SUPPORTED_VERSIONS=$(echo "${SUPPORTED_VERSIONS_STRING}" | tr " " "\n") VERSION_FILE="version.txt" diff --git a/hack/lib/etcd.sh b/hack/lib/etcd.sh index c99dcebeb8825..684020971cc97 100644 --- a/hack/lib/etcd.sh +++ b/hack/lib/etcd.sh @@ -16,7 +16,7 @@ # A set of helpers for starting/running etcd for tests -ETCD_VERSION=${ETCD_VERSION:-3.0.10} +ETCD_VERSION=${ETCD_VERSION:-3.0.13} ETCD_HOST=${ETCD_HOST:-127.0.0.1} ETCD_PORT=${ETCD_PORT:-2379} diff --git a/hack/test-update-storage-objects.sh b/hack/test-update-storage-objects.sh index 090b266d85964..aa3d9d247f572 100755 --- a/hack/test-update-storage-objects.sh +++ b/hack/test-update-storage-objects.sh @@ -160,7 +160,7 @@ killApiServer kube::etcd::stop TARGET_STORAGE="etcd3" \ - TARGET_VERSION="3.0.12" \ + TARGET_VERSION="3.0.13" \ DATA_DIRECTORY="${ETCD_DIR}" \ ETCD=$(which etcd) \ ETCDCTL=$(which etcdctl) \ From f9fd7aede57896563057cf1a6eecf0dcef7a10f0 Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Wed, 2 Nov 2016 09:32:15 +0100 Subject: [PATCH 16/17] Extend etcd migration logs --- cluster/images/etcd/migrate-if-needed.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cluster/images/etcd/migrate-if-needed.sh b/cluster/images/etcd/migrate-if-needed.sh index 84199ee4904ef..2867e9575296b 100755 --- a/cluster/images/etcd/migrate-if-needed.sh +++ b/cluster/images/etcd/migrate-if-needed.sh @@ -114,17 +114,16 @@ start_etcd() { --listen-client-urls http://127.0.0.1:${ETCD_PORT} \ --advertise-client-urls http://127.0.0.1:${ETCD_PORT} \ --listen-peer-urls http://127.0.0.1:${ETCD_PEER_PORT} \ - --initial-advertise-peer-urls http://127.0.01:${ETCD_PEER_PORT} \ - 1>>/dev/null 2>&1 & + --initial-advertise-peer-urls http://127.0.0.1:${ETCD_PEER_PORT} & ETCD_PID=$! # Wait until we can write to etcd. for i in $(seq 240); do + sleep 0.5 ETCDCTL_API="${API_VERSION}" ${ETCDCTL_CMD} 'etcd_version' ${START_VERSION} if [ "$?" -eq "0" ]; then echo "Etcd on port ${ETCD_PORT} is up." return 0 fi - sleep 0.5 done echo "Timeout while waiting for etcd on port ${ETCD_PORT}" return 1 From 1148b30e0a54d53dde5f5f928d22784d034c539e Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Wed, 2 Nov 2016 20:57:17 +0100 Subject: [PATCH 17/17] Fix collisions between different etcds during migration. --- cluster/images/etcd/migrate-if-needed.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cluster/images/etcd/migrate-if-needed.sh b/cluster/images/etcd/migrate-if-needed.sh index 2867e9575296b..5b262837138b2 100755 --- a/cluster/images/etcd/migrate-if-needed.sh +++ b/cluster/images/etcd/migrate-if-needed.sh @@ -102,6 +102,13 @@ start_etcd() { # Use random ports, so that apiserver cannot connect to etcd. ETCD_PORT=18629 ETCD_PEER_PORT=18630 + # Avoid collisions between etcd and event-etcd. + case "${DATA_DIRECTORY}" in + *event*) + ETCD_PORT=18631 + ETCD_PEER_PORT=18632 + ;; + esac local ETCD_CMD="${ETCD:-/usr/local/bin/etcd-${START_VERSION}}" local ETCDCTL_CMD="${ETCDCTL:-/usr/local/bin/etcdctl-${START_VERSION}}" local API_VERSION="$(echo ${START_STORAGE} | cut -c5-5)"