forked from tigera/operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
615 lines (521 loc) · 21.2 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
# Copyright (c) 2019 Tigera, Inc. All rights reserved.
# This Makefile requires the following dependencies on the host system:
# - go
#
# TODO: Add in the necessary variables, etc, to make this Makefile work.
# TODO: Add in multi-arch stuff.
# Shortcut targets
default: build
## Build binary for current platform
all: build
## Run the tests for the current platform/architecture
test: fmt vet ut
# Both native and cross architecture builds are supported.
# The target architecture is select by setting the ARCH variable.
# When ARCH is undefined it is set to the detected host architecture.
# When ARCH differs from the host architecture a crossbuild will be performed.
ARCHES=$(patsubst build/Dockerfile.%,%,$(wildcard build/Dockerfile.*))
# BUILDARCH is the host architecture
# ARCH is the target architecture
# we need to keep track of them separately
BUILDARCH ?= $(shell uname -m)
BUILDOS ?= $(shell uname -s | tr A-Z a-z)
# canonicalized names for host architecture
ifeq ($(BUILDARCH),aarch64)
BUILDARCH=arm64
endif
ifeq ($(BUILDARCH),x86_64)
BUILDARCH=amd64
endif
# unless otherwise set, I am building for my own architecture, i.e. not cross-compiling
ARCH ?= $(BUILDARCH)
# canonicalized names for target architecture
ifeq ($(ARCH),aarch64)
override ARCH=arm64
endif
ifeq ($(ARCH),x86_64)
override ARCH=amd64
endif
# we want to be able to run the same recipe on multiple targets keyed on the image name
# to do that, we would use the entire image name, e.g. calico/node:abcdefg, as the stem, or '%', in the target
# however, make does **not** allow the usage of invalid filename characters - like / and : - in a stem, and thus errors out
# to get around that, we "escape" those characters by converting all : to --- and all / to ___ , so that we can use them
# in the target, we then unescape them back
escapefs = $(subst :,---,$(subst /,___,$(1)))
unescapefs = $(subst ---,:,$(subst ___,/,$(1)))
# these macros create a list of valid architectures for pushing manifests
space :=
space +=
comma := ,
prefix_linux = $(addprefix linux/,$(strip $1))
join_platforms = $(subst $(space),$(comma),$(call prefix_linux,$(strip $1)))
# Targets used when cross building.
.PHONY: register
# Enable binfmt adding support for miscellaneous binary formats.
# This is only needed when running non-native binaries.
register:
ifneq ($(BUILDARCH),$(ARCH))
docker run --rm --privileged multiarch/qemu-user-static:register || true
endif
# list of arches *not* to build when doing *-all
# until s390x works correctly
EXCLUDEARCH ?= s390x
VALIDARCHES = $(filter-out $(EXCLUDEARCH),$(ARCHES))
###############################################################################
PACKAGE_NAME?=github.com/tigera/operator
LOCAL_USER_ID?=$(shell id -u $$USER)
GO_BUILD_VER?=v0.50
CALICO_BUILD?=calico/go-build:$(GO_BUILD_VER)
SRC_FILES=$(shell find ./pkg -name '*.go')
SRC_FILES+=$(shell find ./api -name '*.go')
SRC_FILES+=$(shell find ./controllers -name '*.go')
SRC_FILES+=main.go
EXTRA_DOCKER_ARGS += -e GO111MODULE=on -e GOPRIVATE=github.com/tigera/*
ifeq ($(GIT_USE_SSH),true)
GIT_CONFIG_SSH ?= git config --global url."ssh://[email protected]/".insteadOf "https://github.com/";
endif
ifdef SSH_AUTH_SOCK
EXTRA_DOCKER_ARGS += -v $(SSH_AUTH_SOCK):/ssh-agent --env SSH_AUTH_SOCK=/ssh-agent
endif
ifneq ($(GOPATH),)
# If the environment is using multiple comma-separated directories for gopath, use the first one, as that
# is the default one used by go modules.
GOMOD_CACHE = $(shell echo $(GOPATH) | cut -d':' -f1)/pkg/mod
else
# If gopath is empty, default to $(HOME)/go.
GOMOD_CACHE = $(HOME)/go/pkg/mod
endif
EXTRA_DOCKER_ARGS += -v $(GOMOD_CACHE):/go/pkg/mod:rw
CONTAINERIZED= mkdir -p .go-pkg-cache $(GOMOD_CACHE) && \
docker run --rm \
-v $(CURDIR):/go/src/$(PACKAGE_NAME):rw \
-v $(CURDIR)/.go-pkg-cache:/go-cache/:rw \
-e LOCAL_USER_ID=$(LOCAL_USER_ID) \
-e GOPATH=/go \
-e GOCACHE=/go-cache \
-e KUBECONFIG=/go/src/$(PACKAGE_NAME)/kubeconfig.yaml \
-w /go/src/$(PACKAGE_NAME) \
--net=host \
$(EXTRA_DOCKER_ARGS) \
$(CALICO_BUILD)
BUILD_IMAGE?=tigera/operator
BUILD_INIT_IMAGE?=tigera/operator-init
BINDIR?=build/_output/bin
PUSH_IMAGE_PREFIXES?=quay.io/
RELEASE_PREFIXES?=
# If this is a release, also tag and push additional images.
ifeq ($(RELEASE),true)
PUSH_IMAGE_PREFIXES+=$(RELEASE_PREFIXES)
endif
# remove from the list to push to manifest any registries that do not support multi-arch
EXCLUDE_MANIFEST_REGISTRIES?=quay.io/
PUSH_MANIFEST_IMAGE_PREFIXES=$(PUSH_IMAGE_PREFIXES:$(EXCLUDE_MANIFEST_REGISTRIES)%=)
PUSH_NONMANIFEST_IMAGE_PREFIXES=$(filter-out $(PUSH_MANIFEST_IMAGE_PREFIXES),$(PUSH_IMAGE_PREFIXES))
imagetag:
ifndef IMAGETAG
$(error IMAGETAG is undefined - run using make <target> IMAGETAG=X.Y.Z)
endif
## push one arch
push: imagetag $(addprefix sub-single-push-,$(call escapefs,$(PUSH_IMAGE_PREFIXES)))
sub-single-push-%:
docker push $(call unescapefs,$*$(BUILD_IMAGE):$(IMAGETAG)-$(ARCH))
## push all arches
push-all: imagetag $(addprefix sub-push-,$(ARCHES))
sub-push-%:
$(MAKE) push ARCH=$* IMAGETAG=$(IMAGETAG)
push-manifests: imagetag $(addprefix sub-manifest-,$(call escapefs,$(PUSH_MANIFEST_IMAGE_PREFIXES)))
sub-manifest-%:
# Docker login to hub.docker.com required before running this target as we are using $(DOCKER_CONFIG) holds the docker login credentials
# path to credentials based on manifest-tool's requirements here https://github.com/estesp/manifest-tool#sample-usage
docker run -t --entrypoint /bin/sh -v $(DOCKER_CONFIG):/root/.docker/config.json $(CALICO_BUILD) -c "/usr/bin/manifest-tool push from-args --platforms $(call join_platforms,$(VALIDARCHES)) --template $(call unescapefs,$*$(BUILD_IMAGE):$(IMAGETAG))-ARCH --target $(call unescapefs,$*$(BUILD_IMAGE):$(IMAGETAG))"
## push default amd64 arch where multi-arch manifest is not supported
push-non-manifests: imagetag $(addprefix sub-non-manifest-,$(call escapefs,$(PUSH_NONMANIFEST_IMAGE_PREFIXES)))
sub-non-manifest-%:
ifeq ($(ARCH),amd64)
docker push $(call unescapefs,$*$(BUILD_IMAGE):$(IMAGETAG))
else
$(NOECHO) $(NOOP)
endif
## tag images of one arch
tag-images: imagetag $(addprefix sub-single-tag-images-arch-,$(call escapefs,$(PUSH_IMAGE_PREFIXES))) $(addprefix sub-single-tag-images-non-manifest-,$(call escapefs,$(PUSH_NONMANIFEST_IMAGE_PREFIXES)))
sub-single-tag-images-arch-%:
docker tag $(BUILD_IMAGE):latest-$(ARCH) $(call unescapefs,$*$(BUILD_IMAGE):$(IMAGETAG)-$(ARCH))
# because some still do not support multi-arch manifest
sub-single-tag-images-non-manifest-%:
ifeq ($(ARCH),amd64)
docker tag $(BUILD_IMAGE):latest-$(ARCH) $(call unescapefs,$*$(BUILD_IMAGE):$(IMAGETAG))
else
$(NOECHO) $(NOOP)
endif
## tag images of all archs
tag-images-all: imagetag $(addprefix sub-tag-images-,$(VALIDARCHES))
sub-tag-images-%:
$(MAKE) tag-images ARCH=$* IMAGETAG=$(IMAGETAG)
###############################################################################
# Building the code
###############################################################################
.PHONY: build
# Get version from git.
ifeq ($(LOCAL_BUILD),true)
GIT_VERSION?=$(shell git describe --tags --dirty --always --abbrev=12)-dev-build
else
GIT_VERSION?=$(shell git describe --tags --dirty --always --abbrev=12)
endif
build: fmt vet $(BINDIR)/operator-$(ARCH)
$(BINDIR)/operator-$(ARCH): $(SRC_FILES)
mkdir -p $(BINDIR)
$(CONTAINERIZED) \
sh -c '$(GIT_CONFIG_SSH) \
go build -v -i -o $(BINDIR)/operator-$(ARCH) -ldflags "-X github.com/tigera/operator/version.VERSION=$(GIT_VERSION) -s -w" ./main.go'
.PHONY: image
image: build $(BUILD_IMAGE)
image-all: $(addprefix sub-image-,$(VALIDARCHES))
sub-image-%:
$(MAKE) image ARCH=$*
$(BUILD_IMAGE): $(BUILD_IMAGE)-$(ARCH)
$(BUILD_IMAGE)-$(ARCH): $(BINDIR)/operator-$(ARCH)
docker build --pull -t $(BUILD_IMAGE):latest-$(ARCH) --build-arg GIT_VERSION=$(GIT_VERSION) -f ./build/Dockerfile.$(ARCH) .
ifeq ($(ARCH),amd64)
docker tag $(BUILD_IMAGE):latest-$(ARCH) $(BUILD_IMAGE):latest
endif
build/init/bin/kubectl:
mkdir -p build/init/bin
curl -o build/init/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/v1.14.0/bin/linux/amd64/kubectl
.PHONY: image-init
image-init: image
ifeq ($(ARCH),amd64)
docker tag $(BUILD_IMAGE):latest-$(ARCH) $(BUILD_INIT_IMAGE):latest
endif
.PHONY: images
images: image
# Build the images for the target architecture
.PHONY: images-all
images-all: $(addprefix sub-image-,$(VALIDARCHES))
sub-image-%:
$(MAKE) images ARCH=$*
clean:
rm -rf build/_output
rm -rf build/init/bin
rm -rf hack/bin
rm -rf .go-pkg-cache
rm -f *-release-notes.md
docker rmi -f $(BUILD_IMAGE):latest $(BUILD_IMAGE):latest-$(ARCH)
###############################################################################
# Tests
###############################################################################
WHAT?=.
GINKGO_ARGS?= -v
GINKGO_FOCUS?=.*
## Run the full set of tests
ut: cluster-create run-uts cluster-destroy
run-uts:
-mkdir -p .go-pkg-cache report
$(CONTAINERIZED) sh -c '$(GIT_CONFIG_SSH) \
ginkgo -r --skipPackage ./vendor -focus="$(GINKGO_FOCUS)" $(GINKGO_ARGS) "$(WHAT)"'
## Create a local kind dual stack cluster.
KUBECONFIG?=./kubeconfig.yaml
cluster-create: kubectl
# First make sure any previous cluster is deleted
make cluster-destroy
./deploy/scripts/create_kind_cluster.sh
cp ~/.kube/kind-config-kind $(KUBECONFIG)
$(MAKE) deploy-crds
$(MAKE) create-tigera-operator-namespace
## Deploy CRDs needed for UTs. CRDs needed by ECK that we don't use are not deployed.
deploy-crds: kubectl
@export KUBECONFIG=$(KUBECONFIG) && \
./kubectl apply -f config/crd/bases/ && \
./kubectl apply -f deploy/crds/calico/ && \
./kubectl apply -f deploy/crds/enterprise/ && \
./kubectl apply -f deploy/crds/elastic/elasticsearch-crd.yaml && \
./kubectl apply -f deploy/crds/elastic/kibana-crd.yaml
create-tigera-operator-namespace: kubectl
KUBECONFIG=$(KUBECONFIG) ./kubectl create ns tigera-operator
## Destroy local kind cluster
cluster-destroy:
./deploy/scripts/delete_kind_cluster.sh
rm -f $(KUBECONFIG)
kubectl:
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.17.0/bin/linux/amd64/kubectl
chmod +x ./kubectl
###############################################################################
# Static checks
###############################################################################
.PHONY: static-checks
## Perform static checks on the code.
static-checks:
$(CONTAINERIZED) golangci-lint run --deadline 5m
.PHONY: fix
## Fix static checks
fix:
$(CONTAINERIZED) \
sh -c '$(GIT_CONFIG_SSH) \
goimports -w $(SRC_FILES)'
.PHONY: format-check
format-check:
@$(CONTAINERIZED) \
sh -c '$(GIT_CONFIG_SSH) \
files=$$(gofmt -l ./pkg ./controllers ./api ./test); \
[ "$$files" = "" ] && exit 0; \
echo The following files need a format update:; \
echo $$files; \
echo Try running \"make fix\" and committing any changes; \
exit 1'
.PHONY: dirty-check
dirty-check:
@if [ "$$(git diff --stat)" = "" ]; then exit 0; fi; \
echo "The following files are dirty"; git diff --stat
foss-checks:
@echo Running $@...
docker run --rm \
-v $(CURDIR):/go/src/$(PACKAGE_NAME):rw \
-e LOCAL_USER_ID=$(LOCAL_USER_ID) \
-w /go/src/$(PACKAGE_NAME)
-e FOSSA_API_KEY=$(FOSSA_API_KEY) \
$(CALICO_BUILD) /usr/local/bin/fossa
###############################################################################
# CI/CD
###############################################################################
.PHONY: ci
## Run what CI runs
ci: clean format-check images test $(BINDIR)/gen-versions validate-gen-versions dirty-check
validate-gen-versions:
./hack/gen-versions/validate.sh
## Deploys images to registry
cd:
ifndef CONFIRM
$(error CONFIRM is undefined - run using make <target> CONFIRM=true)
endif
ifndef BRANCH_NAME
$(error BRANCH_NAME is undefined - run using make <target> BRANCH_NAME=var or set an environment variable)
endif
$(MAKE) tag-images-all push-all push-manifests push-non-manifests IMAGETAG=${BRANCH_NAME} EXCLUDEARCH="$(EXCLUDEARCH)"
$(MAKE) tag-images-all push-all push-manifests push-non-manifests IMAGETAG=$(shell git describe --tags --dirty --always --long --abbrev=12) EXCLUDEARCH="$(EXCLUDEARCH)"
###############################################################################
# Release
###############################################################################
## Determines if we are on a tag and if so builds a release.
maybe-build-release:
./hack/maybe-build-release.sh
## Tags and builds a release from start to finish.
release: release-prereqs
ifneq ($(VERSION), $(GIT_VERSION))
$(error Attempt to build $(VERSION) from $(GIT_VERSION))
endif
$(MAKE) release-build
$(MAKE) release-verify
@echo ""
@echo "Release build complete. Next, push the produced images."
@echo ""
@echo " make VERSION=$(VERSION) release-publish"
@echo ""
## Produces a clean build of release artifacts at the specified version.
release-build: release-prereqs clean
# Check that the correct code is checked out.
ifneq ($(VERSION), $(GIT_VERSION))
$(error Attempt to build $(VERSION) from $(GIT_VERSION))
endif
$(MAKE) image-all
$(MAKE) tag-images-all RELEASE=true IMAGETAG=$(VERSION)
# Generate the `latest` images.
$(MAKE) tag-images-all RELEASE=true IMAGETAG=latest
## Verifies the release artifacts produces by `make release-build` are correct.
release-verify: release-prereqs
# Check the reported version is correct for each release artifact.
if ! docker run quay.io/$(BUILD_IMAGE):$(VERSION)-$(ARCH) --version | grep '^Operator: $(VERSION)$$'; then echo "Reported version:" `docker run quay.io/$(BUILD_IMAGE):$(VERSION)-$(ARCH) --version ` "\nExpected version: $(VERSION)"; false; else echo "\nVersion check passed\n"; fi
release-publish-images: release-prereqs
# Push images.
$(MAKE) push-all push-manifests push-non-manifests RELEASE=true IMAGETAG=$(VERSION)
## Pushes a github release and release artifacts produced by `make release-build`.
release-publish: release-prereqs
# Push the git tag.
git push origin $(VERSION)
$(MAKE) release-publish-images IMAGETAG=$(VERSION)
@echo "Finalize the GitHub release based on the pushed tag."
@echo ""
@echo " https://$(PACKAGE_NAME)/releases/tag/$(VERSION)"
@echo ""
@echo "If this is the latest stable release, then run the following to push 'latest' images."
@echo ""
@echo " make VERSION=$(VERSION) release-publish-latest"
@echo ""
# release-prereqs checks that the environment is configured properly to create a release.
release-prereqs:
ifndef VERSION
$(error VERSION is undefined - run using make release VERSION=vX.Y.Z)
endif
ifdef LOCAL_BUILD
$(error LOCAL_BUILD must not be set for a release)
endif
###############################################################################
# Utilities
###############################################################################
OPERATOR_SDK_VERSION=v1.0.1
OPERATOR_SDK_BARE=hack/bin/operator-sdk
OPERATOR_SDK=$(OPERATOR_SDK_BARE)-$(OPERATOR_SDK_VERSION)
$(OPERATOR_SDK):
mkdir -p hack/bin
curl --fail -L -o $@ \
https://github.com/operator-framework/operator-sdk/releases/download/${OPERATOR_SDK_VERSION}/operator-sdk-${OPERATOR_SDK_VERSION}-x86_64-linux-gnu
chmod +x $@
.PHONY: $(OPERATOR_SDK_BARE)
$(OPERATOR_SDK_BARE): $(OPERATOR_SDK)
ln -f -s operator-sdk-$(OPERATOR_SDK_VERSION) $(OPERATOR_SDK_BARE)
## Generating code after API changes.
gen-files: manifests generate
OS_VERSIONS?=config/calico_versions.yml
EE_VERSIONS?=config/enterprise_versions.yml
gen-versions: $(BINDIR)/gen-versions
$(BINDIR)/gen-versions -os-versions=$(OS_VERSIONS) > pkg/components/calico.go
$(BINDIR)/gen-versions -ee-versions=$(EE_VERSIONS) > pkg/components/enterprise.go
$(BINDIR)/gen-versions: $(shell find ./hack/gen-versions -type f)
mkdir -p $(BINDIR)
$(CONTAINERIZED) \
sh -c '$(GIT_CONFIG_SSH) \
go build -o $(BINDIR)/gen-versions ./hack/gen-versions'
## Generate a ClusterServiceVersion package.
# E.g. make gen-csv VERSION=1.6.2 PREV_VERSION=0.0.0
#
# VERSION: the operator version to generate a CSV for.
# PREV_VERSION: the operator version that this CSV will replace. If there is
# no previous version, use 0.0.0
.PHONY: gen-csv
gen-csv: $(OPERATOR_SDK_BARE) get-digest
$(eval EXTRA_DOCKER_ARGS += -e OPERATOR_IMAGE_INSPECT="$(OPERATOR_IMAGE_INSPECT)" -e VERSION=$(VERSION) -e PREV_VERSION=$(PREV_VERSION))
$(CONTAINERIZED) hack/gen-csv/csv.sh
.PHONY: prepull-image
prepull-image:
@echo Pulling operator image...
docker pull quay.io/tigera/operator:v$(VERSION)
# Get the digest for the image. This target runs docker commands on the host since the
# build container doesn't have docker-in-docker. 'docker inspect' returns output like the example
# below. RepoDigests may have more than one entry so we need to filter.
# [
# {
# "Id": "sha256:34a1114040c03830da0a8d57f8d999deba26d8e31bda353aed201a375f68870b",
# "RepoTags": [
# "quay.io/tigera/operator:v1.3.1",
# "..."
# ],
# "RepoDigests": [
# "quay.io/tigera/operator@sha256:5e1d551b5a711592472f4a3cc4645698d5f826da4253f0d47cfa5d5b641a2e1a",
# "..."
# ],
# ...
# }
# ]
.PHONY: get-digest
get-digest: prepull-image
@echo Getting operator image digest...
$(eval OPERATOR_IMAGE_INSPECT=$(shell sh -c "docker image inspect quay.io/tigera/operator:v$(VERSION) | base64 -w 0"))
## Generate a CSV bundle zip file containing all CSVs and a package manifest.
# E.g. make gen-bundle
.PHONY: gen-bundle
gen-bundle:
$(CONTAINERIZED) hack/gen-csv/bundle.sh
.PHONY: help
## Display this help text
help: # Some kind of magic from https://gist.github.com/rcmachado/af3db315e31383502660
$(info Available targets)
@awk '/^[a-zA-Z\-\_0-9\/]+:/ { \
nb = sub( /^## /, "", helpMsg ); \
if(nb == 0) { \
helpMsg = $$0; \
nb = sub( /^[^:]*:.* ## /, "", helpMsg ); \
} \
if (nb) \
printf "\033[1;31m%-" width "s\033[0m %s\n", $$1, helpMsg; \
} \
{ helpMsg = $$0 }' \
width=20 \
$(MAKEFILE_LIST)
#####################################
#####################################
# Current Operator version
VERSION ?= 0.0.1
# Default bundle image tag
BUNDLE_IMG ?= controller-bundle:$(VERSION)
# Options for 'bundle-build'
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)
# Image URL to use all building/pushing image targets
IMG ?= controller:latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:crdVersions=v1,trivialVersions=true"
# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet manifests
go run ./main.go
# Install CRDs into a cluster
install: manifests kustomize
$(KUSTOMIZE) build config/crd | kubectl apply -f -
# Uninstall CRDs from a cluster
uninstall: manifests kustomize
$(KUSTOMIZE) build config/crd | kubectl delete -f -
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
# Generate manifests e.g. CRD
# Can also generate RBAC and webhooks but that is not enabled currently
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./api/..." output:crd:artifacts:config=config/crd/bases
# Run go fmt against code
fmt:
$(CONTAINERIZED) \
sh -c '$(GIT_CONFIG_SSH) \
go fmt ./...'
# Run go vet against code
vet:
$(CONTAINERIZED) \
sh -c '$(GIT_CONFIG_SSH) \
go vet ./...'
# Generate code
generate: $(BINDIR)/controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
GO_GET_CONTAINER=docker run --rm \
-v $(CURDIR)/$(BINDIR):/go/bin:rw \
-e LOCAL_USER_ID=$(LOCAL_USER_ID) \
-e GOPATH=/go \
--net=host \
$(EXTRA_DOCKER_ARGS) \
$(CALICO_BUILD)
# download controller-gen if necessary
CONTROLLER_GEN=$(BINDIR)/controller-gen
controller-gen: $(BINDIR)/controller-gen
$(BINDIR)/controller-gen:
mkdir -p $(BINDIR)
$(GO_GET_CONTAINER) \
sh -c '$(GIT_CONFIG_SSH) \
set -e ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/controller-tools/cmd/[email protected]'
KUSTOMIZE=$(BINDIR)/kustomize
# download kustomize if necessary
$(BINDIR)/kustomize:
mkdir -p $(BINDIR)
$(GO_GET_CONTAINER) \
sh -c '$(GIT_CONFIG_SSH) \
set -e ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/kustomize/kustomize/[email protected] '
## Generate bundle manifests and metadata, then validate generated files.
#.PHONY: bundle
#bundle: manifests
# operator-sdk generate kustomize manifests -q
# cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
# $(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
# operator-sdk bundle validate ./bundle
#
## Build the bundle image.
#.PHONY: bundle-build
#bundle-build:
# docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .