Skip to content

Commit

Permalink
fix: support deploying the chart with custom release name (#412)
Browse files Browse the repository at this point in the history
Signed-off-by: Lenin Mehedy <lenin.mehedy@swirldslabs.com>
  • Loading branch information
leninmehedy authored Oct 18, 2023
1 parent 31f615c commit 619b42b
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 82 deletions.
2 changes: 2 additions & 0 deletions charts/hedera-network/templates/tests/test-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: RELEASE_NAME
value: {{ $.Release.Name }}
command:
- "/bin/bash"
- "-c"
Expand Down
2 changes: 2 additions & 0 deletions charts/hedera-network/tests/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ 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}"
[ ! -d "${LOG_DIR}" ] && mkdir "${LOG_DIR}"

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}"
Expand Down
1 change: 1 addition & 0 deletions charts/hedera-network/tests/env.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
USER="${USER:-changeme}"
NAMESPACE="${NAMESPACE:-fst-${USER}}"
RELEASE_NAME="${RELEASE_NAME:-fst}"

TOTAL_NODES=3

Expand Down
2 changes: 1 addition & 1 deletion charts/hedera-network/tests/helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
Expand Down
140 changes: 79 additions & 61 deletions dev/scripts/env.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -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
3 changes: 2 additions & 1 deletion dev/scripts/helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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} ..."
Expand Down
42 changes: 24 additions & 18 deletions dev/scripts/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,69 +92,75 @@ 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
else
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

Expand All @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion dev/scripts/template.env
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 619b42b

Please sign in to comment.