@@ -3,11 +3,15 @@ IMG ?= controller:latest
33IMAGE_REGISTRY_NAME ?= quay.io/open-cluster-management
44IMAGE_NAME = cluster-proxy
55IMAGE_TAG ?= latest
6- E2E_TEST_CLUSTER_NAME ?= loopback
6+ E2E_TEST_CLUSTER_NAME ?= e2e
77CONTAINER_ENGINE ?= docker
88# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
99CRD_OPTIONS ?= "crd:crdVersions={v1},allowDangerousTypes=true,generateEmbeddedObjectMeta=true"
1010
11+ # Label filter for e2e tests (Ginkgo v2 label filter expression)
12+ # Examples: "install", "connectivity", "certificate && !rotation", etc.
13+ LABEL_FILTER ?=
14+
1115# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
1216ifeq (,$(shell go env GOBIN) )
1317GOBIN =$(shell go env GOPATH) /bin
@@ -56,11 +60,7 @@ fmt: ## Run go fmt against code.
5660vet : # # Run go vet against code.
5761 go vet ./...
5862
59- golint :
60- go install github.com/golangci/golangci-lint/cmd/
[email protected] 61- golangci-lint run --timeout=3m ./...
62-
63- verify : fmt vet golint
63+ verify : fmt vet
6464
6565test : manifests generate fmt vet # # Run tests.
6666 go test ./pkg/... -coverprofile cover.out
@@ -70,6 +70,7 @@ test: manifests generate fmt vet ## Run tests.
7070build : generate fmt vet
7171 go build -o bin/addon-manager cmd/addon-manager/main.go
7272 go build -o bin/addon-agent cmd/addon-agent/main.go
73+ go build -o bin/cluster-proxy cmd/cluster-proxy/main.go
7374
7475docker-build : test # # Build docker image with the manager.
7576 $(CONTAINER_ENGINE ) build -t ${IMG} .
@@ -81,7 +82,7 @@ docker-push: ## Push docker image with the manager.
8182
8283CONTROLLER_GEN = $(shell pwd) /bin/controller-gen
8384controller-gen : # # Download controller-gen locally if necessary.
84- $(call go-get-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen@v0.18 .0)
85+ $(call go-get-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen@v0.19 .0)
8586
8687KUSTOMIZE = $(shell pwd) /bin/kustomize
8788kustomize : # # Download kustomize locally if necessary.
@@ -117,6 +118,16 @@ images:
117118 --build-arg ADDON_AGENT_IMAGE_NAME=$(IMAGE_REGISTRY_NAME ) /$(IMAGE_NAME ) :$(IMAGE_TAG ) \
118119 -t $(IMAGE_REGISTRY_NAME ) /$(IMAGE_NAME ) :$(IMAGE_TAG ) .
119120
121+ images-amd64 :
122+ $(CONTAINER_ENGINE ) buildx build \
123+ --platform linux/amd64 \
124+ --load \
125+ -f cmd/Dockerfile \
126+ --build-arg ADDON_AGENT_IMAGE_NAME=$(IMAGE_REGISTRY_NAME ) /$(IMAGE_NAME ) :$(IMAGE_TAG ) \
127+ -t $(IMAGE_REGISTRY_NAME ) /$(IMAGE_NAME ) :$(IMAGE_TAG ) .
128+
129+ # # Integration Testing
130+
120131ENVTEST_ASSETS_DIR =$(shell pwd) /testbin
121132test-integration : manifests generate fmt vet
122133 mkdir -p ${ENVTEST_ASSETS_DIR}
@@ -126,13 +137,124 @@ test-integration: manifests generate fmt vet
126137 setup_envtest_env $(ENVTEST_ASSETS_DIR ) ; \
127138 go test ./test/integration/... -coverprofile cover.out
128139
129- e2e-job-image :
140+ # # E2E Testing
141+
142+ # Note: here we use internal service ns as the entrypointAddress. The test cluster should be registered to itself as a managed cluster.
143+ setup-env-for-e2e :
144+ @echo " Setting up environment for e2e tests..."
145+ ./test/e2e/env/init.sh
146+ .PHONY : setup-env-for-e2e
147+
148+ # load cluster-proxy image into kind cluster
149+ load-cluster-proxy-image-kind :
150+ @echo " Loading cluster-proxy image into kind cluster..."
151+ kind load docker-image $(IMAGE_REGISTRY_NAME ) /$(IMAGE_NAME ) :$(IMAGE_TAG ) --name $(E2E_TEST_CLUSTER_NAME )
152+ .PHONY : load-cluster-proxy-image-kind
153+
154+ # delete cluster-proxy image from kind cluster nodes
155+ delete-cluster-proxy-image-from-kind :
156+ @echo " Deleting cluster-proxy image from kind cluster nodes..."
157+ @for node in $$(kind get nodes --name $(E2E_TEST_CLUSTER_NAME ) 2>/dev/null || echo "" ) ; do \
158+ if [ -n " $$ node" ]; then \
159+ docker exec $$ node crictl rmi $(IMAGE_REGISTRY_NAME ) /$(IMAGE_NAME ) :$(IMAGE_TAG ) 2> /dev/null || true ; \
160+ fi ; \
161+ done
162+ .PHONY : delete-cluster-proxy-image-from-kind
163+
164+ deploy-cluster-proxy-e2e : delete-cluster-proxy-image-from-kind load-cluster-proxy-image-kind
165+ @echo " Deploying cluster-proxy..."
166+ helm install \
167+ -n open-cluster-management-addon --create-namespace \
168+ cluster-proxy charts/cluster-proxy \
169+ --set registry=$(IMAGE_REGISTRY_NAME ) \
170+ --set image=$(IMAGE_NAME ) \
171+ --set tag=$(IMAGE_TAG ) \
172+ --set proxyServerImage=$(IMAGE_REGISTRY_NAME ) /$(IMAGE_NAME ) \
173+ --set proxyAgentImage=$(IMAGE_REGISTRY_NAME ) /$(IMAGE_NAME ) \
174+ --set proxyServer.entrypointAddress=" proxy-entrypoint.open-cluster-management-addon.svc" \
175+ --set proxyServer.port=8091 \
176+ --set enableServiceProxy=true
177+ @echo " Cluster-proxy deployed successfully!"
178+ .PHONY : deploy-cluster-proxy-e2e
179+
180+ # Build e2e test container image
181+ build-e2e-image :
182+ @echo " Building e2e test container image..."
130183 $(CONTAINER_ENGINE ) build \
131- -f test/e2e/job/Dockerfile \
132- -t $(IMAGE_REGISTRY_NAME ) /$(IMAGE_NAME ) -e2e-job:$(IMAGE_TAG ) .
184+ -f test/e2e/Dockerfile \
185+ -t $(IMAGE_REGISTRY_NAME ) /$(IMAGE_NAME ) -e2e:$(IMAGE_TAG ) .
186+ .PHONY : build-e2e-image
187+
188+ # Load e2e image into kind cluster (for local testing)
189+ load-e2e-image-kind :
190+ @echo " Loading e2e image into kind cluster..."
191+ kind load docker-image $(IMAGE_REGISTRY_NAME ) /$(IMAGE_NAME ) -e2e:$(IMAGE_TAG ) --name $(E2E_TEST_CLUSTER_NAME )
192+ .PHONY : load-e2e-image-kind
193+
194+ # Delete e2e image from kind cluster nodes (for rapid iteration)
195+ delete-e2e-image-from-kind :
196+ @echo " Deleting e2e image from kind cluster nodes..."
197+ @for node in $$(kind get nodes --name $(E2E_TEST_CLUSTER_NAME ) 2>/dev/null || echo "" ) ; do \
198+ if [ -n " $$ node" ]; then \
199+ docker exec $$ node crictl rmi $(IMAGE_REGISTRY_NAME ) /$(IMAGE_NAME ) -e2e:$(IMAGE_TAG ) 2> /dev/null || true ; \
200+ fi ; \
201+ done
202+ .PHONY : delete-e2e-image-from-kind
203+
204+ # Run e2e tests in cluster using container image (Kubernetes-native approach)
205+ # Use LABEL_FILTER to run specific tests, e.g.: make test-e2e LABEL_FILTER="install"
206+ test-e2e : delete-e2e-image-from-kind build-e2e-image load-e2e-image-kind
207+ @echo " Deleting existing e2e test job if present..."
208+ @kubectl delete job cluster-proxy-e2e -n open-cluster-management-addon --ignore-not-found
209+ @echo " Deploying e2e test job..."
210+ @if [ -n " $( LABEL_FILTER) " ]; then \
211+ echo " Running tests with label filter: $( LABEL_FILTER) " ; \
212+ fi
213+ @sed -e ' /name: LABEL_FILTER/{n;s|value: ""|value: "$(LABEL_FILTER)"|;}' \
214+ -e ' s|image: quay.io/open-cluster-management/cluster-proxy-e2e:latest|image: $(IMAGE_REGISTRY_NAME)/$(IMAGE_NAME)-e2e:$(IMAGE_TAG)|g' \
215+ test/e2e/env/job.yaml | kubectl apply -f -
216+ @./test/e2e/env/wait-for-job.sh cluster-proxy-e2e open-cluster-management-addon 1200
217+ .PHONY : test-e2e
218+
219+ # Rapid iteration workflow for e2e tests (cleans up everything first)
220+ # Use LABEL_FILTER to run specific tests, e.g.: make retest-e2e LABEL_FILTER="connectivity"
221+ retest-e2e : clean-e2e delete-e2e-image-from-kind build-e2e-image load-e2e-image-kind
222+ @echo " Deleting existing e2e test job if present..."
223+ @kubectl delete job cluster-proxy-e2e -n open-cluster-management-addon --ignore-not-found
224+ @echo " Deploying e2e test job..."
225+ @if [ -n " $( LABEL_FILTER) " ]; then \
226+ echo " Running tests with label filter: $( LABEL_FILTER) " ; \
227+ fi
228+ @sed -e ' /name: LABEL_FILTER/{n;s|value: ""|value: "$(LABEL_FILTER)"|;}' \
229+ -e ' s|image: quay.io/open-cluster-management/cluster-proxy-e2e:latest|image: $(IMAGE_REGISTRY_NAME)/$(IMAGE_NAME)-e2e:$(IMAGE_TAG)|g' \
230+ test/e2e/env/job.yaml | kubectl apply -f -
231+ @./test/e2e/env/wait-for-job.sh cluster-proxy-e2e open-cluster-management-addon 1200
232+ .PHONY : retest-e2e
133233
134- build-e2e :
135- go test -c -o bin/e2e ./test/e2e/
234+ # Clean up e2e test job and related resources
235+ clean-e2e :
236+ @echo " Cleaning up e2e test resources..."
237+ kubectl delete job/cluster-proxy-e2e -n open-cluster-management-addon --ignore-not-found=true
238+ kubectl delete serviceaccount/cluster-proxy-e2e -n open-cluster-management-addon --ignore-not-found=true
239+ kubectl delete clusterrolebinding/cluster-proxy-e2e --ignore-not-found=true
240+ kubectl delete clusterrole/cluster-proxy-e2e --ignore-not-found=true
241+ .PHONY : clean-e2e
136242
137- test-e2e : build-e2e
138- ./bin/e2e --test-cluster $(E2E_TEST_CLUSTER_NAME )
243+ # Quick verify of user-server
244+ # Example result:
245+ # {
246+ # "kind": "APIVersions",
247+ # "versions": [
248+ # "v1"
249+ # ],
250+ # "serverAddressByClientCIDRs": [
251+ # {
252+ # "clientCIDR": "0.0.0.0/0",
253+ # "serverAddress": "172.17.0.2:6443"
254+ # }
255+ # ]
256+ # }
257+ verify-user-server :
258+ @echo " Verifying user-server..."
259+ TOKEN=$$(kubectl create token default -n default ) && POD=$$(kubectl get pods -n open-cluster-management-addon -l component=cluster-proxy-addon-user --field-selector=status.phase=Running -o jsonpath='{.items[0].metadata.name}' ) && kubectl debug -it $$ POD -n open-cluster-management-addon --image=praqma/network-multitool -- sh -c " curl -k -H 'Authorization: Bearer $$ TOKEN' https://cluster-proxy-addon-user.open-cluster-management-addon.svc.cluster.local:9092/loopback/api"
260+ .PHONY : verify-user-server
0 commit comments