Skip to content

Commit 47485a7

Browse files
authored
Adding e2e make target, makefile adjustments, and e2e test framework (#81)
* Adding e2e make target, makefile adjustments, and e2e test framework * addressing comments * added e2e github action and added pending tag to test * back-out scoping change * disable -j flag for make Signed-off-by: dtfranz <[email protected]>
1 parent edece37 commit 47485a7

File tree

6 files changed

+163
-7
lines changed

6 files changed

+163
-7
lines changed

.github/workflows/e2e.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: e2e
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
10+
jobs:
11+
e2e-kind:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v1
15+
- uses: actions/setup-go@v3
16+
with:
17+
go-version-file: "go.mod"
18+
- name: Run e2e tests
19+
run: |
20+
make e2e

Makefile

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
1+
###########################
2+
# Configuration Variables #
3+
###########################
24
# Image URL to use all building/pushing image targets
3-
IMG ?= controller:latest
5+
export IMAGE_REPO ?= quay.io/operator-framework/operator-controller
6+
export IMAGE_TAG ?= devel
7+
export GO_BUILD_TAGS ?= upstream
8+
IMG?=$(IMAGE_REPO):$(IMAGE_TAG)
9+
10+
OPERATOR_CONTROLLER_NAMESPACE ?= operator-controller-system
11+
KIND_CLUSTER_NAME ?= operator-controller
12+
413
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
514
ENVTEST_K8S_VERSION = 1.25.0
615

@@ -16,6 +25,9 @@ endif
1625
SHELL = /usr/bin/env bash -o pipefail
1726
.SHELLFLAGS = -ec
1827

28+
# Disable -j flag for make
29+
.NOTPARALLEL:
30+
1931
.PHONY: all
2032
all: build
2133

@@ -54,25 +66,46 @@ fmt: ## Run go fmt against code.
5466
vet: ## Run go vet against code.
5567
go vet ./...
5668

57-
.PHONY: test
58-
test: manifests generate fmt vet envtest ## Run tests.
69+
.PHONY: test test-e2e e2e kind-load kind-cluster kind-cluster-cleanup
70+
test: manifests generate fmt vet envtest test-e2e ## Run all tests.
5971
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
6072

73+
FOCUS := $(if $(TEST),-v -focus "$(TEST)")
74+
E2E_FLAGS ?= ""
75+
test-e2e: ginkgo ## Run the e2e tests
76+
$(GINKGO) --tags $(GO_BUILD_TAGS) $(E2E_FLAGS) -trace -progress $(FOCUS) test/e2e
77+
78+
e2e: KIND_CLUSTER_NAME=operator-controller-e2e
79+
e2e: run test-e2e kind-cluster-cleanup ## Run e2e test suite on local kind cluster
80+
81+
kind-load: kind ## Loads the currently constructed image onto the cluster
82+
$(KIND) load docker-image $(IMG) --name $(KIND_CLUSTER_NAME)
83+
84+
kind-cluster: kind kind-cluster-cleanup ## Standup a kind cluster
85+
$(KIND) create cluster --name ${KIND_CLUSTER_NAME}
86+
$(KIND) export kubeconfig --name ${KIND_CLUSTER_NAME}
87+
88+
kind-cluster-cleanup: kind ## Delete the kind cluster
89+
$(KIND) delete cluster --name ${KIND_CLUSTER_NAME}
90+
6191
##@ Build
6292

6393
.PHONY: build
6494
build: manifests generate fmt vet ## Build manager binary.
6595
go build -o bin/manager main.go
6696

6797
.PHONY: run
68-
run: manifests generate fmt vet ## Run a controller from your host.
69-
go run ./main.go
98+
run: docker-build kind-cluster kind-load install deploy wait ## Build the operator-controller then deploy it into a new kind cluster.
99+
100+
.PHONY: wait
101+
wait:
102+
kubectl wait --for=condition=Available --namespace=$(OPERATOR_CONTROLLER_NAMESPACE) deployment/operator-controller-controller-manager --timeout=60s
70103

71104
# If you wish built the manager image targeting other platforms you can use the --platform flag.
72105
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
73106
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
74107
.PHONY: docker-build
75-
docker-build: test ## Build docker image with the manager.
108+
docker-build: generate ## Build docker image with the operator-controller.
76109
docker build -t ${IMG} .
77110

78111
.PHONY: docker-push
@@ -129,12 +162,24 @@ $(LOCALBIN):
129162
## Tool Binaries
130163
KUSTOMIZE ?= $(LOCALBIN)/kustomize
131164
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
165+
KIND ?= $(LOCALBIN)/kind
166+
GINKGO ?= $(LOCALBIN)/ginkgo
132167
ENVTEST ?= $(LOCALBIN)/setup-envtest
133168

134169
## Tool Versions
135170
KUSTOMIZE_VERSION ?= v4.5.7
136171
CONTROLLER_TOOLS_VERSION ?= v0.10.0
137172

173+
.PHONY: kind
174+
kind: $(KIND) ## Download kind locally if necessary.
175+
$(KIND): $(LOCALBIN)
176+
test -s $(LOCALBIN)/kind || GOBIN=$(LOCALBIN) go install sigs.k8s.io/[email protected]
177+
178+
.PHONY: ginkgo
179+
ginkgo: $(GINKGO) ## Download ginkgo locally if necessary.
180+
$(GINKGO): $(LOCALBIN)
181+
test -s $(LOCALBIN)/ginkgo || GOBIN=$(LOCALBIN) go install github.com/onsi/ginkgo/v2/[email protected]
182+
138183
KUSTOMIZE_INSTALL_SCRIPT ?= "https://github.com/raw/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
139184
.PHONY: kustomize
140185
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.

config/manager/kustomization.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
resources:
22
- manager.yaml
3+
apiVersion: kustomize.config.k8s.io/v1beta1
4+
kind: Kustomization
5+
images:
6+
- name: controller
7+
newName: quay.io/operator-framework/operator-controller
8+
newTag: devel

config/manager/manager.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ spec:
7171
args:
7272
- --leader-elect
7373
image: controller:latest
74+
imagePullPolicy: IfNotPresent
7475
name: manager
7576
securityContext:
7677
allowPrivilegeEscalation: false

test/e2e/e2e_suite_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package e2e
2+
3+
import (
4+
"testing"
5+
"time"
6+
7+
. "github.com/onsi/ginkgo/v2"
8+
. "github.com/onsi/gomega"
9+
"k8s.io/apimachinery/pkg/runtime"
10+
"k8s.io/client-go/rest"
11+
ctrl "sigs.k8s.io/controller-runtime"
12+
"sigs.k8s.io/controller-runtime/pkg/client"
13+
14+
operatorv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
15+
)
16+
17+
var (
18+
cfg *rest.Config
19+
c client.Client
20+
)
21+
22+
func TestE2E(t *testing.T) {
23+
RegisterFailHandler(Fail)
24+
SetDefaultEventuallyTimeout(1 * time.Minute)
25+
SetDefaultEventuallyPollingInterval(1 * time.Second)
26+
RunSpecs(t, "E2E Suite")
27+
}
28+
29+
var _ = BeforeSuite(func() {
30+
cfg = ctrl.GetConfigOrDie()
31+
32+
scheme := runtime.NewScheme()
33+
err := operatorv1alpha1.AddToScheme(scheme)
34+
Expect(err).To(Not(HaveOccurred()))
35+
36+
c, err = client.New(cfg, client.Options{Scheme: scheme})
37+
Expect(err).To(Not(HaveOccurred()))
38+
})

test/e2e/reconcile_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package e2e
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
"k8s.io/apimachinery/pkg/util/rand"
9+
10+
. "github.com/onsi/ginkgo/v2"
11+
. "github.com/onsi/gomega"
12+
operatorv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
13+
)
14+
15+
var _ = Describe("Operator Install", func() {
16+
When("a valid Operator CR specifying a package", func() {
17+
var (
18+
operator *operatorv1alpha1.Operator
19+
ctx context.Context
20+
err error
21+
)
22+
BeforeEach(func() {
23+
ctx = context.Background()
24+
25+
operator = &operatorv1alpha1.Operator{
26+
ObjectMeta: metav1.ObjectMeta{
27+
Name: fmt.Sprintf("operator-%s", rand.String(8)),
28+
},
29+
Spec: operatorv1alpha1.OperatorSpec{
30+
PackageName: "my-cool-package",
31+
},
32+
}
33+
err = c.Create(ctx, operator)
34+
Expect(err).To(Not(HaveOccurred()))
35+
})
36+
AfterEach(func() {
37+
By("deleting the testing Operator resource")
38+
err = c.Delete(ctx, operator)
39+
Expect(err).To(Not(HaveOccurred()))
40+
})
41+
PIt("installs the specified package", func() {
42+
// Pending until we actually have some code to test
43+
// Expect that a CRD and Deployment were successfully installed by rukpak
44+
})
45+
})
46+
})

0 commit comments

Comments
 (0)