Skip to content

Commit

Permalink
Support for etcd migration
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtek-t committed Aug 12, 2016
1 parent 4d27f99 commit d27c118
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cluster/gce/config-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ KUBE_APISERVER_REQUEST_TIMEOUT=300
PREEMPTIBLE_NODE=${PREEMPTIBLE_NODE:-false}
PREEMPTIBLE_MASTER=${PREEMPTIBLE_MASTER:-false}

MASTER_OS_DISTRIBUTION=${KUBE_MASTER_OS_DISTRIBUTION:-${KUBE_OS_DISTRIBUTION:-gci}}
MASTER_OS_DISTRIBUTION=${KUBE_MASTER_OS_DISTRIBUTION:-${KUBE_OS_DISTRIBUTION:-debian}}
NODE_OS_DISTRIBUTION=${KUBE_NODE_OS_DISTRIBUTION:-${KUBE_OS_DISTRIBUTION:-debian}}
# By default a cluster will be started with the master on GCI and nodes on
# containervm. If you are updating the containervm version, update this
Expand Down Expand Up @@ -161,7 +161,7 @@ KUBE_UP_AUTOMATIC_CLEANUP=${KUBE_UP_AUTOMATIC_CLEANUP:-false}
TEST_CLUSTER="${TEST_CLUSTER:-true}"

# Storage backend. 'etcd2' supported, 'etcd3' experimental.
STORAGE_BACKEND=${STORAGE_BACKEND:-etcd2}
STORAGE_BACKEND=${STORAGE_BACKEND:-etcd3}

# OpenContrail networking plugin specific settings
NETWORK_PROVIDER="${NETWORK_PROVIDER:-kubenet}" # none, opencontrail, flannel, kubenet
Expand Down
1 change: 1 addition & 0 deletions cluster/gce/gci/configure-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ function prepare-etcd-manifest {
sed -i -e "s@{{ *cpulimit *}}@\"$4\"@g" "${temp_file}"
sed -i -e "s@{{ *hostname *}}@$host_name@g" "${temp_file}"
sed -i -e "s@{{ *etcd_cluster *}}@$etcd_cluster@g" "${temp_file}"
sed -i -e "s@{{ *storage_backend *}}@${STORAGE_BACKEND:-etcd2}@g" "${temp_file}"
sed -i -e "s@{{ *cluster_state *}}@$cluster_state@g" "${temp_file}"
# Replace the volume host path.
sed -i -e "s@/mnt/master-pd/var/etcd@/mnt/disks/master-pd/var/etcd@g" "${temp_file}"
Expand Down
1 change: 1 addition & 0 deletions cluster/gce/trusty/configure-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ prepare_etcd_manifest() {
sed -i -e "s@{{ *cpulimit *}}@\"$4\"@g" "${etcd_temp_file}"
sed -i -e "s@{{ *hostname *}}@$host_name@g" "${etcd_temp_file}"
sed -i -e "s@{{ *etcd_cluster *}}@$etcd_cluster@g" "${etcd_temp_file}"
sed -i -e "s@{{ *storage_backend *}}@${STORAGE_BACKEND:-etcd2}@g" "${temp_file}"
sed -i -e "s@{{ *cluster_state *}}@$cluster_state@g" "${etcd_temp_file}"
# Replace the volume host path
sed -i -e "s@/mnt/master-pd/var/etcd@/mnt/disks/master-pd/var/etcd@g" "${etcd_temp_file}"
Expand Down
2 changes: 1 addition & 1 deletion cluster/images/etcd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ FROM BASEIMAGE
MAINTAINER Dawn Chen <dawnchen@google.com>

EXPOSE 2379 2380 4001 7001
COPY etcd etcdctl /usr/local/bin/
COPY etcd etcdctl migrate-if-needed.sh /usr/local/bin/
2 changes: 1 addition & 1 deletion cluster/images/etcd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

TAG?=3.0.4
ARCH?=amd64
REGISTRY?=gcr.io/google_containers
REGISTRY?=gcr.io/groovy-sentry-504
GOLANG_VERSION?=1.6.3
GOARM=6
TEMP_DIR:=$(shell mktemp -d)
Expand Down
64 changes: 64 additions & 0 deletions cluster/images/etcd/migrate-if-needed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/sh

# Copyright 2016 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# 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 <target-storage> <data-dir>
# It will look into the contents of file <data-dir>/version.txt to
# determine the current storage version (no file means etcd2).

set -o errexit
set -o nounset
set -o pipefail

if [ "$#" -ne 2 ]; then
echo "Incorrect number of argument"
echo "Expected usage: ./migrate_if_needed <target-storage> <data-dir>"
exit 1
fi

TARGET_STORAGE=$1
DATA_DIRECTORY=$2
VERSION_FILE="version.txt"

CURRENT_STORAGE='etcd2'
if [ -e "${DATA_DIRECTORY}/${VERSION_FILE}" ]; then
CURRENT_STORAGE="$(cat ${DATA_DIRECTORY}/${VERSION_FILE})"
fi

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.
if [ -d "${DATA_DIRECTORY}" ]; then
if [ "$(ls -A ${DATA_DIRECTORY})" ]; then
echo "Performing etcd2 -> etcd3 migration"
# TODO: Pass a correct transformer to handle TTLs.
ETCDCTL_API=3 /usr/local/bin/etcdctl migrate --data-dir=${DATA_DIRECTORY}
fi
fi
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."
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}"
5 changes: 3 additions & 2 deletions cluster/saltbase/salt/etcd/etcd.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
{% endfor -%}
{% set etcd_cluster = vars.etcd_cluster -%}
{% set cluster_state = vars.cluster_state -%}
{% set storage_backend = pillar.get('storage_backend_', 'etcd2') -%}

{
"apiVersion": "v1",
Expand All @@ -27,7 +28,7 @@
"containers":[
{
"name": "etcd-container",
"image": "gcr.io/google_containers/etcd:3.0.3",
"image": "gcr.io/groovy-sentry-504/etcd:3.0.4",
"resources": {
"requests": {
"cpu": {{ cpulimit }}
Expand All @@ -36,7 +37,7 @@
"command": [
"/bin/sh",
"-c",
"/usr/local/bin/etcd --name etcd-{{ hostname }} --listen-peer-urls http://{{ hostname }}:{{ server_port }} --initial-advertise-peer-urls http://{{ hostname }}:{{ 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 }} --initial-cluster-state {{ cluster_state }} --initial-cluster {{ etcd_cluster }} 1>>/var/log/etcd{{ suffix }}.log 2>&1"
"/usr/local/bin/migrate-if-needed.sh {{ storage_backend }} /var/etcd/data{{ suffix }}; /usr/local/bin/etcd --name etcd-{{ hostname }} --listen-peer-urls http://{{ hostname }}:{{ server_port }} --initial-advertise-peer-urls http://{{ hostname }}:{{ 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 }} --initial-cluster-state {{ cluster_state }} --initial-cluster {{ etcd_cluster }} 1>>/var/log/etcd{{ suffix }}.log 2>&1"
],
"livenessProbe": {
"httpGet": {
Expand Down

0 comments on commit d27c118

Please sign in to comment.