Skip to content

Commit 72f4dbe

Browse files
committed
implement user-server(service-proxy), provide user a https server to access managed cluster service on the hub side.
Signed-off-by: xuezhaojun <[email protected]>
1 parent 7bcbdcf commit 72f4dbe

File tree

200 files changed

+23417
-1932
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

200 files changed

+23417
-1932
lines changed

.github/workflows/go-presubmit.yml

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,11 @@ jobs:
9090
run: curl -L https://raw.githubusercontent.com/open-cluster-management-io/clusteradm/main/install.sh | bash
9191
- name: Create k8s Kind Cluster
9292
uses: helm/[email protected]
93-
- name: Prepare OCM testing environment
94-
run: |
95-
clusteradm init --output-join-command-file join.sh --wait
96-
sh -c "$(cat join.sh) loopback --force-internal-endpoint-lookup"
97-
clusteradm accept --clusters loopback --wait 30
98-
kubectl wait --for=condition=ManagedClusterConditionAvailable managedcluster/loopback
93+
with:
94+
cluster_name: e2e
9995
- name: Build image
100-
run: |
101-
make images
102-
kind load docker-image quay.io/open-cluster-management/cluster-proxy:latest --name chart-testing
103-
- name: Install latest cluster-proxy
104-
run: |
105-
helm install \
106-
-n open-cluster-management-addon --create-namespace \
107-
cluster-proxy charts/cluster-proxy/ \
108-
--set tag=latest --set installByPlacement.placementName=default
109-
- name: Build&Run e2e test
110-
run: |
111-
kubectl wait --for=condition=ProxyServerDeployed=true managedproxyconfiguration cluster-proxy --timeout=60s
112-
kubectl wait --for=condition=Available deployment/cluster-proxy --timeout=60s -n open-cluster-management-addon
113-
kubectl port-forward -n open-cluster-management-addon services/proxy-entrypoint 8090:8090 &
114-
make test-e2e
96+
run: make images
97+
- name: Setup environment
98+
run: make setup-env-for-e2e && make deploy-cluster-proxy-e2e
99+
- name: Run e2e tests
100+
run: make test-e2e

Makefile

Lines changed: 152 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ IMG ?= controller:latest
33
IMAGE_REGISTRY_NAME ?= quay.io/open-cluster-management
44
IMAGE_NAME = cluster-proxy
55
IMAGE_TAG ?= latest
6-
E2E_TEST_CLUSTER_NAME ?= loopback
6+
E2E_TEST_CLUSTER_NAME ?= e2e
77
CONTAINER_ENGINE ?= docker
88
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
99
CRD_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)
1216
ifeq (,$(shell go env GOBIN))
1317
GOBIN=$(shell go env GOPATH)/bin
@@ -56,11 +60,7 @@ fmt: ## Run go fmt against code.
5660
vet: ## 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

6565
test: manifests generate fmt vet ## Run tests.
6666
go test ./pkg/... -coverprofile cover.out
@@ -70,6 +70,7 @@ test: manifests generate fmt vet ## Run tests.
7070
build: 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

7475
docker-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

8283
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
8384
controller-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

8687
KUSTOMIZE = $(shell pwd)/bin/kustomize
8788
kustomize: ## Download kustomize locally if necessary.
@@ -117,6 +118,30 @@ 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+
pure-image:
130+
$(CONTAINER_ENGINE) build \
131+
-f cmd/pure.Dockerfile \
132+
--build-arg ADDON_AGENT_IMAGE_NAME=$(IMAGE_REGISTRY_NAME)/$(IMAGE_NAME):$(IMAGE_TAG) \
133+
-t $(IMAGE_REGISTRY_NAME)/$(IMAGE_NAME):$(IMAGE_TAG) .
134+
135+
pure-image-amd64:
136+
$(CONTAINER_ENGINE) buildx build \
137+
--platform linux/amd64 \
138+
--load \
139+
-f cmd/pure.Dockerfile \
140+
--build-arg ADDON_AGENT_IMAGE_NAME=$(IMAGE_REGISTRY_NAME)/$(IMAGE_NAME):$(IMAGE_TAG) \
141+
-t $(IMAGE_REGISTRY_NAME)/$(IMAGE_NAME):$(IMAGE_TAG) .
142+
143+
## Integration Testing
144+
120145
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
121146
test-integration: manifests generate fmt vet
122147
mkdir -p ${ENVTEST_ASSETS_DIR}
@@ -126,13 +151,126 @@ test-integration: manifests generate fmt vet
126151
setup_envtest_env $(ENVTEST_ASSETS_DIR); \
127152
go test ./test/integration/... -coverprofile cover.out
128153

