Skip to content

Commit 818b5f9

Browse files
authored
Controller tests setup (#495)
1 parent d60e6a0 commit 818b5f9

File tree

4 files changed

+226
-172
lines changed

4 files changed

+226
-172
lines changed

Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ RESOURCE_PREFIX ?= flink-operator-
1111
# The Kubernetes namespace to limit watching.
1212
WATCH_NAMESPACE ?=
1313

14+
# Env test configuration
15+
ENVTEST_K8S_VERSION=1.25.0
16+
SETUP_ENVTEST_VERSION=v0.0.0-20221007015352-8ad090e0663e
17+
LOCALBIN=$(shell pwd)/bin
18+
1419
all: build
1520

1621
##@ General
@@ -56,8 +61,7 @@ vet: ## Run go vet against code.
5661
test: manifests generate fmt vet tidy kustomize envtest ## Run tests.
5762
rm -rf config/test && mkdir -p config/test/crd
5863
$(KUSTOMIZE) build config/crd > config/test/crd/flinkoperator.k8s.io_flinkclusters.yaml
59-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
60-
64+
KUBEBUILDER_ASSETS=$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path) go test ./... -coverprofile cover.out
6165
##@ Build
6266

6367
build: generate fmt vet tidy ## Build manager binary.
@@ -125,7 +129,8 @@ kustomize: ## Download kustomize locally if necessary.
125129
ENVTEST = $(shell pwd)/bin/setup-envtest
126130
.PHONY: envtest
127131
envtest: ## Download envtest-setup locally if necessary.
128-
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
132+
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@$(SETUP_ENVTEST_VERSION))
133+
129134

130135
CRD_REF_DOCS = $(shell pwd)/bin/crd-ref-docs
131136
crd-ref-docs:
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package flinkcluster
2+
3+
import (
4+
. "github.com/onsi/ginkgo/v2"
5+
. "github.com/onsi/gomega"
6+
appsv1 "k8s.io/api/apps/v1"
7+
"k8s.io/apimachinery/pkg/types"
8+
"time"
9+
)
10+
11+
var _ = Describe("FlinkCluster Controller", func() {
12+
// Utility constants and functions here
13+
const (
14+
timeout = time.Second * 10
15+
duration = time.Second * 10
16+
interval = time.Millisecond * 250
17+
)
18+
19+
Context("When creating a new FlinkCluster", func() {
20+
It("Should create the JobManager Statefulset", func() {
21+
// Test code here
22+
By("By creating a new FlinkCluster")
23+
dummyFlinkCluster := getDummyFlinkCluster()
24+
Expect(k8sClient.Create(ctx, dummyFlinkCluster)).Should(Succeed())
25+
26+
expectedJobManagerName := dummyFlinkCluster.ObjectMeta.Name + "-jobmanager"
27+
jobManagerLookupKey := types.NamespacedName{Name: expectedJobManagerName, Namespace: dummyFlinkCluster.ObjectMeta.Namespace}
28+
createdJobManagerStatefulSet := &appsv1.StatefulSet{}
29+
30+
Eventually(func() bool {
31+
err := k8sClient.Get(ctx, jobManagerLookupKey, createdJobManagerStatefulSet)
32+
if err != nil {
33+
return false
34+
}
35+
return true
36+
}, timeout, interval).Should(BeTrue())
37+
38+
})
39+
})
40+
})

0 commit comments

Comments
 (0)