diff --git a/deploy-scripts/.env.example b/deploy-scripts/.env.example index 6953fbd..05426ba 100644 --- a/deploy-scripts/.env.example +++ b/deploy-scripts/.env.example @@ -6,8 +6,10 @@ # cp .env.example .env # Kubernetes Configuration -export NAMESPACE="${NAMESPACE:-hyperfleet-e2e}" - +# NAMESPACE must be unique to prevent GCP Pub/Sub topic/subscription collisions. +# GCP resources are named using the namespace (e.g., ${NAMESPACE}-clusters), +# so multiple users sharing the same namespace will interfere with each other's tests. +export NAMESPACE="${NAMESPACE:-hyperfleet-e2e-$(echo ${USER:-default} | tr '[:upper:]' '[:lower:]')}" # Provider Configuration export GCP_PROJECT_ID="${GCP_PROJECT_ID:-hcm-hyperfleet}" diff --git a/deploy-scripts/README.md b/deploy-scripts/README.md index 5a537c7..8719471 100644 --- a/deploy-scripts/README.md +++ b/deploy-scripts/README.md @@ -39,14 +39,14 @@ Ensure you have: Install all components with default settings: ```bash -./deploy-scripts/deploy-clm.sh --action install --namespace hyperfleet-e2e +./deploy-scripts/deploy-clm.sh --action install --namespace ``` Install with custom image tags: ```bash ./deploy-scripts/deploy-clm.sh --action install \ - --namespace my-test-env \ + --namespace \ --api-image-tag v1.2.0 \ --sentinel-image-tag v1.2.0 \ --adapter-image-tag v1.2.0 @@ -55,7 +55,7 @@ Install with custom image tags: Uninstall all components: ```bash -./deploy-scripts/deploy-clm.sh --action uninstall --namespace hyperfleet-e2e +./deploy-scripts/deploy-clm.sh --action uninstall --namespace hyperfleet-e2e-$USER ``` ### Option 2: Using .env File (Recommended for Complex Configurations) @@ -74,7 +74,7 @@ For easier management of deployment parameters, use a `.env` file: ``` Key parameters you can configure: - - `NAMESPACE` - Kubernetes namespace (default: `hyperfleet-e2e`) + - `NAMESPACE` - Kubernetes namespace (default: `hyperfleet-e2e-$USER`) - `IMAGE_REGISTRY` - Container image registry - `API_IMAGE_TAG`, `SENTINEL_IMAGE_TAG`, `ADAPTER_IMAGE_TAG` - Image tags - `GCP_PROJECT_ID` - Google Cloud Project ID for Pub/Sub @@ -84,7 +84,7 @@ For easier management of deployment parameters, use a `.env` file: 3. **Run the deployment:** ```bash - ./deploy-clm.sh --action install + ./deploy-clm.sh --action install --namespace hyperfleet-e2e-$USER ``` **Configuration Priority:** @@ -114,7 +114,7 @@ For basic usage, see [Quick Start](#quick-start) section above. | Flag | Description | Default | |------|-------------|---------| -| `--namespace ` | Kubernetes namespace for deployment | `hyperfleet-e2e` | +| `--namespace ` | Kubernetes namespace for deployment | `hyperfleet-e2e-$USER` | | `--dry-run` | Print commands without executing | `false` | | `--verbose` | Enable verbose logging | `false` | | `--help` | Show help message | - | @@ -151,7 +151,7 @@ For basic usage, see [Quick Start](#quick-start) section above. #### 1. Install with Default Settings ```bash -./deploy-scripts/deploy-clm.sh --action install --namespace hyperfleet-e2e +./deploy-scripts/deploy-clm.sh --action install --namespace hyperfleet-e2e-$USER ``` This installs all three components (API, Sentinel, Adapter) with default configurations. @@ -160,7 +160,7 @@ This installs all three components (API, Sentinel, Adapter) with default configu ```bash ./deploy-scripts/deploy-clm.sh --action install \ - --namespace test-env \ + --namespace \ --skip-adapter ``` @@ -168,7 +168,7 @@ This installs all three components (API, Sentinel, Adapter) with default configu ```bash ./deploy-scripts/deploy-clm.sh --action install \ - --namespace staging \ + --namespace \ --api-image-tag v1.2.0 \ --sentinel-image-tag v1.2.0 \ --adapter-image-tag v1.2.0 @@ -178,7 +178,7 @@ This installs all three components (API, Sentinel, Adapter) with default configu ```bash ./deploy-scripts/deploy-clm.sh --action install \ - --namespace dev-test \ + --namespace \ --api-image-repo myregistry.io/hyperfleet-api \ --api-image-tag pr-123 ``` @@ -187,7 +187,7 @@ This installs all three components (API, Sentinel, Adapter) with default configu ```bash ./deploy-scripts/deploy-clm.sh --action install \ - --namespace test \ + --namespace \ --dry-run \ --verbose ``` @@ -199,7 +199,7 @@ This simulates the installation without making any actual changes. #### 1. Uninstall All Components ```bash -./deploy-scripts/deploy-clm.sh --action uninstall --namespace hyperfleet-e2e +./deploy-scripts/deploy-clm.sh --action uninstall --namespace ``` This removes all Helm releases. @@ -208,7 +208,7 @@ This removes all Helm releases. ```bash ./deploy-scripts/deploy-clm.sh --action uninstall \ - --namespace test-env \ + --namespace \ --dry-run \ --verbose ``` @@ -217,7 +217,7 @@ This removes all Helm releases. ```bash ./deploy-scripts/deploy-clm.sh --action uninstall \ - --namespace test-env \ + --namespace \ --skip-api \ --skip-sentinel ``` @@ -251,15 +251,16 @@ The script leverages Helm's built-in namespace management: - **Installation**: Namespace is automatically created by Helm using the `--create-namespace` flag - **Uninstallation**: Resources are removed by `helm uninstall`, but the namespace is **not deleted** +- **Uniqueness**: Each deployment requires a unique namespace to prevent GCP Pub/Sub resource collisions. If you want to completely remove the namespace after uninstallation: ```bash # Uninstall components -./deploy-scripts/deploy-clm.sh --action uninstall --namespace test-env +./deploy-scripts/deploy-clm.sh --action uninstall --namespace # Manually delete namespace if desired -kubectl delete namespace test-env +kubectl delete namespace ``` This design allows you to: @@ -275,7 +276,7 @@ Use `--dry-run --verbose` flags to see what the script would do without making c ```bash ./deploy-scripts/deploy-clm.sh --action install \ - --namespace test \ + --namespace \ --dry-run \ --verbose ``` @@ -291,7 +292,7 @@ kubectl logs -n View script execution with bash trace: ```bash -bash -x deploy-scripts/deploy-clm.sh --action install --namespace test +bash -x deploy-scripts/deploy-clm.sh --action install --namespace ``` ## Integration with E2E Tests @@ -302,10 +303,10 @@ Before running E2E tests, deploy the CLM components: ```bash # Deploy test environment -./deploy-scripts/deploy-clm.sh --action install --namespace e2e-test +./deploy-scripts/deploy-clm.sh --action install --namespace # Configure E2E test API URL -EXTERNAL_IP=$(kubectl get svc hyperfleet-api -n $NAMESPACE_NAME -o jsonpath='{.status.loadBalancer.ingress[0].ip}') +EXTERNAL_IP=$(kubectl get svc hyperfleet-api -n $NAMESPACE -o jsonpath='{.status.loadBalancer.ingress[0].ip}') export HYPERFLEET_API_URL="http://${EXTERNAL_IP}:8000" # Run E2E tests @@ -317,7 +318,7 @@ export HYPERFLEET_API_URL="http://${EXTERNAL_IP}:8000" After tests complete: ```bash -./deploy-scripts/deploy-clm.sh --action uninstall --namespace e2e-test +./deploy-scripts/deploy-clm.sh --action uninstall --namespace ``` ## Script Output diff --git a/deploy-scripts/deploy-clm.sh b/deploy-scripts/deploy-clm.sh index dc4853e..e4d9c95 100755 --- a/deploy-scripts/deploy-clm.sh +++ b/deploy-scripts/deploy-clm.sh @@ -6,8 +6,11 @@ # (API, Sentinel, and Adapters) using Helm for E2E testing environments. # # Usage: -# ./deploy-clm.sh --action install --namespace hyperfleet-e2e -# ./deploy-clm.sh --action uninstall --namespace hyperfleet-e2e --dry-run +# ./deploy-clm.sh --action install --namespace +# ./deploy-clm.sh --action uninstall --namespace --dry-run +# +# Set NAMESPACE in .env file or use --namespace flag. +# Each deployment requires a unique namespace to prevent GCP Pub/Sub resource collisions. set -euo pipefail @@ -38,7 +41,7 @@ fi # ============================================================================ ACTION="${ACTION:-}" -NAMESPACE="${NAMESPACE:-hyperfleet-e2e}" +NAMESPACE="${NAMESPACE:-}" DRY_RUN="${DRY_RUN:-false}" VERBOSE="${VERBOSE:-false}" @@ -124,13 +127,16 @@ Automated deployment script for HyperFleet CLM components (API, Sentinel, Adapte CONFIGURATION: This script loads configuration from ${SCRIPT_DIR}/.env file. - You can override any .env value using command-line flags. + Command-line flags override .env values. + + NAMESPACE should be unique to prevent GCP Pub/Sub collisions. + Recommended: set NAMESPACE=hyperfleet-e2e-\$USER in .env file. REQUIRED FLAGS: --action Action to perform: install or uninstall OPTIONAL FLAGS: - --namespace Kubernetes namespace (default: hyperfleet-e2e) + --namespace Kubernetes namespace (default from .env: ${NAMESPACE}) # Component Selection --skip-api Skip API installation @@ -187,38 +193,37 @@ ENVIRONMENT VARIABLES: - API_ADAPTERS_NODEPOOL Adapters for API nodepool config (set per test case) EXAMPLES: - # Install all components with default settings - ${0##*/} --action install --namespace hyperfleet-e2e + # Install with .env defaults + ${0##*/} --action install + + # Install with explicit namespace + ${0##*/} --action install --namespace # Install with custom image tags ${0##*/} --action install \\ - --namespace test-env \\ + --namespace \\ --api-image-tag v1.0.0 \\ --sentinel-image-tag v1.0.0 \\ --adapter-image-tag v1.0.0 # Install only API and Sentinel - ${0##*/} --action install --skip-adapter + ${0##*/} --action install --namespace --skip-adapter - # Dry-run uninstallation - ${0##*/} --action uninstall --namespace hyperfleet-e2e --dry-run --verbose + # Dry-run to preview actions + ${0##*/} --action uninstall --namespace --dry-run --verbose - # Delete Kubernetes resources (Helm releases + namespace) - ${0##*/} --action uninstall --namespace hyperfleet-e2e --delete-k8s-resources + # Delete Kubernetes resources + ${0##*/} --action uninstall --namespace --delete-k8s-resources - # Delete GCP Pub/Sub resources (topics and subscriptions) - ${0##*/} --action uninstall --namespace hyperfleet-e2e --delete-cloud-resources + # Delete GCP Pub/Sub resources + ${0##*/} --action uninstall --namespace --delete-cloud-resources - # Complete cleanup: delete everything (k8s + cloud resources) - ${0##*/} --action uninstall --namespace hyperfleet-e2e --all + # Complete cleanup: delete everything + ${0##*/} --action uninstall --namespace --all - # Or explicitly specify both - ${0##*/} --action uninstall --namespace hyperfleet-e2e \\ - --delete-k8s-resources \\ - --delete-cloud-resources - - # Install with custom image repositories + # Install with custom image repository ${0##*/} --action install \\ + --namespace \\ --api-image-repo myregistry.io/hyperfleet-api \\ --api-image-tag dev-123 @@ -352,6 +357,19 @@ parse_arguments() { exit 1 fi + # Validate NAMESPACE variable is set + if [[ -z "${NAMESPACE}" ]]; then + log_error "Missing required flag: --namespace or env variable NAMESPACE" + echo + print_usage + exit 1 + fi + + if (( ${#NAMESPACE} > 63 )) || [[ ! "${NAMESPACE}" =~ ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$ ]]; then + log_error "Invalid namespace: '${NAMESPACE}'. Must match DNS-1123 label format and be <= 63 chars." + exit 1 + fi + if [[ "${ACTION}" != "install" && "${ACTION}" != "uninstall" ]]; then log_error "Invalid action: ${ACTION}. Must be 'install' or 'uninstall'" exit 1