forked from metallb/metallb-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·266 lines (212 loc) · 10.3 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
SHELL := /bin/bash
# Current Operator version
VERSION ?= main
CSV_VERSION = $(shell echo $(VERSION) | sed 's/v//')
ifeq ($(VERSION), main)
CSV_VERSION := 0.0.0
endif
# Default image repo
REPO ?= quay.io/metallb
# Image URL to use all building/pushing image targets
IMG ?= $(REPO)/metallb-operator:$(VERSION)
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:crdVersions=v1"
#Which dir to use in deploy kustomize build
KUSTOMIZE_DEPLOY_DIR ?= config/default
# Route to operator-sdk binary
OPERATOR_SDK=_cache/operator-sdk
# Default bundle image tag
BUNDLE_IMG ?= $(REPO)/metallb-operator-bundle:$(VERSION)
# Default bundle index image tag
BUNDLE_INDEX_IMG ?= $(REPO)/metallb-operator-bundle-index:$(VERSION)
# Options for 'bundle'
ifneq ($(origin CHANNELS), undefined)
BUNDLE_CHANNELS := --channels=$(CHANNELS)
endif
ifneq ($(origin DEFAULT_CHANNEL), undefined)
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
# Default namespace
NAMESPACE ?= metallb-system
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
OPERATOR_SDK_VERSION=v1.26.1
OLM_VERSION=v0.18.3
OPM_VERSION=v1.23.2
KUSTOMIZE_VERSION=v5.0.1
KUSTOMIZE=$(shell pwd)/_cache/kustomize
OPM_TOOL_URL=https://api.github.com/repos/operator-framework/operator-registry/releases
TESTS_REPORTS_PATH ?= /tmp/test_e2e_logs/
VALIDATION_TESTS_REPORTS_PATH ?= /tmp/test_validation_logs/
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
test: generate fmt vet manifests ## Run unit and integration tests
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.3/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
all: manager ## Default make target if no options specified
test-validation: generate fmt vet manifests ## Run validation tests
rm -rf ${VALIDATION_TESTS_REPORTS_PATH}
mkdir -p ${VALIDATION_TESTS_REPORTS_PATH}
USE_LOCAL_RESOURCES=true go test --tags=validationtests -v ./test/e2e/validation -ginkgo.v -junit $(VALIDATION_TESTS_REPORTS_PATH) -report $(VALIDATION_TESTS_REPORTS_PATH)
test-functional: generate fmt vet manifests ## Run e2e tests
rm -rf ${TESTS_REPORTS_PATH}
mkdir -p ${TESTS_REPORTS_PATH}
USE_LOCAL_RESOURCES=true go test --tags=e2etests -v ./test/e2e/functional -ginkgo.v -junit $(TESTS_REPORTS_PATH) -report $(TESTS_REPORTS_PATH)
test-e2e: generate fmt vet manifests test-validation test-functional ## Run e2e tests
manager: generate fmt vet ## Build manager binary
go build -ldflags "-X main.build=$$(git rev-parse HEAD)" -o bin/manager main.go
run: generate fmt vet manifests ## Run against the configured cluster
go run ./main.go
install: manifests kustomize ## Install CRDs into a cluster
$(KUSTOMIZE) build config/crd | kubectl apply -f -
uninstall: manifests kustomize ## Uninstall CRDs from a cluster
$(KUSTOMIZE) build config/crd | kubectl delete -f -
deploy: manifests kustomize ## Deploy controller in the configured cluster
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
cd $(KUSTOMIZE_DEPLOY_DIR) && $(KUSTOMIZE) edit set namespace $(NAMESPACE)
cd config/metallb_rbac && $(KUSTOMIZE) edit set namespace $(NAMESPACE)
$(KUSTOMIZE) build $(KUSTOMIZE_DEPLOY_DIR) | kubectl apply -f -
$(KUSTOMIZE) build config/metallb_rbac | kubectl apply -f -
set-namespace-openshift:
sed -i 's/ namespace:.*/ namespace: $(NAMESPACE)/' $(KUSTOMIZE_DEPLOY_DIR)/custom-namespace-transformer.yaml
deploy-openshift: KUSTOMIZE_DEPLOY_DIR=config/openshift
deploy-openshift: set-namespace-openshift deploy ## Deploy controller in the configured OpenShift cluster
undeploy: ## Undeploy the controller from the configured cluster
$(KUSTOMIZE) build $(KUSTOMIZE_DEPLOY_DIR) | kubectl delete --ignore-not-found=true -f -
$(KUSTOMIZE) build config/metallb_rbac | kubectl delete --ignore-not-found=true -f -
undeploy-openshift: KUSTOMIZE_DEPLOY_DIR=config/openshift
undeploy-openshift: undeploy ## Undeploy the controller from the configured OpenShift cluster
BIN_FILE ?= "metallb-operator.yaml"
bin: manifests kustomize ## Create manifests
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
cd $(KUSTOMIZE_DEPLOY_DIR) && $(KUSTOMIZE) edit set namespace $(NAMESPACE)
cd config/metallb_rbac && $(KUSTOMIZE) edit set namespace $(NAMESPACE)
$(KUSTOMIZE) build $(KUSTOMIZE_DEPLOY_DIR) > bin/$(BIN_FILE)
echo "---" >> bin/$(BIN_FILE)
$(KUSTOMIZE) build config/metallb_rbac >> bin/$(BIN_FILE)
manifests: controller-gen generate-metallb-manifests ## Generate manifests e.g. CRD, RBAC etc.
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=metallb-manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
sed -i -e 's/validating-webhook-configuration/metallb-operator-webhook-configuration/g' config/webhook/manifests.yaml
sed -i -e 's/webhook-service/metallb-operator-webhook-service/g' config/webhook/manifests.yaml
fmt: ## Run go fmt against code
[ -z "`gofmt -s -w -l -e .`" ]
go fmt ./...
vet: ## Run go vet against code
go vet ./...
generate: controller-gen ## Generate code
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
# Build the docker image
docker-build: ## Build the docker image
docker buildx build --load --platform linux/amd64 -t ${IMG} --build-arg GIT_COMMIT="$(shell git rev-parse HEAD)" .
docker-push: ## Push the docker image
docker push ${IMG}
bundle: operator-sdk manifests ## Generate bundle manifests and metadata, then validate generated files.
ls -d config/crd/bases/* | grep -v metallb.io_metallbs | xargs -I{} cp {} bundle/manifests/
$(OPERATOR_SDK) generate kustomize manifests --interactive=false -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --overwrite --version $(CSV_VERSION) $(BUNDLE_METADATA_OPTS) --extra-service-accounts "controller,speaker"
$(OPERATOR_SDK) bundle validate ./bundle
bundle-release: kustomize bundle bump_versions ## Generate the bundle manifests for a PR
build-bundle: ## Build the bundle image.
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
deploy-olm: operator-sdk ## deploys OLM on the cluster
$(OPERATOR_SDK) olm install --version $(OLM_VERSION)
$(OPERATOR_SDK) olm status
deploy-with-olm: ## deploys the operator with OLM instead of manifests
sed -i 's#quay.io/metallb/metallb-operator-bundle-index:$(VERSION)#$(BUNDLE_INDEX_IMG)#g' config/olm-install/install-resources.yaml
sed -i 's#mymetallb#$(NAMESPACE)#g' config/olm-install/install-resources.yaml
$(KUSTOMIZE) build config/olm-install | kubectl apply -f -
VERSION=$(CSV_VERSION) NAMESPACE=$(NAMESPACE) hack/wait-for-csv.sh
bundle-index-build: opm ## Build the bundle index image.
$(OPM) index add --bundles $(BUNDLE_IMG) --tag $(BUNDLE_INDEX_IMG) -c docker -i quay.io/operator-framework/opm:$(OPM_VERSION)
build-and-push-bundle-images: docker-build docker-push ## Generate and push bundle image and bundle index image
$(MAKE) bundle
$(MAKE) build-bundle
$(MAKE) docker-push IMG=$(BUNDLE_IMG)
$(MAKE) bundle-index-build
$(MAKE) docker-push IMG=$(BUNDLE_INDEX_IMG)
deploy-prometheus:
hack/deploy_prometheus.sh
# find or download controller-gen
# download controller-gen if necessary
controller-gen:
ifeq (, $(shell which controller-gen))
go install sigs.k8s.io/controller-tools/cmd/[email protected]
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
# Get the current operator-sdk binary into the _cache dir.
kustomize:
mkdir -p _cache
ifeq (,$(findstring $(KUSTOMIZE_VERSION),$(shell _cache/kustomize version)))
@{ \
set -e ;\
curl -s -L https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2F$(KUSTOMIZE_VERSION)/kustomize_$(KUSTOMIZE_VERSION)_linux_amd64.tar.gz | tar fxvz - -C _cache ;\
chmod u+x _cache/kustomize ;\
}
endif
# Get the current operator-sdk binary into the _cache dir.
operator-sdk:
mkdir -p _cache
ifeq (,$(findstring $(OPERATOR_SDK_VERSION),$(shell _cache/operator-sdk version)))
@{ \
set -e ;\
curl -Lk https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_linux_amd64 > _cache/operator-sdk ;\
chmod u+x _cache/operator-sdk ;\
}
endif
# Get the current opm binary. If there isn't any, we'll use the
# GOBIN path
opm:
ifeq (, $(shell which opm))
@{ \
set -e ;\
curl -Lk https://github.com/operator-framework/operator-registry/releases/download/$(OPM_VERSION)/linux-amd64-opm > $(GOBIN)/opm ;\
chmod u+x $(GOBIN)/opm ;\
}
OPM=$(GOBIN)/opm
else
OPM=$(shell which opm)
endif
# Get the current kubectl binary. If there isn't any, we'll use the
# GOBIN path
kubectl:
ifeq (, $(shell which kubectl))
@{ \
set -e ;\
curl -LO https://dl.k8s.io/release/v1.23.0/bin/linux/amd64/kubectl > $(GOBIN)/kubectl ;\
chmod u+x $(GOBIN)/kubectl ;\
}
endif
generate-metallb-manifests: kubectl ## Generate MetalLB manifests
@echo "Generating MetalLB manifests"
hack/generate-metallb-manifests.sh
validate-metallb-manifests: ## Validate MetalLB manifests
@echo "Comparing newly generated MetalLB manifests to existing ones"
hack/compare-gen-manifests.sh
lint: ## Run golangci-lint against code
@echo "Running golangci-lint"
hack/lint.sh
fetch_metallb_version: ## Updates the versions of metallb under hack/metallb_version with the latest available tag
@echo "Bumping metallb to latest"
hack/fetch_latest_metallb.sh
bump_versions: ## Updates the versions of the metallb-operator / metallb image with the content of hack/operator_version / metallb_version
@echo "Updating the operator version"
hack/bump_versions.sh
bump_metallb: ## Bumps metallb commit ID and creates manifests. It also validates the changes.
@echo "Updating the metallb version"
hack/bump_metallb.sh
$(MAKE) bin
$(MAKE) bundle-release
check_generated: ## Checks if there are any different with the current checkout
@echo "Checking generated files"
hack/verify_generated.sh
help: ## Show this help
@grep -F -h "##" $(MAKEFILE_LIST) | grep -F -v grep | sed -e 's/\\$$//' \
| awk -F'[:#]' '{print $$1 = sprintf("%-30s", $$1), $$4}'