-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
145 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
#!/bin/bash | ||
|
||
RED='\033[0;31m' | ||
GREEN='\033[0;32m' | ||
RESET='\033[0m' | ||
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}" | ||
return 0 | ||
else | ||
echo -e "${RED}Cleanup failed!${RESET}" | ||
return 1 | ||
fi | ||
} | ||
|
||
function install_helmrelease() { | ||
local release_name="$1" | ||
local namespace="$2" | ||
local chart_path="$3" | ||
local repo_name="$4" | ||
local repo_ns="$5" | ||
local values_file="$6" | ||
|
||
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 [[ -z "$chart_path" ]]; then | ||
echo -e "${RED}Error: Chart path name is required.${RESET}" | ||
exit 1 | ||
fi | ||
|
||
local helmrelease_file=$(mktemp /tmp/HelmRelease.XXXXXX.yaml) | ||
{ | ||
echo "apiVersion: helm.toolkit.fluxcd.io/v2" | ||
echo "kind: HelmRelease" | ||
echo "metadata:" | ||
echo " labels:" | ||
echo " cozystack.io/ui: \"true\"" | ||
echo " name: \"$release_name\"" | ||
echo " namespace: \"$namespace\"" | ||
echo "spec:" | ||
echo " chart:" | ||
echo " spec:" | ||
echo " chart: \"$chart_path\"" | ||
echo " reconcileStrategy: Revision" | ||
echo " sourceRef:" | ||
echo " kind: HelmRepository" | ||
echo " name: \"$repo_name\"" | ||
echo " namespace: \"$repo_ns\"" | ||
echo " version: '*'" | ||
echo " interval: 1m0s" | ||
echo " timeout: 5m0s" | ||
|
||
if [[ -n "$values_file" && -f "$values_file" ]]; then | ||
echo " values:" | ||
cat "$values_file" | sed 's/^/ /' | ||
fi | ||
} > "$helmrelease_file" | ||
|
||
kubectl apply -f "$helmrelease_file" | ||
|
||
rm -f "$helmrelease_file" | ||
} | ||
|
||
function install_tenant (){ | ||
local release_name="$1" | ||
local namespace="$2" | ||
local values_file="${3:-tenant.yaml}" | ||
local repo_name="cozystack-apps" | ||
local repo_ns="cozy-public" | ||
|
||
install_helmrelease "$release_name" "$namespace" "tenant" "$repo_name" "$repo_ns" "$values_file" | ||
} | ||
|
||
function check_helmrelease_status() { | ||
local release_name="$1" | ||
local namespace="$2" | ||
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 | ||
echo -e "${GREEN}Helm release '$release_name' is ready.${RESET}" | ||
return 0 | ||
elif [[ "$status_output" == "InstallFailed" ]]; then | ||
echo -e "${RED}Helm release '$release_name': InstallFailed${RESET}" | ||
exit 1 | ||
else | ||
echo -e "${YELLOW}Helm release '$release_name' is not ready. Current status: $status_output${RESET}" | ||
fi | ||
|
||
sleep "$interval" | ||
elapsed=$((elapsed + interval)) | ||
done | ||
|
||
echo -e "${RED}Timeout reached. Helm release '$release_name' is still not ready after $timeout seconds.${RESET}" | ||
exit 1 | ||
} | ||
|
||
chart_name="$1" | ||
|
||
if [ -z "$chart_name" ]; then | ||
echo -e "${RED}No chart name provided. Exiting...${RESET}" | ||
exit 1 | ||
fi | ||
|
||
echo "Running tests for chart: $chart_name" | ||
install_tenant $TEST_TENANT $ROOT_NS | ||
check_helmrelease_status $TEST_TENANT $ROOT_NS | ||
|
||
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" | ||
|
||
check_helmrelease_status "$release_name" "$TEST_TENANT" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters