|
| 1 | +# Operator Integration Tests |
| 2 | + |
| 3 | +.PHONY: test test-verbose test-tags deps clean help run-local |
| 4 | + |
| 5 | +# Default test timeout |
| 6 | +TIMEOUT ?= 45m |
| 7 | + |
| 8 | +# Default tag filter (empty = all) |
| 9 | +TAGS ?= |
| 10 | + |
| 11 | +# Project root (2 levels up from kubernetes/it) |
| 12 | +PROJECT_ROOT := $(CURDIR)/../.. |
| 13 | + |
| 14 | +# Docker Hub username - change this to your Docker Hub username |
| 15 | +DOCKER_HUB_USER ?= tharsanan |
| 16 | +IMAGE_TAG ?= test |
| 17 | + |
| 18 | +# Full registry path for images |
| 19 | +DOCKER_REGISTRY := docker.io/$(DOCKER_HUB_USER) |
| 20 | + |
| 21 | +help: |
| 22 | + @echo "Operator Integration Test Suite" |
| 23 | + @echo "" |
| 24 | + @echo "Usage:" |
| 25 | + @echo " make deps - Download Go dependencies" |
| 26 | + @echo " make test - Run all integration tests (assumes setup is done)" |
| 27 | + @echo " make test-verbose - Run tests with verbose output" |
| 28 | + @echo " make test-tags - Run tests with specific tags (TAGS=@gateway-lifecycle)" |
| 29 | + @echo " make run-local - Full local test run (builds images, pushes to Docker Hub, runs tests)" |
| 30 | + @echo " make run-local TAGS=@tag - Run specific tags locally" |
| 31 | + @echo " make run-local-quick - Quick run (skip building, for iterating on tests)" |
| 32 | + @echo " make clean - Clean test artifacts" |
| 33 | + @echo "" |
| 34 | + @echo "Configuration:" |
| 35 | + @echo " DOCKER_HUB_USER=$(DOCKER_HUB_USER) - Set your Docker Hub username" |
| 36 | + @echo " IMAGE_TAG=$(IMAGE_TAG) - Image tag to use" |
| 37 | + @echo "" |
| 38 | + @echo "Examples:" |
| 39 | + @echo " make run-local DOCKER_HUB_USER=myuser" |
| 40 | + @echo " make run-local TAGS=@gateway-lifecycle" |
| 41 | + @echo "" |
| 42 | + @echo "Available tags:" |
| 43 | + @echo " @gateway-lifecycle - Gateway CR create/delete" |
| 44 | + @echo " @restapi-lifecycle - RestApi CR create/update/delete" |
| 45 | + @echo " @jwt-authentication - JWT policy tests" |
| 46 | + @echo " @multi-namespace - Multi-namespace API tests" |
| 47 | + @echo " @scoped-mode - Scoped operator mode tests" |
| 48 | + @echo " @full-lifecycle - Complete operator lifecycle test" |
| 49 | + |
| 50 | +deps: |
| 51 | + go mod tidy |
| 52 | + go mod download |
| 53 | + |
| 54 | +test: deps |
| 55 | + go test -v -timeout $(TIMEOUT) ./... |
| 56 | + |
| 57 | +test-verbose: deps |
| 58 | + go test -v -timeout $(TIMEOUT) ./... 2>&1 | tee test-output.log |
| 59 | + |
| 60 | +test-tags: deps |
| 61 | +ifdef TAGS |
| 62 | + go test -v -timeout $(TIMEOUT) ./... -godog.tags="$(TAGS)" |
| 63 | +else |
| 64 | + @echo "Please specify TAGS, e.g., make test-tags TAGS=@gateway-lifecycle" |
| 65 | + @exit 1 |
| 66 | +endif |
| 67 | + |
| 68 | +# Run a specific feature file |
| 69 | +test-feature: deps |
| 70 | +ifdef FEATURE |
| 71 | + go test -v -timeout $(TIMEOUT) ./... -godog.paths="features/$(FEATURE)" |
| 72 | +else |
| 73 | + @echo "Please specify FEATURE, e.g., make test-feature FEATURE=gateway_lifecycle.feature" |
| 74 | + @exit 1 |
| 75 | +endif |
| 76 | + |
| 77 | +clean: |
| 78 | + rm -f test-output.log |
| 79 | + go clean -testcache |
| 80 | + |
| 81 | +# Verify prerequisites |
| 82 | +check-prereqs: |
| 83 | + @echo "Checking prerequisites..." |
| 84 | + @which kubectl > /dev/null || (echo "kubectl not found" && exit 1) |
| 85 | + @which helm > /dev/null || (echo "helm not found" && exit 1) |
| 86 | + @which docker > /dev/null || (echo "docker not found" && exit 1) |
| 87 | + @kubectl cluster-info > /dev/null 2>&1 || (echo "No Kubernetes cluster available - set kubectl context" && exit 1) |
| 88 | + @echo "All prerequisites met!" |
| 89 | + |
| 90 | +# Check Docker Hub login |
| 91 | +check-docker-login: |
| 92 | + @echo "Checking Docker Hub login..." |
| 93 | + @docker login |
| 94 | + @echo "Docker Hub login OK!" |
| 95 | + |
| 96 | +# Deploy OCI registry in-cluster for Helm charts |
| 97 | +setup-helm-registry: |
| 98 | + @echo "Setting up in-cluster OCI registry for Helm charts..." |
| 99 | + @kubectl get namespace registry > /dev/null 2>&1 || kubectl create namespace registry |
| 100 | + @kubectl get deployment registry -n registry > /dev/null 2>&1 || kubectl apply -f $(CURDIR)/manifests/registry.yaml |
| 101 | + @echo "Waiting for registry to be ready..." |
| 102 | + @kubectl wait --for=condition=available deployment/registry -n registry --timeout=120s |
| 103 | + @kubectl wait --for=condition=ready pod -l app=registry -n registry --timeout=120s |
| 104 | + @echo "Helm registry is ready!" |
| 105 | + |
| 106 | +# Build all required images using existing Makefiles |
| 107 | +build-images: |
| 108 | + @echo "Building images for $(DOCKER_REGISTRY)..." |
| 109 | + @echo "Building Gateway images (controller, policy-engine, router)..." |
| 110 | + $(MAKE) -C $(PROJECT_ROOT)/gateway build-local DOCKER_REGISTRY=$(DOCKER_REGISTRY) VERSION=$(IMAGE_TAG) |
| 111 | + @echo "Building Operator image..." |
| 112 | + $(MAKE) -C $(PROJECT_ROOT)/kubernetes/gateway-operator docker-build IMG=$(DOCKER_REGISTRY)/gateway-operator:$(IMAGE_TAG) |
| 113 | + @echo "Building Mock JWKS..." |
| 114 | + cd $(PROJECT_ROOT)/tests/mock-servers/mock-jwks && \ |
| 115 | + docker build -t $(DOCKER_REGISTRY)/mock-jwks:$(IMAGE_TAG) . |
| 116 | + @echo "All images built!" |
| 117 | + cd $(PROJECT_ROOT)/tests/mock-servers/mock-jwks && \ |
| 118 | + docker build -t $(DOCKER_REGISTRY)/mock-jwks:$(IMAGE_TAG) . |
| 119 | + @echo "All images built!" |
| 120 | + |
| 121 | +# Push images to Docker Hub |
| 122 | +push-images: check-docker-login |
| 123 | + @echo "Pushing images to Docker Hub ($(DOCKER_REGISTRY))..." |
| 124 | + docker push $(DOCKER_REGISTRY)/gateway-controller:$(IMAGE_TAG) |
| 125 | + docker push $(DOCKER_REGISTRY)/policy-engine:$(IMAGE_TAG) |
| 126 | + docker push $(DOCKER_REGISTRY)/gateway-router:$(IMAGE_TAG) |
| 127 | + docker push $(DOCKER_REGISTRY)/gateway-operator:$(IMAGE_TAG) |
| 128 | + docker push $(DOCKER_REGISTRY)/mock-jwks:$(IMAGE_TAG) |
| 129 | + @echo "All images pushed to Docker Hub!" |
| 130 | + |
| 131 | +# Push Gateway Helm chart to in-cluster OCI registry |
| 132 | +push-helm-chart: setup-helm-registry |
| 133 | + @echo "Packaging Gateway Helm chart..." |
| 134 | + cd $(PROJECT_ROOT)/kubernetes/helm/gateway-helm-chart && \ |
| 135 | + helm package . --version 0.0.0-test |
| 136 | + @echo "Starting port-forward for Helm push..." |
| 137 | + @kubectl port-forward svc/registry -n registry 5000:5000 & |
| 138 | + @sleep 3 |
| 139 | + @echo "Pushing Helm chart..." |
| 140 | + cd $(PROJECT_ROOT)/kubernetes/helm/gateway-helm-chart && \ |
| 141 | + helm push gateway-0.0.0-test.tgz oci://localhost:5000/charts --plain-http |
| 142 | + @pkill -f "kubectl port-forward.*registry" || true |
| 143 | + @echo "Helm chart pushed!" |
| 144 | + |
| 145 | +# Full local setup: build images, push to Docker Hub, setup Helm registry |
| 146 | +# Set SKIP_IMAGES=1 to skip building and pushing images |
| 147 | +setup-local: check-prereqs |
| 148 | +ifndef SKIP_IMAGES |
| 149 | + $(MAKE) build-images |
| 150 | + $(MAKE) push-images |
| 151 | +endif |
| 152 | + $(MAKE) setup-helm-registry |
| 153 | + $(MAKE) push-helm-chart |
| 154 | + @echo "" |
| 155 | + @echo "=== Local environment is ready! ===" |
| 156 | +ifndef SKIP_IMAGES |
| 157 | + @echo "Images pushed to: $(DOCKER_REGISTRY)" |
| 158 | +endif |
| 159 | + @echo "Helm chart pushed to: oci://registry.registry.svc.cluster.local:5000/charts/gateway" |
| 160 | + @echo "" |
| 161 | + |
| 162 | +# Run tests locally with full setup |
| 163 | +# Only assumes: kubectl context is set, docker login done |
| 164 | +# Set SKIP_SETUP=1 to skip setup-local and deps |
| 165 | +# Set TAGS=@tag to run specific tags (optional) |
| 166 | +run-local: |
| 167 | +ifndef SKIP_SETUP |
| 168 | + $(MAKE) setup-local |
| 169 | + $(MAKE) deps |
| 170 | +endif |
| 171 | + @echo "" |
| 172 | +ifdef TAGS |
| 173 | + @echo "=== Running operator integration tests with tags: $(TAGS) ===" |
| 174 | +else |
| 175 | + @echo "=== Running operator integration tests ===" |
| 176 | +endif |
| 177 | + @echo "" |
| 178 | + cd $(CURDIR)/cmd && \ |
| 179 | + DOCKER_REGISTRY=$(DOCKER_REGISTRY) \ |
| 180 | + IMAGE_TAG=$(IMAGE_TAG) \ |
| 181 | + IMAGE_PULL_POLICY=Always \ |
| 182 | + OPERATOR_CHART_PATH=$(PROJECT_ROOT)/kubernetes/helm/operator-helm-chart \ |
| 183 | + GATEWAY_CHART_PATH=$(PROJECT_ROOT)/kubernetes/helm/gateway-helm-chart \ |
| 184 | + GATEWAY_CHART_NAME=oci://registry.registry.svc.cluster.local:5000/charts/gateway \ |
| 185 | + GATEWAY_CHART_VERSION=0.0.0-test \ |
| 186 | + TAGS="$(TAGS)" \ |
| 187 | + go run . |
| 188 | + |
0 commit comments