129-
e2e-job-image:
154+
## E2E Testing
155+
156+
# Note: here we use internal service ns as the entrypointAddress. The test cluster should be registered to itself as a managed cluster.
157+
setup-env-for-e2e:
158+
@echo "Setting up environment for e2e tests..."
159+
./test/e2e/env/init.sh
160+
.PHONY: setup-env-for-e2e
161+
162+
# load cluster-proxy image into kind cluster
163+
load-cluster-proxy-image-kind:
164+
@echo "Loading cluster-proxy image into kind cluster..."
165+
kind load docker-image $(IMAGE_REGISTRY_NAME)/$(IMAGE_NAME):$(IMAGE_TAG) --name $(E2E_TEST_CLUSTER_NAME)
166+
.PHONY: load-cluster-proxy-image-kind
167+
168+
# delete cluster-proxy image from kind cluster nodes
169+
delete-cluster-proxy-image-from-kind:
170+
@echo "Deleting cluster-proxy image from kind cluster nodes..."
171+
@for node in $$(kind get nodes --name $(E2E_TEST_CLUSTER_NAME) 2>/dev/null || echo ""); do \
172+
if [ -n "$$node" ]; then \
173+
docker exec $$node crictl rmi $(IMAGE_REGISTRY_NAME)/$(IMAGE_NAME):$(IMAGE_TAG) 2>/dev/null || true; \
174+
fi; \
175+
done
176+
.PHONY: delete-cluster-proxy-image-from-kind
177+
178+
deploy-cluster-proxy-e2e: delete-cluster-proxy-image-from-kind load-cluster-proxy-image-kind
179+
@echo "Deploying cluster-proxy crds..."
180+
kubectl apply -f charts/cluster-proxy/crds/managedproxyconfigurations.yaml
181+
kubectl apply -f charts/cluster-proxy/crds/managedproxyserviceresolvers.yaml
182+
@echo "Deploying cluster-proxy..."
183+
helm install \
184+
-n open-cluster-management-addon --create-namespace \
185+
cluster-proxy charts/cluster-proxy \
186+
--set registry=$(IMAGE_REGISTRY_NAME) \
187+
--set image=$(IMAGE_NAME) \
188+
--set tag=$(IMAGE_TAG) \
189+
--set proxyServerImage=$(IMAGE_REGISTRY_NAME)/$(IMAGE_NAME) \
190+
--set proxyAgentImage=$(IMAGE_REGISTRY_NAME)/$(IMAGE_NAME) \
191+
--set proxyServer.entrypointAddress="proxy-entrypoint.open-cluster-management-addon.svc" \
192+
--set proxyServer.port=8091
193+
@echo "Cluster-proxy deployed successfully!"
194+
.PHONY: deploy-cluster-proxy-e2e
195+
196+
# Build e2e test container image
197+
build-e2e-image:
198+
@echo "Building e2e test container image..."
130199
$(CONTAINER_ENGINE) build \
131-
-f test/e2e/job/Dockerfile \
132-
-t $(IMAGE_REGISTRY_NAME)/$(IMAGE_NAME)-e2e-job:$(IMAGE_TAG) .
200+
-f test/e2e/Dockerfile \
201+
-t $(IMAGE_REGISTRY_NAME)/$(IMAGE_NAME)-e2e:$(IMAGE_TAG) .
202+
.PHONY: build-e2e-image
203+
204+
# Load e2e image into kind cluster (for local testing)
205+
load-e2e-image-kind:
206+
@echo "Loading e2e image into kind cluster..."
207+
kind load docker-image $(IMAGE_REGISTRY_NAME)/$(IMAGE_NAME)-e2e:$(IMAGE_TAG) --name $(E2E_TEST_CLUSTER_NAME)
208+
.PHONY: load-e2e-image-kind
209+
210+
# Delete e2e image from kind cluster nodes (for rapid iteration)
211+
delete-e2e-image-from-kind:
212+
@echo "Deleting e2e image from kind cluster nodes..."
213+
@for node in $$(kind get nodes --name $(E2E_TEST_CLUSTER_NAME) 2>/dev/null || echo ""); do \
214+
if [ -n "$$node" ]; then \
215+
docker exec $$node crictl rmi $(IMAGE_REGISTRY_NAME)/$(IMAGE_NAME)-e2e:$(IMAGE_TAG) 2>/dev/null || true; \
216+
fi; \
217+
done
218+
.PHONY: delete-e2e-image-from-kind
219+
220+
# Run e2e tests in cluster using container image (Kubernetes-native approach)
221+
# Use LABEL_FILTER to run specific tests, e.g.: make test-e2e LABEL_FILTER="install"
222+
test-e2e: delete-e2e-image-from-kind build-e2e-image load-e2e-image-kind
223+
@echo "Deleting existing e2e test job if present..."
224+
@kubectl delete job cluster-proxy-e2e -n open-cluster-management-addon --ignore-not-found
225+
@echo "Deploying e2e test job..."
226+
@if [ -n "$(LABEL_FILTER)" ]; then \
227+
echo "Running tests with label filter: $(LABEL_FILTER)"; \
228+
fi
229+
@sed -e '/name: LABEL_FILTER/{n;s|value: ""|value: "$(LABEL_FILTER)"|;}' \
230+
-e 's|image: quay.io/open-cluster-management/cluster-proxy-e2e:latest|image: $(IMAGE_REGISTRY_NAME)/$(IMAGE_NAME)-e2e:$(IMAGE_TAG)|g' \
231+
test/e2e/env/job.yaml | kubectl apply -f -
232+
@./test/e2e/env/wait-for-job.sh cluster-proxy-e2e open-cluster-management-addon 1200
233+
.PHONY: test-e2e
234+
235+
# Rapid iteration workflow for e2e tests (cleans up everything first)
236+
# Use LABEL_FILTER to run specific tests, e.g.: make retest-e2e LABEL_FILTER="connectivity"
237+
retest-e2e: clean-e2e delete-e2e-image-from-kind build-e2e-image load-e2e-image-kind
238+
@echo "Deleting existing e2e test job if present..."
239+
@kubectl delete job cluster-proxy-e2e -n open-cluster-management-addon --ignore-not-found
240+
@echo "Deploying e2e test job..."
241+
@if [ -n "$(LABEL_FILTER)" ]; then \
242+
echo "Running tests with label filter: $(LABEL_FILTER)"; \
243+
fi
244+
@sed -e '/name: LABEL_FILTER/{n;s|value: ""|value: "$(LABEL_FILTER)"|;}' \
245+
-e 's|image: quay.io/open-cluster-management/cluster-proxy-e2e:latest|image: $(IMAGE_REGISTRY_NAME)/$(IMAGE_NAME)-e2e:$(IMAGE_TAG)|g' \
246+
test/e2e/env/job.yaml | kubectl apply -f -
247+
@./test/e2e/env/wait-for-job.sh cluster-proxy-e2e open-cluster-management-addon 1200
248+
.PHONY: retest-e2e
133249

