diff --git a/tests/scripts/create-dev-cluster.sh b/tests/scripts/create-dev-cluster.sh index 929daa379a55..674acf4b7f51 100755 --- a/tests/scripts/create-dev-cluster.sh +++ b/tests/scripts/create-dev-cluster.sh @@ -4,17 +4,22 @@ DEFAULT_NS="rook-ceph" CLUSTER_FILES="common.yaml operator.yaml cluster-test.yaml cluster-on-pvc-minikube.yaml dashboard-external-http.yaml toolbox.yaml" MONITORING_FILES="monitoring/prometheus.yaml monitoring/service-monitor.yaml monitoring/exporter-service-monitor.yaml monitoring/prometheus-service.yaml monitoring/rbac.yaml" SCRIPT_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P) -ROOK_EXAMPLES_DIR="${SCRIPT_ROOT}/../../deploy/examples/" + +# Script arguments: new arguments must be added here (following the same format) +export MINIKUBE_NODES="${MINIKUBE_NODES:=1}" ## Specify the minikube number of nodes to create +export MINIKUBE_DISK_SIZE="${MINIKUBE_DISK_SIZE:=40g}" ## Specify the minikube disk size +export MINIKUBE_EXTRA_DISKS="${MINIKUBE_EXTRA_DISKS:=3}" ## Specify the minikube number of extra disks +export ROOK_PROFILE_NAME="${ROOK_PROFILE_NAME:=rook}" ## Specify the minikube profile name +export ROOK_CLUSTER_NS="${ROOK_CLUSTER_NS:=$DEFAULT_NS}" ## CephCluster namespace +export ROOK_OPERATOR_NS="${ROOK_OPERATOR_NS:=$DEFAULT_NS}" ## Rook operator namespace (if different from CephCluster namespace) +export ROOK_EXAMPLES_DIR="${ROOK_EXAMPLES_DIR:="$SCRIPT_ROOT"/../../deploy/examples}" ## Path to Rook examples directory (i.e github.com/rook/rook/deploy/examples) +export ROOK_CLUSTER_SPEC_FILE="${ROOK_CLUSTER_SPEC_FILE:=cluster-test.yaml}" ## CephCluster manifest file init_vars(){ - ROOK_PROFILE_NAME=${1:-rook} - ROOK_CLUSTER_NS=${2:-$DEFAULT_NS} - ROOK_OPERATOR_NS=${3:-$DEFAULT_NS} - ROOK_CLUSTER_SPEC_FILE=${4:-cluster-test.yaml} MINIKUBE="minikube --profile $ROOK_PROFILE_NAME" KUBECTL="$MINIKUBE kubectl --" - echo "Using '$ROOK_EXAMPLES_DIR' as examples directory.." + echo "Using '$(realpath "$ROOK_EXAMPLES_DIR")' as examples directory.." echo "Using '$ROOK_CLUSTER_SPEC_FILE' as cluster spec file.." echo "Using '$ROOK_PROFILE_NAME' as minikube profile.." echo "Using '$ROOK_CLUSTER_NS' as cluster namespace.." @@ -22,17 +27,19 @@ init_vars(){ } update_namespaces() { - for file in $CLUSTER_FILES $MONITORING_FILES; do - echo "Updating namespace on $file" - sed -i.bak \ - -e "s/\(.*\):.*# namespace:operator/\1: $ROOK_OPERATOR_NS # namespace:operator/g" \ - -e "s/\(.*\):.*# namespace:cluster/\1: $ROOK_CLUSTER_NS # namespace:cluster/g" \ - -e "s/\(.*serviceaccount\):.*:\(.*\) # serviceaccount:namespace:operator/\1:$ROOK_OPERATOR_NS:\2 # serviceaccount:namespace:operator/g" \ - -e "s/\(.*serviceaccount\):.*:\(.*\) # serviceaccount:namespace:cluster/\1:$ROOK_CLUSTER_NS:\2 # serviceaccount:namespace:cluster/g" \ - -e "s/\(.*\): [-_A-Za-z0-9]*\.\(.*\) # driver:namespace:operator/\1: $ROOK_OPERATOR_NS.\2 # driver:namespace:operator/g" \ - -e "s/\(.*\): [-_A-Za-z0-9]*\.\(.*\) # driver:namespace:cluster/\1: $ROOK_CLUSTER_NS.\2 # driver:namespace:cluster/g" \ - "$file" - done + if [ "$ROOK_CLUSTER_NS" != "$DEFAULT_NS" ] || [ "$ROOK_OPERATOR_NS" != "$DEFAULT_NS" ]; then + for file in $CLUSTER_FILES $MONITORING_FILES; do + echo "Updating namespace on $file" + sed -i.bak \ + -e "s/\(.*\):.*# namespace:operator/\1: $ROOK_OPERATOR_NS # namespace:operator/g" \ + -e "s/\(.*\):.*# namespace:cluster/\1: $ROOK_CLUSTER_NS # namespace:cluster/g" \ + -e "s/\(.*serviceaccount\):.*:\(.*\) # serviceaccount:namespace:operator/\1:$ROOK_OPERATOR_NS:\2 # serviceaccount:namespace:operator/g" \ + -e "s/\(.*serviceaccount\):.*:\(.*\) # serviceaccount:namespace:cluster/\1:$ROOK_CLUSTER_NS:\2 # serviceaccount:namespace:cluster/g" \ + -e "s/\(.*\): [-_A-Za-z0-9]*\.\(.*\) # driver:namespace:operator/\1: $ROOK_OPERATOR_NS.\2 # driver:namespace:operator/g" \ + -e "s/\(.*\): [-_A-Za-z0-9]*\.\(.*\) # driver:namespace:cluster/\1: $ROOK_CLUSTER_NS.\2 # driver:namespace:cluster/g" \ + "$file" + done + fi } wait_for_ceph_cluster() { @@ -105,7 +112,7 @@ setup_minikube_env() { minikube_driver="$(get_minikube_driver)" echo "Setting up minikube env for profile '$ROOK_PROFILE_NAME' (using $minikube_driver driver)" $MINIKUBE delete - $MINIKUBE start --disk-size=40g --extra-disks=3 --driver "$minikube_driver" + $MINIKUBE start --disk-size="$MINIKUBE_DISK_SIZE" --extra-disks="$MINIKUBE_EXTRA_DISKS" --driver "$minikube_driver" -n "$MINIKUBE_NODES" eval "$($MINIKUBE docker-env)" } @@ -173,15 +180,13 @@ enable_monitoring() { show_usage() { echo "" - echo " Usage: $(basename "$0") [-r] [-m] [-p ] [-d /path/to/rook-examples/dir]" - echo " -f Force cluster creation by deleting minikube profile" - echo " -r Enable rook orchestrator" - echo " -m Enable monitoring" - echo " -p Specify the minikube profile name" - echo " -d value Path to Rook examples directory (i.e github.com/rook/rook/deploy/examples)" - echo " -c " - echo " -o " - echo " -i Specify the cluster file spec name" + echo "Usage: [ARG=VALUE]... $(basename "$0") [-f] [-r] [-m]" + echo " -f Force cluster creation by deleting minikube profile" + echo " -r Enable rook orchestrator" + echo " -m Enable monitoring" + echo " Args:" + sed -n -E "s/^export (.*)=\".*:=.*\" ## (.*)/ \1 (\\$\1): \2/p;" "$SCRIPT_ROOT"/"$(basename "$0")" | envsubst + echo "" } invocation_error() { @@ -193,7 +198,7 @@ invocation_error() { #################################################################### ################# MAIN ############################################# -while getopts ":hrmfd:p:i:c:o:" opt; do +while getopts ":hrmf" opt; do case $opt in h) show_usage @@ -208,21 +213,6 @@ while getopts ":hrmfd:p:i:c:o:" opt; do f) force_minikube=true ;; - d) - ROOK_EXAMPLES_DIR="$OPTARG" - ;; - p) - minikube_profile_name="$OPTARG" - ;; - i) - cluster_spec_file="$OPTARG" - ;; - c) - rook_cluster_ns="$OPTARG" - ;; - o) - rook_operator_ns="$OPTARG" - ;; \?) invocation_error "Invalid option: -$OPTARG" ;; @@ -232,30 +222,21 @@ while getopts ":hrmfd:p:i:c:o:" opt; do esac done -init_vars "$minikube_profile_name" "$rook_cluster_ns" "$rook_operator_ns" "$cluster_spec_file" +# initialization zone +init_vars change_to_examples_dir +[ -z "$force_minikube" ] && check_minikube_exists +update_namespaces -if [ -z "$force_minikube" ]; then - check_minikube_exists -fi - -if [ "$rook_cluster_ns" != "$DEFAULT_NS" ] || [ "$rook_operator_ns" != "$DEFAULT_NS" ]; then - update_namespaces -fi - +# cluster creation zone setup_minikube_env create_rook_cluster wait_for_rook_operator wait_for_ceph_cluster -if [ "$enable_rook" = true ]; then - enable_rook_orchestrator -fi - -if [ "$enable_monitoring" = true ]; then - enable_monitoring -fi - +# final tweaks and ceph cluster tuning +[ "$enable_rook" = true ] && enable_rook_orchestrator +[ "$enable_monitoring" = true ] && enable_monitoring show_info "$enable_monitoring" ####################################################################