diff --git a/bindata/etcd/etcd-common-tools b/bindata/etcd/etcd-common-tools index 5f381ff4c..ebff8bb56 100644 --- a/bindata/etcd/etcd-common-tools +++ b/bindata/etcd/etcd-common-tools @@ -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" +} diff --git a/bindata/etcd/etcd-member-remove.sh b/bindata/etcd/etcd-member-remove.sh index 687b75126..d831b9bda 100644 --- a/bindata/etcd/etcd-member-remove.sh +++ b/bindata/etcd/etcd-member-remove.sh @@ -18,7 +18,6 @@ function usage { exit 1 } -### main if [ "$1" == "" ]; then usage fi @@ -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" diff --git a/pkg/operator/etcd_assets/bindata.go b/pkg/operator/etcd_assets/bindata.go index 450d62822..41d7ae4f0 100644 --- a/pkg/operator/etcd_assets/bindata.go +++ b/pkg/operator/etcd_assets/bindata.go @@ -123,6 +123,17 @@ 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" +} `) func etcdEtcdCommonToolsBytes() ([]byte, error) { @@ -160,7 +171,6 @@ function usage { exit 1 } -### main if [ "$1" == "" ]; then usage fi @@ -170,18 +180,15 @@ 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" `) func etcdEtcdMemberRemoveShBytes() ([]byte, error) {