134-
build-e2e:
135-
go test -c -o bin/e2e ./test/e2e/
250+
# Clean up e2e test job and related resources
251+
clean-e2e:
252+
@echo "Cleaning up e2e test resources..."
253+
kubectl delete job/cluster-proxy-e2e -n open-cluster-management-addon --ignore-not-found=true
254+
kubectl delete serviceaccount/cluster-proxy-e2e -n open-cluster-management-addon --ignore-not-found=true
255+
kubectl delete clusterrolebinding/cluster-proxy-e2e --ignore-not-found=true
256+
kubectl delete clusterrole/cluster-proxy-e2e --ignore-not-found=true
257+
.PHONY: clean-e2e
136258

137-
test-e2e: build-e2e
138-
./bin/e2e --test-cluster $(E2E_TEST_CLUSTER_NAME)
259+
# Quick verify of user-server
260+
# Example result:
261+
# {
262+
# "kind": "APIVersions",
263+
# "versions": [
264+
# "v1"
265+
# ],
266+
# "serverAddressByClientCIDRs": [
267+
# {
268+
# "clientCIDR": "0.0.0.0/0",
269+
# "serverAddress": "172.17.0.2:6443"
270+
# }
271+
# ]
272+
# }
273+
verify-user-server:
274+
@echo "Verifying user-server..."
275+
TOKEN=$$(kubectl create token default -n default) && POD=$$(kubectl get pods -n open-cluster-management-addon -l component=cluster-proxy-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-user.open-cluster-management-addon.svc.cluster.local:9092/loopback/api"
276+
.PHONY: verify-user-server

charts/cluster-proxy/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ apiVersion: v2
22
name: cluster-proxy
33
description: A Helm chart for Cluster-Proxy OCM Addon
44
type: application
5-
version: 0.8.0
5+
version: 0.9.0
66
appVersion: 1.0.0

0 commit comments

Comments
 (0)