This is an automated email from the ASF dual-hosted git repository.
lingsamuel pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-ingress-controller.git
The following commit(s) were added to refs/heads/master by this push:
new f84a083 feat: support custom registry for e2e test (#896)
f84a083 is described below
commit f84a083719b5de74c68dd3bf206b1a88f2a540c4
Author: JasonZhu <[email protected]>
AuthorDate: Tue Mar 8 08:35:36 2022 +0800
feat: support custom registry for e2e test (#896)
* feat: support custom registry for e2e test
* fix: add README and format variable CUSTOM_REGISTRT in makefile
* fix: format var name
* fix: rename LOCAL_REGISTRY variable name
* fix: update registry name in code
* fix: remove unused kind up part
* fix: format Makefile
---
Makefile | 45 ++++++++++++++++++++++-----------------
test/e2e/README.md | 4 +++-
test/e2e/scaffold/apisix.go | 2 +-
test/e2e/scaffold/etcd.go | 2 +-
test/e2e/scaffold/httpbin.go | 4 ++--
test/e2e/scaffold/ingress.go | 8 +++----
test/e2e/scaffold/scaffold.go | 10 +++++++++
test/e2e/scaffold/test_backend.go | 2 +-
8 files changed, 47 insertions(+), 30 deletions(-)
diff --git a/Makefile b/Makefile
index 91a5541..10dacf7 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@ default: help
VERSION ?= 1.4.0
RELEASE_SRC = apache-apisix-ingress-controller-${VERSION}-src
-LOCAL_REGISTRY="localhost:5000"
+REGISTRY ?="localhost:5000"
IMAGE_TAG ?= dev
GITSHA ?= "no-git-module"
@@ -63,14 +63,19 @@ lint:
unit-test:
go test -cover -coverprofile=coverage.txt ./...
-### e2e-test: Run e2e test cases (kind is required)
+### e2e-test: Run e2e test cases (in existing clusters directly)
.PHONY: e2e-test
-e2e-test: ginkgo-check push-images-to-kind
+e2e-test: ginkgo-check push-images
kubectl apply -k $(PWD)/samples/deploy/crd
cd test/e2e \
&& go mod download \
+ && export REGISTRY=$(REGISTRY) \
&& ACK_GINKGO_RC=true ginkgo -cover -coverprofile=coverage.txt
-r --randomizeSuites --randomizeAllSpecs --trace --nodes=$(E2E_CONCURRENCY)
+### e2e-test-local: Run e2e test cases (kind is required)
+.PHONY: e2e-test-local
+e2e-test-local: kind-up e2e-test
+
.PHONY: ginkgo-check
ginkgo-check:
ifeq ("$(wildcard $(GINKGO))", "")
@@ -78,37 +83,37 @@ ifeq ("$(wildcard $(GINKGO))", "")
exit 1
endif
-### push-images-to-kind: Push images used in e2e test suites to kind.
-.PHONY: push-images-to-kind
-push-images-to-kind: kind-up
+### push-images: Push images used in e2e test suites to kind or custom
registry.
+.PHONY: push-images
+push-images:
ifeq ($(E2E_SKIP_BUILD), 0)
docker pull apache/apisix:2.12.0-alpine
- docker tag apache/apisix:2.12.0-alpine
$(LOCAL_REGISTRY)/apache/apisix:dev
- docker push $(LOCAL_REGISTRY)/apache/apisix:dev
+ docker tag apache/apisix:2.12.0-alpine $(REGISTRY)/apache/apisix:dev
+ docker push $(REGISTRY)/apache/apisix:dev
docker pull bitnami/etcd:3.4.14-debian-10-r0
- docker tag bitnami/etcd:3.4.14-debian-10-r0
$(LOCAL_REGISTRY)/bitnami/etcd:3.4.14-debian-10-r0
- docker push $(LOCAL_REGISTRY)/bitnami/etcd:3.4.14-debian-10-r0
+ docker tag bitnami/etcd:3.4.14-debian-10-r0
$(REGISTRY)/bitnami/etcd:3.4.14-debian-10-r0
+ docker push $(REGISTRY)/bitnami/etcd:3.4.14-debian-10-r0
docker pull kennethreitz/httpbin
- docker tag kennethreitz/httpbin $(LOCAL_REGISTRY)/kennethreitz/httpbin
- docker push $(LOCAL_REGISTRY)/kennethreitz/httpbin
+ docker tag kennethreitz/httpbin $(REGISTRY)/kennethreitz/httpbin
+ docker push $(REGISTRY)/kennethreitz/httpbin
docker build -t test-backend:$(IMAGE_TAG) --build-arg ENABLE_PROXY=true
./test/e2e/testbackend
- docker tag test-backend:$(IMAGE_TAG)
$(LOCAL_REGISTRY)/test-backend:$(IMAGE_TAG)
- docker push $(LOCAL_REGISTRY)/test-backend:$(IMAGE_TAG)
+ docker tag test-backend:$(IMAGE_TAG)
$(REGISTRY)/test-backend:$(IMAGE_TAG)
+ docker push $(REGISTRY)/test-backend:$(IMAGE_TAG)
docker build -t apache/apisix-ingress-controller:$(IMAGE_TAG)
--build-arg ENABLE_PROXY=true .
- docker tag apache/apisix-ingress-controller:$(IMAGE_TAG)
$(LOCAL_REGISTRY)/apache/apisix-ingress-controller:$(IMAGE_TAG)
- docker push
$(LOCAL_REGISTRY)/apache/apisix-ingress-controller:$(IMAGE_TAG)
+ docker tag apache/apisix-ingress-controller:$(IMAGE_TAG)
$(REGISTRY)/apache/apisix-ingress-controller:$(IMAGE_TAG)
+ docker push $(REGISTRY)/apache/apisix-ingress-controller:$(IMAGE_TAG)
docker pull jmalloc/echo-server:latest
- docker tag jmalloc/echo-server:latest
$(LOCAL_REGISTRY)/jmalloc/echo-server:latest
- docker push $(LOCAL_REGISTRY)/jmalloc/echo-server:latest
+ docker tag jmalloc/echo-server:latest
$(REGISTRY)/jmalloc/echo-server:latest
+ docker push $(REGISTRY)/jmalloc/echo-server:latest
docker pull busybox:1.28
- docker tag busybox:1.28 $(LOCAL_REGISTRY)/busybox:1.28
- docker push $(LOCAL_REGISTRY)/busybox:1.28
+ docker tag busybox:1.28 $(REGISTRY)/busybox:1.28
+ docker push $(REGISTRY)/busybox:1.28
endif
### kind-up: Launch a Kubernetes cluster with a image registry by
Kind.
diff --git a/test/e2e/README.md b/test/e2e/README.md
index c986b7a..be5ddd7 100644
--- a/test/e2e/README.md
+++ b/test/e2e/README.md
@@ -46,12 +46,14 @@ Test caes inside `features` directory test some features
about APISIX, such as t
Quick Start
-----------
-Run `make e2e-test` to run the e2e test suites in your development
environment, a several stuffs that this command will do:
+Run `make e2e-test-local` to run the e2e test suites in your development
environment, a several stuffs that this command will do:
1. Create a Kubernetes cluster by [kind](https://kind.sigs.k8s.io/), please
installing in advance.
2. Build and push all related images to this cluster.
3. Run e2e test suites.
+Run `make e2e-test` to run the e2e test suites in an existing cluster, you can
specify custom registry by passing REGISTRY(eg docker.io).
+
Step `1` and `2` can be skipped by passing `E2E_SKIP_BUILD=1` to this
directive, also, you can customize the
running concurrency of e2e test suites by passing `E2E_CONCURRENCY=X` where
`X` is the desired number of cases running in parallel.
diff --git a/test/e2e/scaffold/apisix.go b/test/e2e/scaffold/apisix.go
index 53b01bb..3614099 100644
--- a/test/e2e/scaffold/apisix.go
+++ b/test/e2e/scaffold/apisix.go
@@ -141,7 +141,7 @@ func (s *Scaffold) newAPISIX() (*corev1.Service, error) {
if err := k8s.KubectlApplyFromStringE(s.t, s.kubectlOptions,
configData); err != nil {
return nil, err
}
- if err := k8s.KubectlApplyFromStringE(s.t, s.kubectlOptions,
_apisixDeployment); err != nil {
+ if err := k8s.KubectlApplyFromStringE(s.t, s.kubectlOptions,
s.FormatRegistry(_apisixDeployment)); err != nil {
return nil, err
}
if err := k8s.KubectlApplyFromStringE(s.t, s.kubectlOptions,
_apisixService); err != nil {
diff --git a/test/e2e/scaffold/etcd.go b/test/e2e/scaffold/etcd.go
index c0559bb..3b9301e 100644
--- a/test/e2e/scaffold/etcd.go
+++ b/test/e2e/scaffold/etcd.go
@@ -92,7 +92,7 @@ spec:
)
func (s *Scaffold) newEtcd() (*corev1.Service, error) {
- if err := k8s.KubectlApplyFromStringE(s.t, s.kubectlOptions,
etcdDeployment); err != nil {
+ if err := k8s.KubectlApplyFromStringE(s.t, s.kubectlOptions,
s.FormatRegistry(etcdDeployment)); err != nil {
return nil, err
}
if err := k8s.KubectlApplyFromStringE(s.t, s.kubectlOptions,
etcdService); err != nil {
diff --git a/test/e2e/scaffold/httpbin.go b/test/e2e/scaffold/httpbin.go
index b508e94..b2aaaa9 100644
--- a/test/e2e/scaffold/httpbin.go
+++ b/test/e2e/scaffold/httpbin.go
@@ -89,7 +89,7 @@ spec:
)
func (s *Scaffold) newHTTPBIN() (*corev1.Service, error) {
- httpbinDeployment := fmt.Sprintf(_httpbinDeploymentTemplate, 1)
+ httpbinDeployment :=
fmt.Sprintf(s.FormatRegistry(_httpbinDeploymentTemplate), 1)
if err := k8s.KubectlApplyFromStringE(s.t, s.kubectlOptions,
httpbinDeployment); err != nil {
return nil, err
}
@@ -105,7 +105,7 @@ func (s *Scaffold) newHTTPBIN() (*corev1.Service, error) {
// ScaleHTTPBIN scales the number of HTTPBIN pods to desired.
func (s *Scaffold) ScaleHTTPBIN(desired int) error {
- httpbinDeployment := fmt.Sprintf(_httpbinDeploymentTemplate, desired)
+ httpbinDeployment :=
fmt.Sprintf(s.FormatRegistry(_httpbinDeploymentTemplate), desired)
if err := k8s.KubectlApplyFromStringE(s.t, s.kubectlOptions,
httpbinDeployment); err != nil {
return err
}
diff --git a/test/e2e/scaffold/ingress.go b/test/e2e/scaffold/ingress.go
index 6c5181c..d551eb4 100644
--- a/test/e2e/scaffold/ingress.go
+++ b/test/e2e/scaffold/ingress.go
@@ -407,9 +407,9 @@ func (s *Scaffold) newIngressAPISIXController() error {
var ingressAPISIXDeployment string
label := fmt.Sprintf("apisix.ingress.watch=%s", s.namespace)
if s.opts.EnableWebhooks {
- ingressAPISIXDeployment =
fmt.Sprintf(_ingressAPISIXDeploymentTemplate, s.opts.IngressAPISIXReplicas,
s.namespace, label, s.opts.APISIXRouteVersion, s.opts.APISIXPublishAddress,
_volumeMounts, _webhookCertSecret)
+ ingressAPISIXDeployment =
fmt.Sprintf(s.FormatRegistry(_ingressAPISIXDeploymentTemplate),
s.opts.IngressAPISIXReplicas, s.namespace, label, s.opts.APISIXRouteVersion,
s.opts.APISIXPublishAddress, _volumeMounts, _webhookCertSecret)
} else {
- ingressAPISIXDeployment =
fmt.Sprintf(_ingressAPISIXDeploymentTemplate, s.opts.IngressAPISIXReplicas,
s.namespace, label, s.opts.APISIXRouteVersion, s.opts.APISIXPublishAddress, "",
_webhookCertSecret)
+ ingressAPISIXDeployment =
fmt.Sprintf(s.FormatRegistry(_ingressAPISIXDeploymentTemplate),
s.opts.IngressAPISIXReplicas, s.namespace, label, s.opts.APISIXRouteVersion,
s.opts.APISIXPublishAddress, "", _webhookCertSecret)
}
err = k8s.KubectlApplyFromStringE(s.t, s.kubectlOptions,
ingressAPISIXDeployment)
@@ -515,9 +515,9 @@ func (s *Scaffold) ScaleIngressController(desired int)
error {
var ingressDeployment string
label := fmt.Sprintf("apisix.ingress.watch=%s", s.namespace)
if s.opts.EnableWebhooks {
- ingressDeployment =
fmt.Sprintf(_ingressAPISIXDeploymentTemplate, desired, s.namespace, label,
s.opts.APISIXRouteVersion, s.opts.APISIXPublishAddress, _volumeMounts,
_webhookCertSecret)
+ ingressDeployment =
fmt.Sprintf(s.FormatRegistry(_ingressAPISIXDeploymentTemplate), desired,
s.namespace, label, s.opts.APISIXRouteVersion, s.opts.APISIXPublishAddress,
_volumeMounts, _webhookCertSecret)
} else {
- ingressDeployment =
fmt.Sprintf(_ingressAPISIXDeploymentTemplate, desired, s.namespace, label,
s.opts.APISIXRouteVersion, s.opts.APISIXPublishAddress, "", _webhookCertSecret)
+ ingressDeployment =
fmt.Sprintf(s.FormatRegistry(_ingressAPISIXDeploymentTemplate), desired,
s.namespace, label, s.opts.APISIXRouteVersion, s.opts.APISIXPublishAddress, "",
_webhookCertSecret)
}
if err := k8s.KubectlApplyFromStringE(s.t, s.kubectlOptions,
ingressDeployment); err != nil {
return err
diff --git a/test/e2e/scaffold/scaffold.go b/test/e2e/scaffold/scaffold.go
index 7d5fa08..0963e9a 100644
--- a/test/e2e/scaffold/scaffold.go
+++ b/test/e2e/scaffold/scaffold.go
@@ -461,6 +461,16 @@ func (s *Scaffold) renderConfig(path string) (string,
error) {
return buf.String(), nil
}
+// FormatRegistry replace default registry to custom registry if exist
+func (s *Scaffold) FormatRegistry(workloadTemplate string) string {
+ customRegistry, isExist := os.LookupEnv("REGISTRY")
+ if isExist {
+ return strings.Replace(workloadTemplate, "localhost:5000",
customRegistry, -1)
+ } else {
+ return workloadTemplate
+ }
+}
+
func waitExponentialBackoff(condFunc func() (bool, error)) error {
backoff := wait.Backoff{
Duration: 500 * time.Millisecond,
diff --git a/test/e2e/scaffold/test_backend.go
b/test/e2e/scaffold/test_backend.go
index 2a1f719..f1b6850 100644
--- a/test/e2e/scaffold/test_backend.go
+++ b/test/e2e/scaffold/test_backend.go
@@ -121,7 +121,7 @@ spec:
)
func (s *Scaffold) newTestBackend() (*corev1.Service, error) {
- backendDeployment := fmt.Sprintf(_testBackendDeploymentTemplate, 1)
+ backendDeployment :=
fmt.Sprintf(s.FormatRegistry(_testBackendDeploymentTemplate), 1)
if err := k8s.KubectlApplyFromStringE(s.t, s.kubectlOptions,
backendDeployment); err != nil {
return nil, err
}