Skip to content

Commit

Permalink
fix migration script (#143)
Browse files Browse the repository at this point in the history
- 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 <arnaud.meyer@idealo.de>
  • Loading branch information
schallert and Arnaud Meyer authored May 17, 2019
1 parent 165bee3 commit 9e4dff1
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions scripts/migrate_etcd_0.1_0.2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=<namespace> ETCD_POD=<pod> M3DB_NS=<namespace> M3DB_CLUSTER=<cluster_name> ./migrate_etcd_0.2_0.3.sh"
echo "Script for migrating etcd data from m3db-operator 0.1 -> 0.2"
echo "Usage: ETCD_NS=<namespace> ETCD_POD=<pod> M3DB_NS=<namespace> M3DB_CLUSTER=<cluster_name> ./migrate_etcd_0.1_0.2.sh"
exit 0
fi

Expand All @@ -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"

0 comments on commit 9e4dff1

Please sign in to comment.