Skip to content

Commit

Permalink
kind infra, present ensure_memory_dir_for_etcd_data
Browse files Browse the repository at this point in the history
In order to run etcd in memory it is necessary
to create tmpfs mount to back the directory that
will be mounted to KIND cluster node.

'ensure_memory_dir_for_etcd_data' function
ensures that the directory '$ETCD_DATA_DIR'
exists, empty, and mounted as tmpfs.

'cleanup_dir_for_etcd_data' will teardown
the mount and directory that created by
'ensure_memory_dir_for_etcd_data'
It will be invoked by 'make cluster-down'

Signed-off-by: Or Mergi <[email protected]>
  • Loading branch information
ormergi committed Nov 17, 2020
1 parent 8727fb4 commit 98c7518
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions cluster-up/cluster/kind/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <<EOF >> ${KUBEVIRTCI_CONFIG_PATH}/$KUBEVIRT_PROVIDER/kind.yaml
Expand Down Expand Up @@ -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
}

0 comments on commit 98c7518

Please sign in to comment.