Skip to content

Commit 15bf2bb

Browse files
authored
Merge pull request #108 from shanduur/make-test
Added make targets to run E2E tests on ephemeral clusters
2 parents d662406 + 3eb11da commit 15bf2bb

File tree

12 files changed

+2484
-56
lines changed

12 files changed

+2484
-56
lines changed

Makefile

Lines changed: 84 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ CONTROLLER_TAG ?= cosi-controller:latest
4141
## Image tag for sidecar image build
4242
SIDECAR_TAG ?= cosi-provisioner-sidecar:latest
4343

44+
## Location to install dependencies to
45+
TOOLBIN ?= $(CURDIR)/.cache/tools
46+
$(TOOLBIN):
47+
mkdir -p $(TOOLBIN)
48+
4449
##@ Development
4550

4651
.PHONY: all .gen
@@ -66,16 +71,15 @@ vet: vet.client vet.controller vet.sidecar ## Vet code
6671
test: .test.proto test.client test.controller test.sidecar ## Run tests including unit tests
6772

6873
.PHONY: test-e2e
69-
test-e2e: # Run e2e tests
70-
@echo "unimplemented placeholder"
74+
test-e2e: chainsaw # Run e2e tests against the K8s cluster specified in ~/.kube/config. It requires both controller and driver deployed. If you need to create a cluster beforehand, consider using 'cluster' and 'deploy' targets.
75+
$(CHAINSAW) test --values ./test/e2e/values.yaml
7176

7277
.PHONY: lint
7378
lint: golangci-lint.client golangci-lint.controller golangci-lint.sidecar ## Run all linters (suggest `make -k`)
7479

7580
.PHONY: lint-fix
7681
lint-fix: golangci-lint-fix.client golangci-lint-fix.controller golangci-lint-fix.sidecar ## Run all linters and perform fixes where possible (suggest `make -k`)
7782

78-
7983
##@ Build
8084

8185
.PHONY: build
@@ -96,39 +100,9 @@ clean:
96100
## Clean build environment and cached tools
97101
clobber:
98102
$(MAKE) -C proto clobber
103+
rm -rf $(TOOLBIN)
99104
rm -rf $(CURDIR)/.cache
100105

101-
##
102-
## === TOOLS === #
103-
104-
GOLANGCI_LINT_VERSION ?= v1.61.0
105-
106-
TOOLBIN ?= $(CURDIR)/.cache/tools
107-
$(TOOLBIN):
108-
mkdir -p $(TOOLBIN)
109-
110-
GOLANGCI_LINT ?= $(TOOLBIN)/golangci-lint
111-
# .PHONY: golangci-lint
112-
# golangci-lint: $(GOLANGCI_LINT)
113-
$(GOLANGCI_LINT): $(TOOLBIN)
114-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
115-
116-
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
117-
# $1 - target path with name of binary
118-
# $2 - package url which can be installed
119-
# $3 - specific version of package
120-
define go-install-tool
121-
@[ -f "$(1)-$(3)" ] || { \
122-
set -e; \
123-
package=$(2)@$(3) ;\
124-
echo "Downloading $${package}" ;\
125-
rm -f $(1) || true ;\
126-
GOBIN=$(TOOLBIN) go install $${package} ;\
127-
mv $(1) $(1)-$(3) ;\
128-
} ;\
129-
ln -sf $(1)-$(3) $(1)
130-
endef
131-
132106
##
133107
## === INTERMEDIATES === #
134108

@@ -160,3 +134,79 @@ golangci-lint-fix.%: $(GOLANGCI_LINT)
160134

