diff --git a/cluster-up/cluster/kind/common.sh b/cluster-up/cluster/kind/common.sh index df967e2c04..2bc0a5c470 100755 --- a/cluster-up/cluster/kind/common.sh +++ b/cluster-up/cluster/kind/common.sh @@ -15,6 +15,8 @@ REGISTRY_NAME=${CLUSTER_NAME}-registry MASTER_NODES_PATTERN="control-plane" WORKER_NODES_PATTERN="worker" +ETCD_DATA_DIR=${ETCD_DATA_DIR:-none} + function _wait_kind_up { echo "Waiting for kind to be ready ..." while [ -z "$(docker exec --privileged ${CLUSTER_NAME}-control-plane kubectl --kubeconfig=/etc/kubernetes/admin.conf get nodes --selector=node-role.kubernetes.io/master -o=jsonpath='{.items..status.conditions[-1:].status}' | grep True)" ]; do @@ -192,6 +194,44 @@ function setup_kind() { prepare_config } +function ensure_memory_dir_for_etcd_data() { + if [ "$ETCD_DATA_DIR" == none ];then + echo "ETCD_DATA_DIR is not defined" + exit 1 + fi + + if grep -qs $ETCD_DATA_DIR /proc/mounts; then + echo "etcd data mount already exists" + df -h $ETCD_DATA_DIR + if [ -d "$ETCD_DATA_DIR" ];then + echo "ectd data directory already exists, cleaning up directory content..." + rm -rf $ETCD_DATA_DIR/* + df -h $ETCD_DATA_DIR + fi + else + echo "creating directory for ectd data" + mkdir -p $ETCD_DATA_DIR + [ "$(echo $?)" != 0 ] && echo "failed to create etcd data directory" && exit 1 + ls -lsah $ETCD_DATA_DIR + + echo "mount etcd data directory as tempfs" + mount -t tmpfs tmpfs $ETCD_DATA_DIR + [ "$(echo $?)" != 0 ] && echo "failed to mount etcd data directory" && exit 1 + df -h $ETCD_DATA_DIR + fi +} + +function cleanup_dir_for_etcd_data() { + if grep -qs $ETCD_DATA_DIR /proc/mounts; then + umount -f $ETCD_IN_MEMORY &> 1 + [ "$(echo $?)" == 0 ] && echo "etcd data directory umounted" + fi + if [ -d "$ETCD_DATA_DIR" ];then + rm -rf $ETCD_IN_MEMORY + echo "etcd data directory deleted" + fi +} + function _add_worker_extra_mounts() { if [[ "$KUBEVIRT_PROVIDER" =~ sriov.* ]]; then cat <> ${KUBEVIRTCI_CONFIG_PATH}/$KUBEVIRT_PROVIDER/kind.yaml @@ -254,4 +294,8 @@ function down() { fi $KIND delete cluster --name=${CLUSTER_NAME} rm -f ${KUBEVIRTCI_CONFIG_PATH}/$KUBEVIRT_PROVIDER/kind.yaml + + if [ "$ETCD_DATA_DIR" != none ];then + cleanup_dir_for_etcd_data + fi }