From 03206eb14690c8cef079531c971ecac0aac3f59a Mon Sep 17 00:00:00 2001 From: Andrei Kvapil Date: Fri, 18 Oct 2024 10:43:05 +0200 Subject: [PATCH] Refactor e2e tests for applications --- hack/e2e.applications.sh | 11 ++--------- hack/modules/create_git_repo.sh | 33 -------------------------------- hack/modules/install_all_apps.sh | 14 +++++++------- hack/modules/install_chart.sh | 10 +++++----- hack/modules/install_tenant.sh | 8 ++++---- hack/pre-checks.sh | 2 +- 6 files changed, 19 insertions(+), 59 deletions(-) delete mode 100644 hack/modules/create_git_repo.sh diff --git a/hack/e2e.applications.sh b/hack/e2e.applications.sh index d5f7dde3a..fae502c94 100755 --- a/hack/e2e.applications.sh +++ b/hack/e2e.applications.sh @@ -5,17 +5,11 @@ done ROOT_NS="tenant-root" TEST_TENANT="tenant-e2e" -FLUX_NS="cozy-fluxcd" -GITREPO_NAME="e2e-repo" -BRANCH="main" - function test() { - create_git_repo $GITREPO_NAME $FLUX_NS $BRANCH - - install_tenant $TEST_TENANT $ROOT_NS $GITREPO_NAME $FLUX_NS + install_tenant $TEST_TENANT $ROOT_NS check_helmrelease_status $TEST_TENANT $ROOT_NS - install_all_apps "../packages/apps" "$TEST_TENANT" $GITREPO_NAME $FLUX_NS + install_all_apps "../packages/apps" "$TEST_TENANT" cozystack-apps cozy-public if true; then echo -e "${GREEN}All tests passed!${RESET}" @@ -27,7 +21,6 @@ function test() { } function clean() { - kubectl delete gitrepository.source.toolkit.fluxcd.io $GITREPO_NAME -n $FLUX_NS kubectl delete helmrelease.helm.toolkit.fluxcd.io $TEST_TENANT -n $ROOT_NS if true; then echo -e "${GREEN}Cleanup successful!${RESET}" diff --git a/hack/modules/create_git_repo.sh b/hack/modules/create_git_repo.sh deleted file mode 100644 index 7715cd03b..000000000 --- a/hack/modules/create_git_repo.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -function create_git_repo() { - local repo_name="$1" - local namespace="$2" - local branch="$3" - - if [[ -z "$repo_name" || -z "$namespace" || -z "$branch" ]]; then - echo "Usage: create_git_repo " - return 1 - fi - - local gitrepo_file=$(mktemp /tmp/GitRepository.XXXXXX.yaml) - { - echo "apiVersion: source.toolkit.fluxcd.io/v1" - echo "kind: GitRepository" - echo "metadata:" - echo " name: \"$repo_name\"" - echo " namespace: \"$namespace\"" - echo "spec:" - echo " interval: 1m" - echo " url: https://github.com/aenix-io/cozystack" - echo " ref:" - echo " branch: \"$branch\"" - echo " ignore: |" - echo " !/packages/apps/ " - - } > "$gitrepo_file" - - kubectl apply -f "$gitrepo_file" - - rm -f "$gitrepo_file" -} diff --git a/hack/modules/install_all_apps.sh b/hack/modules/install_all_apps.sh index 9faf35e27..a697fd092 100755 --- a/hack/modules/install_all_apps.sh +++ b/hack/modules/install_all_apps.sh @@ -36,8 +36,8 @@ function is_chart_ignored() { function install_all_apps() { local charts_dir="$1" local namespace="$2" - local gitrepo_name="$3" - local flux_ns="$4" + local repo_name="$3" + local repo_ns="$4" local ignore_file="./modules/ignored_charts" local ignored_charts @@ -53,12 +53,12 @@ function install_all_apps() { continue fi - chart_name="$chart_name-e2e" - echo "Installing chart: $chart_name" - install_helmrelease "$chart_name" "$namespace" "$chart_path" "$gitrepo_name" "$flux_ns" + release_name="$chart_name-e2e" + echo "Installing release: $release_name" + install_helmrelease "$release_name" "$namespace" "$chart_name" "$repo_name" "$repo_ns" - echo "Checking status for HelmRelease: $chart_name" - check_helmrelease_status "$chart_name" "$namespace" + echo "Checking status for HelmRelease: $release_name" + check_helmrelease_status "$release_name" "$namespace" else echo "$chart_path is not a directory. Skipping." fi diff --git a/hack/modules/install_chart.sh b/hack/modules/install_chart.sh index 7fe53be17..5e45ba408 100755 --- a/hack/modules/install_chart.sh +++ b/hack/modules/install_chart.sh @@ -6,8 +6,8 @@ function install_helmrelease() { local release_name="$1" local namespace="$2" local chart_path="$3" - local gitrepo_name="$4" - local flux_ns="$5" + local repo_name="$4" + local repo_ns="$5" local values_file="$6" if [[ -z "$release_name" ]]; then @@ -41,9 +41,9 @@ function install_helmrelease() { echo " chart: \"$chart_path\"" echo " reconcileStrategy: Revision" echo " sourceRef:" - echo " kind: GitRepository" - echo " name: \"$gitrepo_name\"" - echo " namespace: \"$flux_ns\"" + echo " kind: HelmRepository" + echo " name: \"$repo_name\"" + echo " namespace: \"$repo_ns\"" echo " version: '*'" echo " interval: 1m0s" echo " timeout: 5m0s" diff --git a/hack/modules/install_tenant.sh b/hack/modules/install_tenant.sh index ed4c3291c..f1cab14d6 100755 --- a/hack/modules/install_tenant.sh +++ b/hack/modules/install_tenant.sh @@ -3,9 +3,9 @@ function install_tenant (){ local release_name="$1" local namespace="$2" - local gitrepo_name="$3" - local flux_ns="$4" - local values_file="${5:-tenant.yaml}" + local values_file="${3:-tenant.yaml}" + local repo_name="cozystack-apps" + local repo_ns="cozy-public" - install_helmrelease "$release_name" "$namespace" "../../packages/apps/tenant" "$gitrepo_name" "$flux_ns" "$values_file" + install_helmrelease "$release_name" "$namespace" "tenant" "$repo_name" "$repo_ns" "$values_file" } diff --git a/hack/pre-checks.sh b/hack/pre-checks.sh index be0e2a675..d8fc94e0e 100755 --- a/hack/pre-checks.sh +++ b/hack/pre-checks.sh @@ -5,7 +5,7 @@ RED='\033[31m' RESET='\033[0m' check-yq-version() { - current_version=$(yq -V | grep -oP 'v[0-9]+\.[0-9]+\.[0-9]+') + current_version=$(yq -V | awk '$(NF-1) == "version" {print $NF}') if [ -z "$current_version" ]; then echo "yq is not installed or version cannot be determined." exit 1