161135
.PHONY: FORCE # use this to force phony behavior for targets with pattern rules
162136
FORCE:
137+
138+
##@ Deployment
139+
140+
.PHONY: cluster
141+
cluster: kind ctlptl ## Create Kind cluster and local registry
142+
$(CTLPTL) apply -f ctlptl.yaml
143+
144+
.PHONY: cluster-reset
145+
cluster-reset: kind ctlptl ## Delete Kind cluster
146+
$(CTLPTL) delete -f ctlptl.yaml
147+
148+
.PHONY: deploy
149+
deploy: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. The 'generate' and 'codegen' targets should be run manually, and are expected to be run at least once before the 'deploy' target, as those are not cached.
150+
$(KUSTOMIZE) build . | $(KUBECTL) apply -f -
151+
152+
.PHONY: undeploy
153+
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
154+
$(KUSTOMIZE) build . | $(KUBECTL) delete --ignore-not-found=true -f -
155+
156+
##@ Tools
157+
158+
## Tool Binaries
159+
CHAINSAW ?= $(TOOLBIN)/chainsaw
160+
CTLPTL ?= $(TOOLBIN)/ctlptl
161+
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
162+
KIND ?= $(TOOLBIN)/kind
163+
KUBECTL ?= kubectl ## Special case, we do not manage it via tools.go
164+
KUSTOMIZE ?= $(TOOLBIN)/kustomize
165+
166+
## Tool Versions
167+
CHAINSAW_VERSION ?= $(shell grep 'github.com/kyverno/chainsaw ' ./hack/tools/go.mod | cut -d ' ' -f 2)
168+
CTLPTL_VERSION ?= $(shell grep 'github.com/tilt-dev/ctlptl ' ./hack/tools/go.mod | cut -d ' ' -f 2)
169+
GOLANGCI_LINT_VERSION ?= $(shell grep 'github.com/golangci/golangci-lint ' ./hack/tools/go.mod | cut -d ' ' -f 2)
170+
KIND_VERSION ?= $(shell grep 'sigs.k8s.io/kind ' ./hack/tools/go.mod | cut -d ' ' -f 2)
171+
KUSTOMIZE_VERSION ?= $(shell grep 'sigs.k8s.io/kustomize/kustomize/v5 ' ./hack/tools/go.mod | cut -d ' ' -f 2)
172+
173+
.PHONY: chainsaw
174+
chainsaw: $(CHAINSAW)$(CHAINSAW_VERSION) ## Download chainsaw locally if necessary.
175+
$(CHAINSAW)$(CHAINSAW_VERSION): $(TOOLBIN)
176+
$(call go-install-tool,$(CHAINSAW),github.com/kyverno/chainsaw,$(CHAINSAW_VERSION))
177+
178+
.PHONY: ctlptl
179+
ctlptl: $(CTLPTL)$(CTLPTL_VERSION) ## Download ctlptl locally if necessary.
180+
$(CTLPTL)$(CTLPTL_VERSION): $(TOOLBIN)
181+
$(call go-install-tool,$(CTLPTL),github.com/tilt-dev/ctlptl/cmd/ctlptl,$(CTLPTL_VERSION))
182+
183+
.PHONY: golangci-lint
184+
golangci-lint: $(GOLANGCI_LINT)$(GOLANGCI_LINT_VERSION) ## Download golangci-lint locally if necessary.
185+
$(GOLANGCI_LINT)$(GOLANGCI_LINT_VERSION): $(LOCALBIN)
186+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
187+
188+
.PHONY: kind
189+
kind: $(KIND)$(KIND_VERSION) ## Download kind locally if necessary.
190+
$(KIND)$(KIND_VERSION): $(TOOLBIN)
191+
$(call go-install-tool,$(KIND),sigs.k8s.io/kind,$(KIND_VERSION))
192+
193+
.PHONY: kustomize
194+
kustomize: $(KUSTOMIZE)$(KUSTOMIZE_VERSION) ## Download kustomize locally if necessary.
195+
$(KUSTOMIZE)$(KUSTOMIZE_VERSION): $(TOOLBIN)
196+
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION))
197+
198+
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
199+
# $1 - target path with name of binary
200+
# $2 - package url which can be installed
201+
# $3 - specific version of package
202+
define go-install-tool
203+
@[ -f "$(1)-$(3)" ] || { \
204+
set -e; \
205+
package=$(2)@$(3) ;\
206+
echo "Downloading $${package}" ;\
207+
rm -f $(1) || true ;\
208+
GOBIN=$(TOOLBIN) go install $${package} ;\
209+
mv $(1) $(1)-$(3) ;\
210+
} ;\
211+
ln -sf $(1)-$(3) $(1)
212+
endef

