diff --git a/hack/e2e.application.sh b/hack/e2e.application.sh index e908615c1..792630dec 100755 --- a/hack/e2e.application.sh +++ b/hack/e2e.application.sh @@ -9,15 +9,29 @@ YELLOW='\033[0;33m' ROOT_NS="tenant-root" TEST_TENANT="tenant-e2e" -function clean() { - kubectl delete helmrelease.helm.toolkit.fluxcd.io $TEST_TENANT -n $ROOT_NS - if true; then - echo -e "${GREEN}Cleanup successful!${RESET}" +values_base_path="/hack/testdata/" +checks_base_path="/hack/testdata/" + +function delete_hr() { + local release_name="$1" + local namespace="$2" + + if [[ -z "$release_name" ]]; then + echo -e "${RED}Error: Release name is required.${RESET}" + exit 1 + fi + + if [[ -z "$namespace" ]]; then + echo -e "${RED}Error: Namespace name is required.${RESET}" + exit 1 + fi + + if [[ "$release_name" == "tenant-e2e" ]]; then + echo -e "${YELLOW}Skipping deletion for release tenant-e2e.${RESET}" return 0 - else - echo -e "${RED}Cleanup failed!${RESET}" - return 1 fi + + kubectl delete helmrelease $release_name -n $namespace } function install_helmrelease() { @@ -43,6 +57,11 @@ function install_helmrelease() { exit 1 fi + if [[ -n "$values_file" && -f "$values_file" ]]; then + local values_section + values_section=$(echo " values:" && sed 's/^/ /' "$values_file") + fi + local helmrelease_file=$(mktemp /tmp/HelmRelease.XXXXXX.yaml) { echo "apiVersion: helm.toolkit.fluxcd.io/v2" @@ -64,11 +83,7 @@ function install_helmrelease() { echo " version: '*'" echo " interval: 1m0s" echo " timeout: 5m0s" - - if [[ -n "$values_file" && -f "$values_file" ]]; then - echo " values:" - cat "$values_file" | sed 's/^/ /' - fi + [[ -n "$values_section" ]] && echo "$values_section" } > "$helmrelease_file" kubectl apply -f "$helmrelease_file" @@ -79,26 +94,38 @@ function install_helmrelease() { function install_tenant (){ local release_name="$1" local namespace="$2" - local values_file="${3:-tenant.yaml}" + local values_file="${values_base_path}tenant/values.yaml" local repo_name="cozystack-apps" local repo_ns="cozy-public" - install_helmrelease "$release_name" "$namespace" "tenant" "$repo_name" "$repo_ns" "$values_file" } +function make_extra_checks(){ + local checks_file="$1" + echo "after exec make $checks_file" + if [[ -n "$checks_file" && -f "$checks_file" ]]; then + echo -e "${YELLOW}Start extra checks with file: ${checks_file}${RESET}" + + fi +} + function check_helmrelease_status() { local release_name="$1" local namespace="$2" + local checks_file="$3" local timeout=300 # Timeout in seconds local interval=5 # Interval between checks in seconds local elapsed=0 + while [[ $elapsed -lt $timeout ]]; do local status_output status_output=$(kubectl get helmrelease "$release_name" -n "$namespace" -o json | jq -r '.status.conditions[-1].reason') - if [[ "$status_output" == "InstallSucceeded" ]]; then + if [[ "$status_output" == "InstallSucceeded" || "$status_output" == "UpgradeSucceeded" ]]; then echo -e "${GREEN}Helm release '$release_name' is ready.${RESET}" + make_extra_checks "$checks_file" + delete_hr $release_name $namespace return 0 elif [[ "$status_output" == "InstallFailed" ]]; then echo -e "${RED}Helm release '$release_name': InstallFailed${RESET}" @@ -122,14 +149,17 @@ if [ -z "$chart_name" ]; then exit 1 fi -echo "Running tests for chart: $chart_name" -install_tenant $TEST_TENANT $ROOT_NS -check_helmrelease_status $TEST_TENANT $ROOT_NS +checks_file="${checks_base_path}${chart_name}/check.sh" repo_name="cozystack-apps" repo_ns="cozy-public" - release_name="$chart_name-e2e" -install_helmrelease "$release_name" "$TEST_TENANT" "$chart_name" "$repo_name" "$repo_ns" +values_file="${values_base_path}${chart_name}/values.yaml" + +install_tenant $TEST_TENANT $ROOT_NS +check_helmrelease_status $TEST_TENANT $ROOT_NS "${checks_base_path}tenant/check.sh" + +echo -e "${YELLOW}Running tests for chart: $chart_name${RESET}" -check_helmrelease_status "$release_name" "$TEST_TENANT" +install_helmrelease $release_name $TEST_TENANT $chart_name $repo_name $repo_ns $values_file +check_helmrelease_status $release_name $TEST_TENANT $checks_file diff --git a/hack/testdata/kubernetes/check.sh b/hack/testdata/kubernetes/check.sh new file mode 100644 index 000000000..61c7ebffa --- /dev/null +++ b/hack/testdata/kubernetes/check.sh @@ -0,0 +1 @@ +return 0 diff --git a/hack/testdata/kubernetes/values.yaml b/hack/testdata/kubernetes/values.yaml new file mode 100644 index 000000000..71e290c53 --- /dev/null +++ b/hack/testdata/kubernetes/values.yaml @@ -0,0 +1,62 @@ +## @section Common parameters + +## @param host The hostname used to access the Kubernetes cluster externally (defaults to using the cluster name as a subdomain for the tenant host). +## @param controlPlane.replicas Number of replicas for Kubernetes contorl-plane components +## @param storageClass StorageClass used to store user data +## +host: "" +controlPlane: + replicas: 2 +storageClass: replicated + +## @param nodeGroups [object] nodeGroups configuration +## +nodeGroups: + md0: + minReplicas: 0 + maxReplicas: 10 + instanceType: "u1.medium" + ephemeralStorage: 20Gi + roles: + - ingress-nginx + + resources: + cpu: "" + memory: "" + +## @section Cluster Addons +## +addons: + + ## Cert-manager: automatically creates and manages SSL/TLS certificate + ## + certManager: + ## @param addons.certManager.enabled Enables the cert-manager + ## @param addons.certManager.valuesOverride Custom values to override + enabled: true + valuesOverride: {} + + ## Ingress-NGINX Controller + ## + ingressNginx: + ## @param addons.ingressNginx.enabled Enable Ingress-NGINX controller (expect nodes with 'ingress-nginx' role) + ## @param addons.ingressNginx.valuesOverride Custom values to override + ## + enabled: true + ## @param addons.ingressNginx.hosts List of domain names that should be passed through to the cluster by upper cluster + ## e.g: + ## hosts: + ## - example.org + ## - foo.example.net + ## + hosts: [] + valuesOverride: {} + + ## Flux CD + ## + fluxcd: + ## @param addons.fluxcd.enabled Enables Flux CD + ## @param addons.fluxcd.valuesOverride Custom values to override + ## + enabled: true + valuesOverride: {} diff --git a/hack/testdata/nats/check.sh b/hack/testdata/nats/check.sh new file mode 100644 index 000000000..61c7ebffa --- /dev/null +++ b/hack/testdata/nats/check.sh @@ -0,0 +1 @@ +return 0 diff --git a/hack/testdata/nats/values.yaml b/hack/testdata/nats/values.yaml new file mode 100644 index 000000000..7044641c0 --- /dev/null +++ b/hack/testdata/nats/values.yaml @@ -0,0 +1,10 @@ + +## @section Common parameters + +## @param external Enable external access from outside the cluster +## @param replicas Persistent Volume size for NATS +## @param storageClass StorageClass used to store the data +## +external: false +replicas: 2 +storageClass: "" diff --git a/hack/testdata/tenant/check.sh b/hack/testdata/tenant/check.sh new file mode 100644 index 000000000..61c7ebffa --- /dev/null +++ b/hack/testdata/tenant/check.sh @@ -0,0 +1 @@ +return 0 diff --git a/hack/values/tenant.yaml b/hack/testdata/tenant/values.yaml similarity index 100% rename from hack/values/tenant.yaml rename to hack/testdata/tenant/values.yaml diff --git a/packages/core/testing/Makefile b/packages/core/testing/Makefile index 728b7de8f..ae8a2f2ee 100755 --- a/packages/core/testing/Makefile +++ b/packages/core/testing/Makefile @@ -42,7 +42,6 @@ test: wait-for-sandbox copy-hack-dir ## Run the end-to-end tests in existing san test-applications: wait-for-sandbox copy-hack-dir ## Run the end-to-end tests in existing sandbox for applications. for app in $(TESTING_APPS); do \ - echo "Running tests for $${app}"; \ kubectl exec -ti -n cozy-e2e-tests deploy/cozystack-e2e-sandbox -- bash -c "/hack/e2e.application.sh $${app}"; \ done kubectl exec -ti -n cozy-e2e-tests deploy/cozystack-e2e-sandbox -- bash -c "kubectl get hr -A | grep -v 'True'" diff --git a/packages/core/testing/values.yaml b/packages/core/testing/values.yaml index ab42bfa75..3380c8968 100755 --- a/packages/core/testing/values.yaml +++ b/packages/core/testing/values.yaml @@ -1,2 +1,2 @@ e2e: - image: ghcr.io/aenix-io/cozystack/e2e-sandbox:latest@sha256:1a26a511b9e269bcb607e2d80f878d7c2d993b7a2a7a3a2a1042470c8c56b061 + image: kklinch0/e2e-sandbox:latest@sha256:179829eb70914207db92c5ad959bbb7c3f060a10b30cc5eb1dff9b999ab19f77