Skip to content

Commit

Permalink
bindata/etcd: add exec_etcdctl function
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Batschelet <sbatsche@redhat.com>
  • Loading branch information
hexfusion committed Mar 18, 2020
1 parent da18363 commit b0f0d08
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
11 changes: 11 additions & 0 deletions bindata/etcd/etcd-common-tools
Expand Up @@ -20,3 +20,14 @@ function dl_etcdctl {
podman rm "${etcdctr}"
etcdctl version
}

# execute etcdctl command inside of running etcdctl container
function exec_etcdctl {
local command="$@"
local container_id=$(sudo crictl ps --label io.kubernetes.container.name=etcdctl -o json | jq -r '.containers[0].id') || true
if [ -z "$container_id" ]; then
echo "etcdctl container is not running"
exit 1
fi
crictl exec -it $container_id /bin/sh -c "etcdctl $command"
}
8 changes: 2 additions & 6 deletions bindata/etcd/etcd-member-remove.sh
Expand Up @@ -18,7 +18,6 @@ function usage {
exit 1
}

### main
if [ "$1" == "" ]; then
usage
fi
Expand All @@ -28,15 +27,12 @@ NAME="$1"
source /etc/kubernetes/static-pod-resources/etcd-certs/configmaps/etcd-scripts/etcd.env
source /etc/kubernetes/static-pod-resources/etcd-certs/configmaps/etcd-scripts/etcd-common-tools

# Download etcdctl binary
dl_etcdctl

# If the 1st field or the 3rd field of the member list exactly matches with the name, then get its ID. Note 3rd field has extra space to match.
ID=$(etcdctl member list | awk -F, "\$1 ~ /^${NAME}$/ || \$3 ~ /^\s${NAME}$/ { print \$1 }")
ID=$(exec_etcdctl "member list" | awk -F, "\$1 ~ /^${NAME}$/ || \$3 ~ /^\s${NAME}$/ { print \$1 }")
if [ "$?" -ne 0 ] || [ -z "$ID" ]; then
echo "could not find etcd member $NAME to remove."
exit 1
fi

# Remove the member using ID
etcdctl member remove $ID
exec_etcdctl "member remove $ID"
19 changes: 13 additions & 6 deletions pkg/operator/etcd_assets/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b0f0d08

Please sign in to comment.