diff --git a/cluster-up/cluster/kind-k8s-sriov-1.17.0/provider.sh b/cluster-up/cluster/kind-k8s-sriov-1.17.0/provider.sh index 9ca083d62d..e643ab1973 100755 --- a/cluster-up/cluster/kind-k8s-sriov-1.17.0/provider.sh +++ b/cluster-up/cluster/kind-k8s-sriov-1.17.0/provider.sh @@ -5,6 +5,9 @@ set -e export CLUSTER_NAME="sriov" export KIND_NODE_IMAGE="kindest/node:v1.17.0" +export BASE_ETCD_DATA_DIR="/mnt/kind-cluster-etcd" +export ETCD_DATA_DIR="$CLUSTER_NAME-$(date +%s)" + source ${KUBEVIRTCI_PATH}/cluster/kind/common.sh function up() { @@ -19,7 +22,6 @@ function up() { cp $KIND_MANIFESTS_DIR/kind.yaml ${KUBEVIRTCI_CONFIG_PATH}/$KUBEVIRT_PROVIDER/kind.yaml - export ETCD_DATA_DIR="/mnt/etcd" ensure_memory_dir_for_etcd_data kind_up diff --git a/cluster-up/cluster/kind/common.sh b/cluster-up/cluster/kind/common.sh index e722a42b2f..279ed491be 100755 --- a/cluster-up/cluster/kind/common.sh +++ b/cluster-up/cluster/kind/common.sh @@ -15,6 +15,7 @@ REGISTRY_NAME=${CLUSTER_NAME}-registry MASTER_NODES_PATTERN="control-plane" WORKER_NODES_PATTERN="worker" +BASE_ETCD_DATA_DIR=${BASE_ETCD_DATA_DIR:-none} ETCD_DATA_DIR=${ETCD_DATA_DIR:-none} function _wait_kind_up { @@ -195,40 +196,55 @@ function setup_kind() { } function ensure_memory_dir_for_etcd_data() { + if [ "$BASE_ETCD_DATA_DIR" == none ];then + echo "BASE_ETCD_DATA_DIR is not defined" + exit 1 + fi if [ "$ETCD_DATA_DIR" == none ];then echo "ETCD_DATA_DIR is not defined" exit 1 fi + + trap cleanup_dir_for_etcd_data ERR SIGINT SIGTERM - 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 + if grep -qs $BASE_ETCD_DATA_DIR /proc/mounts; then + echo "etcd data, base directory mount already exists" + df -h $BASE_ETCD_DATA_DIR + if [ -d "$BASE_ETCD_DATA_DIR" ];then echo "ectd data directory already exists, cleaning up directory content..." - rm -rf $ETCD_DATA_DIR/* - df -h $ETCD_DATA_DIR + rm -rf $BASE_ETCD_DATA_DIR/* + df -h $BASE_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 "Creating cluster etcd data base directory: $BASE_ETCD_DATA_DIR" + mkdir -p $BASE_ETCD_DATA_DIR - echo "mount etcd data directory as tempfs" - mount -t tmpfs tmpfs $ETCD_DATA_DIR + echo "Mount etcd data base directory to memory: $BASE_ETCD_DATA_DIR" + mount -t tmpfs -o size=1G tmpfs $BASE_ETCD_DATA_DIR [ "$(echo $?)" != 0 ] && echo "failed to mount etcd data directory" && exit 1 - df -h $ETCD_DATA_DIR + df -h $BASE_ETCD_DATA_DIR + + current_cluster_etcd_data_dir="$BASE_ETCD_DATA_DIR/$ETCD_DATA_DIR" + echo "Creating directory for current cluster etcd data: $current_cluster_etcd_data_dir" + mkdir -p $current_cluster_etcd_data_dir + [ "$(echo $?)" != 0 ] && echo "failed to create etcd data directory" && exit 1 + ls -lsah $current_cluster_etcd_data_dir fi } function cleanup_dir_for_etcd_data() { - if grep -qs $ETCD_DATA_DIR /proc/mounts; then - umount -f $ETCD_DATA_DIR &> 1 - [ "$(echo $?)" == 0 ] && echo "etcd data directory umounted" + if grep -qs $BASE_ETCD_DATA_DIR /proc/mounts; then + echo "Unmounting etcd data base directory: $BASE_ETCD_DATA_DIR" + df -h $BASE_ETCD_DATA_DIR + umount -f $BASE_ETCD_DATA_DIR &> 1 + [ "$(echo $?)" == 0 ] && echo "etcd data base directory umounted" fi - if [ -d "$ETCD_DATA_DIR" ];then - rm -rf $ETCD_DATA_DIR - echo "etcd data directory deleted" + + if [ -d "$BASE_ETCD_DATA_DIR" ];then + echo "Removing etcd current cluster data directory: $BASE_ETCD_DATA_DIR" + rm -rf $BASE_ETCD_DATA_DIR + [ "$(echo $?)" == 0 ] && echo "etcd data base directory deleted" + fi } @@ -272,11 +288,11 @@ EOF function _add_control_plane_extra_mounts() { if [[ "$KUBEVIRT_PROVIDER" =~ sriov.* ]]; then - if [ "$ETCD_DATA_DIR" != none ]; then + if [ -d "$BASE_ETCD_DATA_DIR/$ETCD_DATA_DIR" ]; then cat <> ${KUBEVIRTCI_CONFIG_PATH}/$KUBEVIRT_PROVIDER/kind.yaml extraMounts: - containerPath: /var/lib/etcd - hostPath: $ETCD_DATA_DIR + hostPath: $BASE_ETCD_DATA_DIR/$ETCD_DATA_DIR EOF fi fi @@ -308,7 +324,7 @@ function down() { $KIND delete cluster --name=${CLUSTER_NAME} rm -f ${KUBEVIRTCI_CONFIG_PATH}/$KUBEVIRT_PROVIDER/kind.yaml - if [ "$ETCD_DATA_DIR" != none ];then + if [ "$ETCD_DATA_DIR" != none ] && [ "$BASE_ETCD_DATA_DIR" != none ];then cleanup_dir_for_etcd_data fi }