diff --git a/charts/hedera-network/templates/tests/test-deployment.yaml b/charts/hedera-network/templates/tests/test-deployment.yaml index 0eab70989..4f4ad87aa 100644 --- a/charts/hedera-network/templates/tests/test-deployment.yaml +++ b/charts/hedera-network/templates/tests/test-deployment.yaml @@ -54,6 +54,8 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace + - name: RELEASE_NAME + value: {{ $.Release.Name }} command: - "/bin/bash" - "-c" diff --git a/charts/hedera-network/tests/env.sh b/charts/hedera-network/tests/env.sh index 050672dce..b5c1cf39a 100755 --- a/charts/hedera-network/tests/env.sh +++ b/charts/hedera-network/tests/env.sh @@ -21,6 +21,7 @@ TESTS_DIR="${TESTS_DIR:-${CUR_DIR}}" TOTAL_NODES="${TOTAL_NODES:-3}" USER="${USER:-changeme}" NAMESPACE="${NAMESPACE:-fst-${USER}}" +RELEASE_NAME="${RELEASE_NAME:-fst}" LOG_DIR="${LOG_DIR:-${CUR_DIR}/logs}" LOG_FILE="${LOG_FILE:-helm-test.log}" OUTPUT_LOG="${OUTPUT_LOG:-false}" @@ -28,6 +29,7 @@ OUTPUT_LOG="${OUTPUT_LOG:-false}" echo "--------------------------Env Setup: fullstack-testing Helm Test------------------------------------------------" echo "NAMESPACE: ${NAMESPACE}" +echo "RELEASE_NAME: ${RELEASE_NAME}" echo "ENV_FILE: ${ENV_FILE}" echo "BATS_HOME: ${BATS_HOME}" echo "TESTS_DIR: ${TESTS_DIR}" diff --git a/charts/hedera-network/tests/env.template b/charts/hedera-network/tests/env.template index 5ed4d1fb1..5cdfb56a0 100644 --- a/charts/hedera-network/tests/env.template +++ b/charts/hedera-network/tests/env.template @@ -1,5 +1,6 @@ USER="${USER:-changeme}" NAMESPACE="${NAMESPACE:-fst-${USER}}" +RELEASE_NAME="${RELEASE_NAME:-fst}" TOTAL_NODES=3 diff --git a/charts/hedera-network/tests/helper.sh b/charts/hedera-network/tests/helper.sh index b86255dfa..6b6b336b6 100644 --- a/charts/hedera-network/tests/helper.sh +++ b/charts/hedera-network/tests/helper.sh @@ -83,7 +83,7 @@ function check_test_status() { function get_config_val() { local config_path=$1 log_debug "Get config command: helm get values fst -a -n ${NAMESPACE} | yq '${config_path}'" - ret=$(helm get values fst -a -n "${NAMESPACE}" | yq "${config_path}" ) + ret=$(helm get values ${RELEASE_NAME} -a -n "${NAMESPACE}" | yq "${config_path}" ) echo "${ret}" log_debug "${config_path} => ${ret}" } diff --git a/dev/scripts/env.sh b/dev/scripts/env.sh index ba7b11325..d5cc1b2ec 100644 --- a/dev/scripts/env.sh +++ b/dev/scripts/env.sh @@ -1,51 +1,7 @@ #!/usr/bin/env bash - start_time=$(date +%s) -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" - -readonly SCRIPT_DIR -readonly TMP_DIR="${SCRIPT_DIR}/../temp" -readonly SETUP_CHART_DIR="${SCRIPT_DIR}/../../charts/fullstack-cluster-setup" -readonly CHART_DIR="${SCRIPT_DIR}/../../charts/hedera-network" - -POD_MONITOR_ROLE="${POD_MONITOR_ROLE:-pod-monitor-role}" -GATEWAY_CLASS_NAME="${GATEWAY_CLASS_NAME:-fst-gateway-class}" - -# telemetry related env variables -readonly COMMON_RESOURCES="${SCRIPT_DIR}/../common-resources" -readonly GATEWAY_API_DIR="${SCRIPT_DIR}/../gateway-api" -readonly TELEMETRY_DIR="${SCRIPT_DIR}/../telemetry" -readonly PROMETHEUS_DIR="${TELEMETRY_DIR}/prometheus" -readonly PROMETHEUS_VERSION=v0.67.1 -readonly PROMETHEUS_OPERATOR_YAML="${PROMETHEUS_DIR}/prometheus-operator.yaml" -readonly PROMETHEUS_YAML="${PROMETHEUS_DIR}/prometheus.yaml" -readonly PROMETHEUS_RBAC_YAML="${PROMETHEUS_DIR}/prometheus-rbac.yaml" -readonly PROMETHEUS_EXAMPLE_APP_YAML="${PROMETHEUS_DIR}/example-app.yaml" - -# docker build related env variables -readonly DOCKERFILE_DIR="${SCRIPT_DIR}/../../docker" -readonly LOCAL_DOCKER_REGISTRY="docker.fst.local" # same as in dev/ci/ci-values.yaml -readonly LOCAL_DOCKER_IMAGE_TAG="local" - -function setup_temp_dir() { - if [ ! -f "${TMP_DIR}/.env" ]; then \ - echo "Creating .env file from template.env" - cp "${SCRIPT_DIR}/template.env" "${TMP_DIR}/.env" - echo "File list in ${TMP_DIR}" - ls -la "${TMP_DIR}" - fi -} - -function load_env_file() { - if [ -f "${TMP_DIR}/.env" ]; then \ - set -a - # shellcheck source=./../temp/.env - source "${TMP_DIR}/.env" - set +a - fi -} - +# -------------------- Helper Functions -------------------------------------------------- function setup_kubectl_context() { load_env_file [[ -z "${CLUSTER_NAME}" ]] && echo "ERROR: Cluster name is required" && return 1 @@ -69,11 +25,6 @@ function setup_kubectl_context() { kubectl config get-contexts } -function setup() { - setup_temp_dir - load_env_file -} - function log_time() { local end_time duration execution_time @@ -87,14 +38,81 @@ function log_time() { echo "-----------------------------------------------------------------------------------------------------" } -setup - -echo "--------------------------Env Setup: fullstack-testing ------------------------------------------------" -echo "CLUSTER_NAME: ${CLUSTER_NAME}" -echo "RELEASE_NAME: ${HELM_RELEASE_NAME}" -echo "USER: ${USER}" -echo "NAMESPACE: ${NAMESPACE}" -echo "SCRIPT_DIR: ${SCRIPT_DIR}" -echo "TMP_DIR: ${TMP_DIR}" -echo "-----------------------------------------------------------------------------------------------------" -echo "" +function show_env_vars() { + echo "--------------------------Env Setup: fullstack-testing ------------------------------------------------" + echo "CLUSTER_NAME: ${CLUSTER_NAME}" + echo "RELEASE_NAME: ${RELEASE_NAME}" + echo "USER: ${USER}" + echo "NAMESPACE: ${NAMESPACE}" + echo "SCRIPT_DIR: ${SCRIPT_DIR}" + echo "TMP_DIR: ${TMP_DIR}" + echo "-----------------------------------------------------------------------------------------------------" + echo "" +} + +function setup_tmp_dir() { + if [ ! -f "${TMP_DIR}/.env" ]; then \ + echo "Creating .env file from template.env" + cp "${SCRIPT_DIR}/template.env" "${TMP_DIR}/.env" + echo "File list in ${TMP_DIR}" + ls -la "${TMP_DIR}" + fi +} + +function load_env_file() { + setup_tmp_dir + if [ -f "${TMP_DIR}/.env" ]; then \ + echo "Loading .env file: ${TMP_DIR}/.env" + set -a + # shellcheck source=./../temp/.env + source "${TMP_DIR}/.env" + set +a + fi +} + +function setup() { + load_env_file +} + +# ----------------------------- Setup ENV Variables ------------------------------------------------------------- +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" +readonly SCRIPT_DIR +readonly TMP_DIR="${SCRIPT_DIR}/../temp" +load_env_file + +USER="${USER:-changeme}" +CLUSTER_NAME="${CLUSTER_NAME:-fst}" +NAMESPACE="${NAMESPACE:-fst-${USER}}" +RELEASE_NAME="${RELEASE_NAME:-fst}" +NMT_VERSION=v2.0.0-alpha.0 +PLATFORM_VERSION=v0.39.1 + +POD_MONITOR_ROLE="${POD_MONITOR_ROLE:-pod-monitor-role}" +GATEWAY_CLASS_NAME="${GATEWAY_CLASS_NAME:-fst-gateway-class}" + +#NODE_NAMES=(node0 node1 node2 node3) +NODE_NAMES=(node0) + +POD_MONITOR_ROLE="${POD_MONITOR_ROLE:-pod-monitor-role}" +GATEWAY_CLASS_NAME="${GATEWAY_CLASS_NAME:-fst-gateway-class}" + +readonly SETUP_CHART_DIR="${SCRIPT_DIR}/../../charts/fullstack-cluster-setup" +readonly CHART_DIR="${SCRIPT_DIR}/../../charts/hedera-network" + +# telemetry related env variables +readonly COMMON_RESOURCES="${SCRIPT_DIR}/../common-resources" +readonly GATEWAY_API_DIR="${SCRIPT_DIR}/../gateway-api" +readonly TELEMETRY_DIR="${SCRIPT_DIR}/../telemetry" +readonly PROMETHEUS_DIR="${TELEMETRY_DIR}/prometheus" +readonly PROMETHEUS_VERSION=v0.67.1 +readonly PROMETHEUS_OPERATOR_YAML="${PROMETHEUS_DIR}/prometheus-operator.yaml" +readonly PROMETHEUS_YAML="${PROMETHEUS_DIR}/prometheus.yaml" +readonly PROMETHEUS_RBAC_YAML="${PROMETHEUS_DIR}/prometheus-rbac.yaml" +readonly PROMETHEUS_EXAMPLE_APP_YAML="${PROMETHEUS_DIR}/example-app.yaml" + +# docker build related env variables +readonly DOCKERFILE_DIR="${SCRIPT_DIR}/../../docker" +readonly LOCAL_DOCKER_REGISTRY="docker.fst.local" # same as in dev/ci/ci-values.yaml +readonly LOCAL_DOCKER_IMAGE_TAG="local" + +show_env_vars \ No newline at end of file diff --git a/dev/scripts/helper.sh b/dev/scripts/helper.sh index 14fde29f5..4527cacb8 100755 --- a/dev/scripts/helper.sh +++ b/dev/scripts/helper.sh @@ -20,6 +20,7 @@ readonly HGCAPP_DIR="/opt/hgcapp" readonly NMT_DIR="${HGCAPP_DIR}/node-mgmt-tools" readonly HAPI_PATH="${HGCAPP_DIR}/services-hedera/HapiApp2.0" readonly HEDERA_HOME_DIR="/home/hedera" +readonly RELEASE_NAME="${RELEASE_NAME:-fst}" readonly NMT_VERSION="${NMT_VERSION:-v2.0.0-alpha.0}" readonly NMT_RELEASE_URL="https://api.github.com/repos/swirlds/swirlds-docker/releases/tags/${NMT_VERSION}" @@ -310,7 +311,7 @@ function prep_address_book() { local status=$(kubectl get pod "${pod}" -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') while [[ "${attempts}" -lt "${max_attempts}" && "${status}" != "True" ]]; do - kubectl get pod network-node0-0 -o 'jsonpath={..status.conditions[?(@.type=="Ready")]}' + kubectl get pod "${pod}" -o 'jsonpath={..status.conditions[?(@.type=="Ready")]}' echo "" echo "Waiting for the pod to be ready - ${pod}: Attempt# ${attempts}/${max_attempts} ..." diff --git a/dev/scripts/main.sh b/dev/scripts/main.sh index 08047150a..14bf367a3 100644 --- a/dev/scripts/main.sh +++ b/dev/scripts/main.sh @@ -92,7 +92,7 @@ function install_chart() { echo "SCRIPT_NAME: ${node_setup_script}" echo "Additional values: ${CHART_VALUES_FILES}" echo "-----------------------------------------------------------------------------------------------------" - local count=$(helm list -q -n "${NAMESPACE}" | grep -c "${HELM_RELEASE_NAME}") + local count=$(helm list -q -n "${NAMESPACE}" | grep -c "${RELEASE_NAME}") if [[ $count -eq 0 ]]; then if [ "${node_setup_script}" = "nmt-install.sh" ]; then nmt_install @@ -100,61 +100,67 @@ function install_chart() { direct_install fi else - echo "${HELM_RELEASE_NAME} is already installed" + echo "${RELEASE_NAME} is already installed" fi log_time "install_chart" } function uninstall_chart() { - [[ -z "${HELM_RELEASE_NAME}" ]] && echo "ERROR: [uninstall_chart] Helm release name is required" && return 1 + [[ -z "${RELEASE_NAME}" ]] && echo "ERROR: [uninstall_chart] Helm release name is required" && return 1 echo "" - local count=$(helm list -q -n "${NAMESPACE}" | grep -c "${HELM_RELEASE_NAME}") + local count=$(helm list -q -n "${NAMESPACE}" | grep -c "${RELEASE_NAME}") if [[ $count -ne 0 ]]; then - echo "Uninstalling helm chart ${HELM_RELEASE_NAME} in namespace ${NAMESPACE}... " + echo "Uninstalling helm chart ${RELEASE_NAME} in namespace ${NAMESPACE}... " echo "-----------------------------------------------------------------------------------------------------" - helm uninstall -n "${NAMESPACE}" "${HELM_RELEASE_NAME}" + helm uninstall -n "${NAMESPACE}" "${RELEASE_NAME}" sleep 10 - echo "Uninstalled helm chart ${HELM_RELEASE_NAME} in namespace ${NAMESPACE}" + echo "Uninstalled helm chart ${RELEASE_NAME} in namespace ${NAMESPACE}" else - echo "Helm chart '${HELM_RELEASE_NAME}' not found in namespace ${NAMESPACE}. Nothing to uninstall. " + echo "Helm chart '${RELEASE_NAME}' not found in namespace ${NAMESPACE}. Nothing to uninstall. " fi # it is needed for GKE deployment local has_secret - has_secret=$(kubectl get secret | grep -c "sh.helm.release.v1.${HELM_RELEASE_NAME}.*") + has_secret=$(kubectl get secret | grep -c "sh.helm.release.v1.${RELEASE_NAME}.*") if [[ $has_secret ]]; then - kubectl delete secret "sh.helm.release.v1.${HELM_RELEASE_NAME}.v1" || true + kubectl delete secret "sh.helm.release.v1.${RELEASE_NAME}.v1" || true + fi + + local has_postgres_pvc + has_postgres_pvc=$(kubectl get pvc --no-headers -l app.kubernetes.io/component=postgresql,app.kubernetes.io/name=postgres,app.kubernetes.io/instance="${RELEASE_NAME}" | wc -l) + if [[ $has_postgres_pvc ]]; then + kubectl delete pvc -l app.kubernetes.io/component=postgresql,app.kubernetes.io/name=postgres,app.kubernetes.io/instance="${RELEASE_NAME}" fi log_time "uninstall_chart" } function nmt_install() { - [[ -z "${HELM_RELEASE_NAME}" ]] && echo "ERROR: [nmt_install] Helm release name is required" && return 1 + [[ -z "${RELEASE_NAME}" ]] && echo "ERROR: [nmt_install] Helm release name is required" && return 1 [[ -z "${NAMESPACE}" ]] && echo "ERROR: [nmt_install] Namespace name is required" && return 1 if [[ -z "${CHART_VALUES_FILES}" ]]; then - helm install "${HELM_RELEASE_NAME}" -n "${NAMESPACE}" "${CHART_DIR}" --set defaults.root.image.repository=hashgraph/full-stack-testing/ubi8-init-dind + helm install "${RELEASE_NAME}" -n "${NAMESPACE}" "${CHART_DIR}" --set defaults.root.image.repository=hashgraph/full-stack-testing/ubi8-init-dind else - helm install "${HELM_RELEASE_NAME}" -n "${NAMESPACE}" "${CHART_DIR}" -f "${CHART_DIR}/values.yaml" --values "${CHART_VALUES_FILES}" --set defaults.root.image.repository=hashgraph/full-stack-testing/ubi8-init-dind + helm install "${RELEASE_NAME}" -n "${NAMESPACE}" "${CHART_DIR}" -f "${CHART_DIR}/values.yaml" --values "${CHART_VALUES_FILES}" --set defaults.root.image.repository=hashgraph/full-stack-testing/ubi8-init-dind fi } function direct_install() { - [[ -z "${HELM_RELEASE_NAME}" ]] && echo "ERROR: [direct_install] Helm release name is required" && return 1 + [[ -z "${RELEASE_NAME}" ]] && echo "ERROR: [direct_install] Helm release name is required" && return 1 [[ -z "${NAMESPACE}" ]] && echo "ERROR: [direct_install] Namespace name is required" && return 1 if [[ -z "${CHART_VALUES_FILES}" ]]; then - helm install "${HELM_RELEASE_NAME}" -n "${NAMESPACE}" "${CHART_DIR}" + helm install "${RELEASE_NAME}" -n "${NAMESPACE}" "${CHART_DIR}" else - helm install "${HELM_RELEASE_NAME}" -n "${NAMESPACE}" "${CHART_DIR}" -f "${CHART_DIR}/values.yaml" --values "${CHART_VALUES_FILES}" + helm install "${RELEASE_NAME}" -n "${NAMESPACE}" "${CHART_DIR}" -f "${CHART_DIR}/values.yaml" --values "${CHART_VALUES_FILES}" fi } function run_helm_chart_tests() { - [[ -z "${HELM_RELEASE_NAME}" ]] && echo "ERROR: [run_helm_chart_tests] Helm release name is required" && return 1 + [[ -z "${RELEASE_NAME}" ]] && echo "ERROR: [run_helm_chart_tests] Helm release name is required" && return 1 setup_kubectl_context @@ -165,7 +171,7 @@ function run_helm_chart_tests() { echo "Running helm chart tests (takes ~5m, timeout 15m)... " echo "-----------------------------------------------------------------------------------------------------" - helm test "${HELM_RELEASE_NAME}" --filter name="${test_name}" --timeout 15m + helm test "${RELEASE_NAME}" --filter name="${test_name}" --timeout 15m local test_status=$(kubectl get pod "${test_name}" -o jsonpath='{.status.phase}' | xargs) echo "Helm test status: ${test_status}" diff --git a/dev/scripts/template.env b/dev/scripts/template.env index bbeb1109e..2918787ed 100644 --- a/dev/scripts/template.env +++ b/dev/scripts/template.env @@ -1,7 +1,7 @@ USER="${USER:-changeme}" CLUSTER_NAME="${CLUSTER_NAME:-fst}" NAMESPACE="${NAMESPACE:-fst-${USER}}" -HELM_RELEASE_NAME="${RELEASE_NAME:-fst}" +RELEASE_NAME="${RELEASE_NAME:-fst}" NMT_VERSION=v2.0.0-alpha.0 PLATFORM_VERSION=v0.39.1