2019-12-03 12:36:15 +00:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
|
|
|
ROOK_VERSION=${ROOK_VERSION:-"v1.1.7"}
|
|
|
|
ROOK_DEPLOY_TIMEOUT=${ROOK_DEPLOY_TIMEOUT:-300}
|
|
|
|
ROOK_URL="https://raw.githubusercontent.com/rook/rook/${ROOK_VERSION}/cluster/examples/kubernetes/ceph"
|
|
|
|
|
|
|
|
function deploy_rook() {
|
2020-01-20 11:28:30 +00:00
|
|
|
kubectl create -f "${ROOK_URL}/common.yaml"
|
|
|
|
kubectl create -f "${ROOK_URL}/operator.yaml"
|
|
|
|
kubectl create -f "${ROOK_URL}/cluster-test.yaml"
|
|
|
|
kubectl create -f "${ROOK_URL}/toolbox.yaml"
|
|
|
|
kubectl create -f "${ROOK_URL}/filesystem-test.yaml"
|
|
|
|
kubectl create -f "${ROOK_URL}/pool-test.yaml"
|
2019-12-03 12:36:15 +00:00
|
|
|
|
2020-01-14 04:55:11 +00:00
|
|
|
# Check if CephCluster is empty
|
2020-01-20 11:28:30 +00:00
|
|
|
if ! kubectl -n rook-ceph get cephclusters -oyaml | grep 'items: \[\]' &>/dev/null; then
|
2020-01-14 04:55:11 +00:00
|
|
|
check_ceph_cluster_health
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if CephFileSystem is empty
|
2020-01-20 11:28:30 +00:00
|
|
|
if ! kubectl -n rook-ceph get cephfilesystems -oyaml | grep 'items: \[\]' &>/dev/null; then
|
2020-01-14 04:55:11 +00:00
|
|
|
check_mds_stat
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if CephBlockPool is empty
|
2020-01-20 11:28:30 +00:00
|
|
|
if ! kubectl -n rook-ceph get cephblockpools -oyaml | grep 'items: \[\]' &>/dev/null; then
|
2020-01-14 04:55:11 +00:00
|
|
|
check_rbd_stat
|
|
|
|
fi
|
2019-12-03 12:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function teardown_rook() {
|
2020-01-20 11:28:30 +00:00
|
|
|
kubectl delete -f "${ROOK_URL}/pool-test.yaml"
|
|
|
|
kubectl delete -f "${ROOK_URL}/filesystem-test.yaml"
|
|
|
|
kubectl delete -f "${ROOK_URL}/toolbox.yaml"
|
|
|
|
kubectl delete -f "${ROOK_URL}/cluster-test.yaml"
|
|
|
|
kubectl delete -f "${ROOK_URL}/operator.yaml"
|
|
|
|
kubectl delete -f "${ROOK_URL}/common.yaml"
|
2019-12-03 12:36:15 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 11:28:30 +00:00
|
|
|
function check_ceph_cluster_health() {
|
|
|
|
for ((retry = 0; retry <= ROOK_DEPLOY_TIMEOUT; retry = retry + 5)); do
|
2020-01-14 04:55:11 +00:00
|
|
|
echo "Wait for rook deploy... ${retry}s" && sleep 5
|
|
|
|
|
|
|
|
CEPH_STATE=$(kubectl -n rook-ceph get cephclusters -o jsonpath='{.items[0].status.state}')
|
|
|
|
CEPH_HEALTH=$(kubectl -n rook-ceph get cephclusters -o jsonpath='{.items[0].status.ceph.health}')
|
|
|
|
echo "Checking CEPH cluster state: [$CEPH_STATE]"
|
|
|
|
if [ "$CEPH_STATE" = "Created" ]; then
|
|
|
|
if [ "$CEPH_HEALTH" = "HEALTH_OK" ]; then
|
|
|
|
echo "Creating CEPH cluster is done. [$CEPH_HEALTH]"
|
2020-01-20 11:28:30 +00:00
|
|
|
break
|
2020-01-14 04:55:11 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
2020-02-07 00:43:37 +00:00
|
|
|
|
|
|
|
if [ "$retry" -gt "$ROOK_DEPLOY_TIMEOUT" ]; then
|
|
|
|
echo "[Timeout] CEPH cluster not in a healthy state (timeout)"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-01-14 04:55:11 +00:00
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
2020-01-20 11:28:30 +00:00
|
|
|
function check_mds_stat() {
|
|
|
|
for ((retry = 0; retry <= ROOK_DEPLOY_TIMEOUT; retry = retry + 5)); do
|
2020-01-14 04:55:11 +00:00
|
|
|
FS_NAME=$(kubectl -n rook-ceph get cephfilesystems.ceph.rook.io -ojsonpath='{.items[0].metadata.name}')
|
|
|
|
echo "Checking MDS ($FS_NAME) stats... ${retry}s" && sleep 5
|
|
|
|
|
|
|
|
ACTIVE_COUNT=$(kubectl -n rook-ceph get cephfilesystems myfs -ojsonpath='{.spec.metadataServer.activeCount}')
|
|
|
|
|
|
|
|
ACTIVE_COUNT_NUM=$((ACTIVE_COUNT + 0))
|
|
|
|
echo "MDS ($FS_NAME) active_count: [$ACTIVE_COUNT_NUM]"
|
2020-01-20 11:28:30 +00:00
|
|
|
if ((ACTIVE_COUNT_NUM < 1)); then
|
|
|
|
continue
|
2020-01-14 04:55:11 +00:00
|
|
|
else
|
2020-01-20 11:28:30 +00:00
|
|
|
if kubectl -n rook-ceph get pod -l rook_file_system=myfs | grep Running &>/dev/null; then
|
2020-01-14 04:55:11 +00:00
|
|
|
echo "Filesystem ($FS_NAME) is successfully created..."
|
2020-01-20 11:28:30 +00:00
|
|
|
break
|
2020-01-14 04:55:11 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
2020-02-07 00:43:37 +00:00
|
|
|
|
|
|
|
if [ "$retry" -gt "$ROOK_DEPLOY_TIMEOUT" ]; then
|
|
|
|
echo "[Timeout] Failed to get ceph filesystem pods"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-01-14 04:55:11 +00:00
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
2020-01-20 11:28:30 +00:00
|
|
|
function check_rbd_stat() {
|
|
|
|
for ((retry = 0; retry <= ROOK_DEPLOY_TIMEOUT; retry = retry + 5)); do
|
2020-01-14 04:55:11 +00:00
|
|
|
RBD_POOL_NAME=$(kubectl -n rook-ceph get cephblockpools -ojsonpath='{.items[0].metadata.name}')
|
|
|
|
echo "Checking RBD ($RBD_POOL_NAME) stats... ${retry}s" && sleep 5
|
|
|
|
|
|
|
|
TOOLBOX_POD=$(kubectl -n rook-ceph get pods -l app=rook-ceph-tools -o jsonpath='{.items[0].metadata.name}')
|
|
|
|
TOOLBOX_POD_STATUS=$(kubectl -n rook-ceph get pod "$TOOLBOX_POD" -ojsonpath='{.status.phase}')
|
2020-02-07 00:43:37 +00:00
|
|
|
[[ "$TOOLBOX_POD_STATUS" != "Running" ]] && \
|
|
|
|
{ echo "Toolbox POD ($TOOLBOX_POD) status: [$TOOLBOX_POD_STATUS]"; continue; }
|
2020-01-14 04:55:11 +00:00
|
|
|
|
2020-01-20 11:28:30 +00:00
|
|
|
if kubectl exec -n rook-ceph "$TOOLBOX_POD" -it -- rbd pool stats "$RBD_POOL_NAME" &>/dev/null; then
|
2020-01-14 04:55:11 +00:00
|
|
|
echo "RBD ($RBD_POOL_NAME) is successfully created..."
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2020-02-07 00:43:37 +00:00
|
|
|
|
|
|
|
if [ "$retry" -gt "$ROOK_DEPLOY_TIMEOUT" ]; then
|
|
|
|
echo "[Timeout] Failed to get RBD pool stats"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-01-14 04:55:11 +00:00
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
2019-12-03 12:36:15 +00:00
|
|
|
case "${1:-}" in
|
|
|
|
deploy)
|
2020-01-20 11:28:30 +00:00
|
|
|
deploy_rook
|
|
|
|
;;
|
2019-12-03 12:36:15 +00:00
|
|
|
teardown)
|
2020-01-20 11:28:30 +00:00
|
|
|
teardown_rook
|
|
|
|
;;
|
2019-12-03 12:36:15 +00:00
|
|
|
*)
|
2020-01-20 11:28:30 +00:00
|
|
|
echo " $0 [command]
|
2019-12-03 12:36:15 +00:00
|
|
|
Available Commands:
|
|
|
|
deploy Deploy a rook
|
|
|
|
teardown Teardown a rook
|
|
|
|
" >&2
|
2020-01-20 11:28:30 +00:00
|
|
|
;;
|
2019-12-03 12:36:15 +00:00
|
|
|
esac
|