From 9e4dff1e1dc86352925ce4b7a828a237419ed13f Mon Sep 17 00:00:00 2001 From: Matt Schallert Date: Fri, 17 May 2019 16:20:13 -0400 Subject: [PATCH] fix migration script (#143) - remove new line char from etcd get - remove key name from etcd get - -i flag required on kubectl exec - correct version numbers in comments Co-authored-by: Arnaud Meyer --- scripts/migrate_etcd_0.1_0.2.sh | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/scripts/migrate_etcd_0.1_0.2.sh b/scripts/migrate_etcd_0.1_0.2.sh index 7e1a2fa1..3f5405ca 100755 --- a/scripts/migrate_etcd_0.1_0.2.sh +++ b/scripts/migrate_etcd_0.1_0.2.sh @@ -2,9 +2,17 @@ set -exo pipefail +TMP=$(mktemp) + +function cleanup() { + rm -f "$TMP" +} + +trap cleanup EXIT + if [[ "$1" == "-h" || -z "$ETCD_NS" || -z "$ETCD_POD" || -z "$M3DB_NS" || -z "$M3DB_CLUSTER" ]]; then - echo "Script for migrating etcd data from m3db-operator 0.2 -> 0.3" - echo "Usage: ETCD_NS= ETCD_POD= M3DB_NS= M3DB_CLUSTER= ./migrate_etcd_0.2_0.3.sh" + echo "Script for migrating etcd data from m3db-operator 0.1 -> 0.2" + echo "Usage: ETCD_NS= ETCD_POD= M3DB_NS= M3DB_CLUSTER= ./migrate_etcd_0.1_0.2.sh" exit 0 fi @@ -19,5 +27,17 @@ fi ENV="$NS/$CLUSTER" echo "Copying namespace and placement data from env=default_env to env=$ENV" -kubectl exec -n "$ETCD_NS" "$ETCD_POD" -- env ETCDCTL_API=3 etcdctl get _sd.placement/default_env/m3db | kubectl exec -n "$ETCD_NS" "$ETCD_POD" -- env ETCDCTL_API=3 etcdctl put "_sd.placement/$ENV/m3db" -kubectl exec -n "$ETCD_NS" "$ETCD_POD" -- env ETCDCTL_API=3 etcdctl get _kv/default_env/m3db.node.namespaces | kubectl exec -n "$ETCD_NS" "$ETCD_POD" -- env ETCDCTL_API=3 etcdctl put "_kv/$ENV/m3db.node.namespaces" + +# Put placement bytes (includes trailing newline) into TMP +kubectl exec -n "$ETCD_NS" "$ETCD_POD" -- env ETCDCTL_API=3 etcdctl get --print-value-only _sd.placement/default_env/m3db > "$TMP" + +# Trim newline in a cross-platform (OSX + Linux) manner and put in new key +N=$(<"$TMP" wc -c) +N=$((N-1)) +head -c "$N" "$TMP" | kubectl exec -i -n "$ETCD_NS" "$ETCD_POD" -- env ETCDCTL_API=3 etcdctl put "_sd.placement/$ENV/m3db" + +# Repeat for namespaces +kubectl exec -n "$ETCD_NS" "$ETCD_POD" -- env ETCDCTL_API=3 etcdctl get --print-value-only _kv/default_env/m3db.node.namespaces > "$TMP" +N=$(<"$TMP" wc -c) +N=$((N-1)) +head -c "$N" "$TMP" | kubectl exec -i -n "$ETCD_NS" "$ETCD_POD" -- env ETCDCTL_API=3 etcdctl put "_kv/$ENV/m3db.node.namespaces"