Skip to content

Commit d2aa44d

Browse files
ansdChunyiLyu
andcommitted
Use setup-envtest
Use https://github.com/kubernetes-sigs/controller-runtime/tree/master/tools/setup-envtest since we want self-contained test dependencies for our integration tests. Migrate PROJECT file to kubebuilder v3 see https://kubebuilder.io/migration/manually_migration_guide_v2_v3.html Delete webhook files We don't use a webhook in the cluster-operator at the moment. Therefore delete the files. If we need a webhook in the future, we can easily re-create the files using 'kubebuilder create webhook' command. Rename flag metrics-addr to metrics-bind-address as described in https://kubebuilder.io/migration/manually_migration_guide_v2_v3.html#rename-the-manager-flags and kubernetes-sigs/kubebuilder#1839 Co-authored-by: Chunyi Lyu <[email protected]>
1 parent 9906e49 commit d2aa44d

File tree

16 files changed

+50
-183
lines changed

16 files changed

+50
-183
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ cover.out
55
.envrc
66
tags
77
releases/
8+
testbin/

Makefile

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
1+
SHELL := bash
2+
platform := $(shell uname | tr A-Z a-z)
3+
14
.DEFAULT_GOAL = help
25
.PHONY: help
36
help:
47
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
58

6-
unit-tests: install-tools generate fmt vet manifests ## Run unit tests
9+
ENVTEST_K8S_VERSION = 1.20.2
10+
ARCHITECTURE = amd64
11+
LOCAL_TESTBIN = $(CURDIR)/testbin
12+
# "Control plane binaries (etcd and kube-apiserver) are loaded by default from /usr/local/kubebuilder/bin.
13+
# This can be overridden by setting the KUBEBUILDER_ASSETS environment variable"
14+
# https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/envtest
15+
export KUBEBUILDER_ASSETS = $(LOCAL_TESTBIN)/k8s/$(ENVTEST_K8S_VERSION)-$(platform)-$(ARCHITECTURE)
16+
17+
$(KUBEBUILDER_ASSETS):
18+
setup-envtest --os $(platform) --arch $(ARCHITECTURE) --bin-dir $(LOCAL_TESTBIN) use $(ENVTEST_K8S_VERSION)
19+
20+
.PHONY: unit-tests
21+
unit-tests: install-tools $(KUBEBUILDER_ASSETS) generate fmt vet manifests ## Run unit tests
722
ginkgo -r --randomizeAllSpecs api/ internal/
823

9-
integration-tests: install-tools generate fmt vet manifests ## Run integration tests
24+
.PHONY: integration-tests
25+
integration-tests: install-tools $(KUBEBUILDER_ASSETS) generate fmt vet manifests ## Run integration tests
1026
ginkgo -r controllers/
1127

12-
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
13-
CRD_OPTIONS ?= "crd:trivialVersions=true, preserveUnknownFields=false, crdVersions=v1"
28+
CRD_OPTIONS ?= "crd:trivialVersions=true, preserveUnknownFields=false"
1429

1530
manifests: install-tools ## Generate manifests e.g. CRD, RBAC etc.
1631
controller-gen $(CRD_OPTIONS) rbac:roleName=operator-role paths="./api/...;./controllers/..." output:crd:artifacts:config=config/crd/bases

PROJECT

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1-
version: "2"
21
domain: rabbitmq.com
2+
layout:
3+
- go.kubebuilder.io/v3
4+
projectName: cluster-operator
35
repo: github.com/rabbitmq/cluster-operator
6+
resources:
7+
- api:
8+
crdVersion: v1
9+
namespaced: true
10+
controller: true
11+
domain: rabbitmq.com
12+
group: rabbitmq.com
13+
kind: RabbitmqCluster
14+
path: github.com/rabbitmq/cluster-operator/api/v1beta1
15+
version: v1beta1
16+
version: "3"

api/v1beta1/suite_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,5 @@ var _ = BeforeSuite(func() {
5757

5858
var _ = AfterSuite(func() {
5959
By("tearing down the test environment")
60-
err := testEnv.Stop()
61-
Expect(err).ToNot(HaveOccurred())
60+
Expect(testEnv.Stop()).To(Succeed())
6261
})

config/certmanager/certificate.yaml

Lines changed: 0 additions & 33 deletions
This file was deleted.

config/certmanager/kustomization.yaml

Lines changed: 0 additions & 31 deletions
This file was deleted.

config/certmanager/kustomizeconfig.yaml

Lines changed: 0 additions & 25 deletions
This file was deleted.

config/crd/bases/rabbitmq.com_rabbitmqclusters.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ apiVersion: apiextensions.k8s.io/v1
1010
kind: CustomResourceDefinition
1111
metadata:
1212
annotations:
13-
controller-gen.kubebuilder.io/version: v0.6.0
13+
controller-gen.kubebuilder.io/version: v0.6.1
1414
creationTimestamp: null
1515
name: rabbitmqclusters.rabbitmq.com
1616
spec:

config/crd/kustomization.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ resources:
1616

1717
patches:
1818
- patches/crd_labels_patch.yaml
19-
# patches here are for enabling the conversion webhook for each CRD
20-
#- patches/webhook_in_rabbitmqcluster.yaml
21-
# +kubebuilder:scaffold:kustomizepatch
2219

2320
# the following config is for teaching kustomize how to do kustomization for CRDs.
2421
configurations:

config/crd/patches/webhook_in_rabbitmqcluster.yaml

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)