Skip to content

Commit 9e69bc9

Browse files
committed
feat: added make targets to manage tools
Signed-off-by: Mateusz Urbanek <[email protected]>
1 parent d662406 commit 9e69bc9

File tree

11 files changed

+2483
-51
lines changed

11 files changed

+2483
-51
lines changed

Makefile

Lines changed: 85 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -98,37 +98,6 @@ clobber:
9898
$(MAKE) -C proto clobber
9999
rm -rf $(CURDIR)/.cache
100100

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-
132101
##
133102
## === INTERMEDIATES === #
134103

@@ -160,3 +129,88 @@ golangci-lint-fix.%: $(GOLANGCI_LINT)
160129

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