controller/kustomization.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
apiVersion: kustomize.config.k8s.io/v1beta1
33
kind: Kustomization
4+
namespace: container-object-storage-system
5+
namePrefix: container-object-storage-
46

57
labels:
68
- includeTemplates: true
@@ -11,6 +13,7 @@ labels:
1113
app.kubernetes.io/managed-by: kustomize
1214

1315
resources:
14-
- resources/sa.yaml
15-
- resources/rbac.yaml
16-
- resources/deployment.yaml
16+
- resources/deployment.yaml
17+
- resources/namespace.yaml
18+
- resources/rbac.yaml
19+
- resources/sa.yaml

controller/resources/deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
kind: Deployment
33
apiVersion: apps/v1
44
metadata:
5-
name: objectstorage-controller
5+
name: controller
66
labels:
77
app: container-object-storage-interface-controller
88
spec:
@@ -19,7 +19,7 @@ spec:
1919
labels:
2020
app: container-object-storage-interface-controller
2121
spec:
22-
serviceAccountName: objectstorage-controller-sa
22+
serviceAccountName: controller-sa
2323
containers:
2424
- name: objectstorage-controller
2525
image: gcr.io/k8s-staging-sig-storage/objectstorage-controller:v20221027-v0.1.1-8-g300019f
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
kind: Namespace
3+
apiVersion: v1
4+
metadata:
5+
name: system

controller/resources/rbac.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
kind: ClusterRole
33
apiVersion: rbac.authorization.k8s.io/v1
44
metadata:
5-
name: objectstorage-controller-role
5+
name: controller-role
66
namespace: default
77
rules:
88
- apiGroups: ["objectstorage.k8s.io"]
@@ -24,7 +24,7 @@ rules:
2424
kind: ClusterRoleBinding
2525
apiVersion: rbac.authorization.k8s.io/v1
2626
metadata:
27-
name: objectstorage-controller
27+
name: controller
2828
namespace: default
2929
labels:
3030
app.kubernetes.io/part-of: container-object-storage-interface
@@ -33,17 +33,17 @@ metadata:
3333
app.kubernetes.io/name: container-object-storage-interface-controller
3434
subjects:
3535
- kind: ServiceAccount
36-
name: objectstorage-controller-sa
36+
name: controller-sa
3737
namespace: default
3838
roleRef:
3939
kind: ClusterRole
40-
name: objectstorage-controller-role
40+
name: controller-role
4141
apiGroup: rbac.authorization.k8s.io
4242
---
4343
kind: Role
4444
apiVersion: rbac.authorization.k8s.io/v1
4545
metadata:
46-
name: objectstorage-controller
46+
name: controller
4747
namespace: default
4848
labels:
4949
app.kubernetes.io/part-of: container-object-storage-interface
@@ -58,7 +58,7 @@ rules:
5858
kind: RoleBinding
5959
apiVersion: rbac.authorization.k8s.io/v1
6060
metadata:
61-
name: objectstorage-controller
61+
name: controller
6262
namespace: default
6363
labels:
6464
app.kubernetes.io/part-of: container-object-storage-interface
@@ -67,9 +67,9 @@ metadata:
6767
app.kubernetes.io/name: container-object-storage-interface-controller
6868
subjects:
6969
- kind: ServiceAccount
70-
name: objectstorage-controller-sa
70+
name: controller-sa
7171
namespace: default
7272
roleRef:
7373
kind: Role
74-
name: objectstorage-controller
74+
name: controller
7575
apiGroup: rbac.authorization.k8s.io

controller/resources/sa.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
apiVersion: v1
33
kind: ServiceAccount
44
metadata:
5-
name: objectstorage-controller-sa
5+
name: controller-sa

ctlptl.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ apiVersion: ctlptl.dev/v1alpha1
88
kind: Cluster
99
product: kind
1010
registry: ctlptl-registry
11+
kindV1Alpha4Cluster:
12+
nodes:
13+
- role: control-plane
14+
image: kindest/node:v1.31.1

0 commit comments

Comments
 (0)