-
Notifications
You must be signed in to change notification settings - Fork 38.8k
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
Support for etcd migration #30500
Support for etcd migration #30500
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/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 | ||
|
||
if [ -z "${TARGET_STORAGE:-}" ]; then | ||
echo "TARGET_USAGE variable unset - skipping migration" | ||
exit 0 | ||
fi | ||
|
||
if [ -z "${DATA_DIRECTORY:-}" ]; then | ||
echo "DATA_DIRECTORY variable unset - skipping migration" | ||
exit 0 | ||
fi | ||
|
||
ETCDCTL="${ETCDCTL:-/usr/local/bin/etcdctl}" | ||
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. | ||
echo "ETCDCTL_API=3 ${ETCDCTL} migrate --data-dir=${DATA_DIRECTORY}" | ||
ETCDCTL_API=3 ${ETCDCTL} migrate --data-dir=${DATA_DIRECTORY} | ||
fi | ||
fi | ||
fi | ||
|
||
if [ "${CURRENT_STORAGE}" = "etcd3" -a "${TARGET_STORAGE}" = "etcd2" ]; then | ||
echo "Performing etcd3 -> etcd2 migration" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's useful to check this in until we figure this step out, since we want to first push a container that can do a rollback, and then after a minor release switch to a container that will do a roll-forward. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's useful, because it will allow us to at least start some real upgrade testing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I said, i think there is huge value in merging it asap, since this will allow:
|
||
# 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}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can and should unit test this, by starting etcd2/3, writing something, stopping it, run the script, then start etcd3/2 and verify the written thing is there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added test for etcd2 -. etcd3 migration (by extending the existing test-update-objects test).
This should be good enough starting point.
[Rollback is not supported yet, so there is obviously no test for it.]