@@ -7,13 +7,13 @@ default:
7
7
all : default
8
8
9
9
help : # # Display this help.
10
- @awk ' BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s \033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST )
10
+ @awk ' BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-20s \033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST )
11
11
12
12
# ###########################################################################
13
13
# Variables
14
14
# ###########################################################################
15
15
16
- IMAGES ?= base-image stateless-lb proxy tapa ipam nsp example-target frontend
16
+ IMAGES ?= base-image stateless-lb proxy tapa ipam nsp example-target frontend operator
17
17
18
18
# Versions
19
19
VERSION ?= latest
@@ -25,6 +25,7 @@ VERSION_NSP ?= $(VERSION)
25
25
VERSION_EXAMPLE_TARGET ?= $(VERSION )
26
26
VERSION_FRONTEND ?= $(VERSION )
27
27
VERSION_BASE_IMAGE ?= $(VERSION )
28
+ VERSION_OPERATOR ?= $(VERSION )
28
29
LOCAL_VERSION ?= $(VERSION )
29
30
30
31
# E2E tests
@@ -33,7 +34,7 @@ E2E_PARAMETERS ?= $(shell cat ./test/e2e/environment/kind-helm/dualstack/config.
33
34
E2E_SEED ?= $(shell shuf -i 1-2147483647 -n1)
34
35
35
36
# Contrainer Registry
36
- REGISTRY ?= localhost:5000 /meridio
37
+ REGISTRY ?= registry.nordix.org/cloud-native /meridio
37
38
BASE_IMAGE ?= $(REGISTRY ) /base-image:$(VERSION_BASE_IMAGE )
38
39
DEBUG_IMAGE ?= $(REGISTRY ) /debug:$(VERSION )
39
40
@@ -45,15 +46,23 @@ MOCKGEN = $(shell pwd)/bin/mockgen
45
46
PROTOC_GEN_GO = $(shell pwd) /bin/protoc-gen-go
46
47
PROTOC_GEN_GO_GRPC = $(shell pwd) /bin/protoc-gen-go-grpc
47
48
NANCY = $(shell pwd) /bin/nancy
49
+ CONTROLLER_GEN = $(shell pwd) /bin/controller-gen
50
+ KUSTOMIZE = $(shell pwd) /bin/kustomize
48
51
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
49
52
50
53
BUILD_DIR ?= build
51
54
BUILD_STEPS ?= build tag push
52
55
56
+ # Security Scan
53
57
OUTPUT_DIR ?= _output
54
-
55
58
SECURITY_SCAN_VOLUME ?= --volume /var/run/docker.sock:/var/run/docker.sock --volume $(HOME ) /Library/Caches:/root/.cache/
56
59
60
+ # Operator
61
+ TEMPLATES_HELM_CHART_VALUES_PATH = config/templates/charts/meridio/values.yaml
62
+ OPERATOR_NAMESPACE = meridio-operator
63
+ ENABLE_MUTATING_WEBHOOK? =true
64
+ WEBHOOK_SUPPORT ?= spire # spire or certmanager
65
+
57
66
# ############################################################################
58
67
# Container: Build, tag, push
59
68
# ############################################################################
73
82
# ############################################################################
74
83
75
84
.PHONY : base-image
76
- base-image : # # Build the base-image
85
+ base-image : # # Build the base-image.
77
86
VERSION=$(VERSION_BASE_IMAGE ) IMAGE=base-image $(MAKE ) -s $(BUILD_STEPS )
78
87
79
88
.PHONY : debug-image
@@ -101,13 +110,17 @@ nsp: ## Build the nsp.
101
110
VERSION=$(VERSION_NSP ) IMAGE=nsp $(MAKE ) -s $(BUILD_STEPS )
102
111
103
112
.PHONY : example-target
104
- example-target :
113
+ example-target : # # Build the example target.
105
114
VERSION=$(VERSION_EXAMPLE_TARGET ) BUILD_DIR=examples/target/build IMAGE=example-target $(MAKE ) $(BUILD_STEPS )
106
115
107
116
.PHONY : frontend
108
117
frontend : # # Build the frontend.
109
118
VERSION=$(VERSION_FRONTEND ) IMAGE=frontend $(MAKE ) -s $(BUILD_STEPS )
110
119
120
+ .PHONY : operator
121
+ operator : # # Build the operator.
122
+ VERSION=$(VERSION_OPERATOR ) IMAGE=operator $(MAKE ) -s $(BUILD_STEPS )
123
+
111
124
# ############################################################################
112
125
# #@ Testing & Code check
113
126
# ############################################################################
@@ -186,6 +199,45 @@ ambassador-proto: proto-compiler
186
199
.PHONY : proto
187
200
proto : ipam-proto nsp-proto ambassador-proto # # Compile the proto.
188
201
202
+ .PHONY : manifests
203
+ manifests : controller-gen # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
204
+ $(CONTROLLER_GEN ) crd rbac:roleName=operator-role webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
205
+
206
+ .PHONY : generate-controller
207
+ generate-controller : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
208
+ $(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
209
+
210
+ # ############################################################################
211
+ # #@ Operator
212
+ # ############################################################################
213
+
214
+ .PHONY : deploy
215
+ deploy : manifests kustomize namespace configure-webhook set-templates-values # # Deploy controller to the K8s cluster specified in ~/.kube/config.
216
+ cd config/operator && $(KUSTOMIZE ) edit set image operator=${REGISTRY} /operator:${VERSION_OPERATOR}
217
+ $(KUSTOMIZE ) build config/default --enable-helm | kubectl apply -f -
218
+
219
+ .PHONY : undeploy
220
+ undeploy : namespace configure-webhook # # Undeploy controller from the K8s cluster specified in ~/.kube/config.
221
+ $(KUSTOMIZE ) build config/default --enable-helm | kubectl delete -f - --ignore-not-found=true
222
+
223
+ .PHONY : set-templates-values
224
+ set-templates-values : # Set the values in the templates helm chart
225
+ sed -i ' s/^version: .*/version: ${VERSION}/' ${TEMPLATES_HELM_CHART_VALUES_PATH} ; \
226
+ sed -i ' s/^registry: .*/registry: $(shell echo ${REGISTRY} | cut -d "/" -f 1)/' ${TEMPLATES_HELM_CHART_VALUES_PATH} ; \
227
+ sed -i ' s#^organization: .*#organization: $(shell echo ${REGISTRY} | cut -d "/" -f 2-)#' ${TEMPLATES_HELM_CHART_VALUES_PATH}
228
+
229
+ .PHONY : namespace
230
+ namespace : # Edit the namespace of operator to be deployed
231
+ cd config/default && $(KUSTOMIZE ) edit set namespace ${OPERATOR_NAMESPACE}
232
+
233
+ .PHONY : print-manifests
234
+ print-manifests : manifests kustomize namespace configure-webhook set-templates-values # Generate manifests to be deployed in the cluster
235
+ cd config/operator && $(KUSTOMIZE ) edit set image operator=${REGISTRY} /operator:${VERSION_OPERATOR}
236
+ $(KUSTOMIZE ) build config/default --enable-helm
237
+
238
+ configure-webhook :
239
+ ENABLE_MUTATING_WEBHOOK=$(ENABLE_MUTATING_WEBHOOK ) WEBHOOK_SUPPORT=$(WEBHOOK_SUPPORT ) hack/webhook-switch.sh
240
+
189
241
# ############################################################################
190
242
# Tools
191
243
# ############################################################################
@@ -227,6 +279,14 @@ ginkgo:
227
279
nancy-tool :
228
280
$(call go-get-tool,$(NANCY ) ,github.com/sonatype-nexus-community/[email protected] )
229
281
282
+ .PHONY : controller-gen
283
+ controller-gen :
284
+ $(call go-get-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/[email protected] )
285
+
286
+ .PHONY : kustomize
287
+ kustomize :
288
+ $(call go-get-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/[email protected] )
289
+
230
290
# go-get-tool will 'go get' any package $2 and install it to $1.
231
291
define go-get-tool
232
292
@[ -f $(1 ) ] || { \
@@ -238,4 +298,4 @@ echo "Downloading $(2)" ;\
238
298
GOBIN=$(PROJECT_DIR ) /bin go install $(2 ) ;\
239
299
rm -rf $$TMP_DIR ;\
240
300
}
241
- endef
301
+ endef
0 commit comments