Skip to content
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

fix migration script #143

Merged
merged 2 commits into from
May 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"