Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support custom registry for e2e test #896

Merged
merged 7 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ default: help
VERSION ?= 1.4.0
RELEASE_SRC = apache-apisix-ingress-controller-${VERSION}-src
LOCAL_REGISTRY="localhost:5000"
CUSTOM_REGISTRY ?= ""
Belyenochi marked this conversation as resolved.
Show resolved Hide resolved
IMAGE_TAG ?= dev

GITSHA ?= "no-git-module"
Expand Down Expand Up @@ -65,10 +66,11 @@ unit-test:

### e2e-test: Run e2e test cases (kind is required)
.PHONY: e2e-test
e2e-test: ginkgo-check push-images-to-kind
e2e-test: ginkgo-check push-images-to-kind push-images-to-custom-registry
kubectl apply -k $(PWD)/samples/deploy/crd
cd test/e2e \
&& go mod download \
&& export CUSTOM_REGISTRY=$(CUSTOM_REGISTRY)
&& ACK_GINKGO_RC=true ginkgo -cover -coverprofile=coverage.txt -r --randomizeSuites --randomizeAllSpecs --trace --nodes=$(E2E_CONCURRENCY)

.PHONY: ginkgo-check
Expand All @@ -78,9 +80,45 @@ ifeq ("$(wildcard $(GINKGO))", "")
exit 1
endif

### push-images-to-custom-registry: Push images used in e2e test suites to custom registry.
.PHONY: push-images-to-custom-registry
push-images-to-custom-registry:
ifdef CUSTOM_REGISTRY
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 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 pull kennethreitz/httpbin
docker tag kennethreitz/httpbin $(LOCAL_REGISTRY)/kennethreitz/httpbin
docker push $(LOCAL_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 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 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 pull busybox:1.28
docker tag busybox:1.28 $(LOCAL_REGISTRY)/busybox:1.28
docker push $(LOCAL_REGISTRY)/busybox:1.28
endif
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
ifndef CUSTOM_REGISTRY
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
Expand Down Expand Up @@ -110,6 +148,7 @@ ifeq ($(E2E_SKIP_BUILD), 0)
docker tag busybox:1.28 $(LOCAL_REGISTRY)/busybox:1.28
docker push $(LOCAL_REGISTRY)/busybox:1.28
endif
endif

### kind-up: Launch a Kubernetes cluster with a image registry by Kind.
.PHONY: kind-up
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ Run `make e2e-test` to run the e2e test suites in your development environment,
2. Build and push all related images to this cluster.
3. Run e2e test suites.

If you want to run e2e tests in an existing cluster, you can specify it by passing CUSTOM_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.

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/scaffold/apisix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/scaffold/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/scaffold/httpbin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/scaffold/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/scaffold/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("CUSTOM_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,
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/scaffold/test_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down