3
3
# To re-generate a bundle for another specific version without changing the standard setup, you can:
4
4
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
5
5
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
6
- VERSION ?= 0 .0.1
6
+ VERSION ?= 1 .0.0
7
7
8
8
# CHANNELS define the bundle channels used in the bundle.
9
9
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
@@ -35,10 +35,20 @@ IMAGE_TAG_BASE ?= quay.io/mycontroller/mycontroller-operator
35
35
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
36
36
BUNDLE_IMG ?= $(IMAGE_TAG_BASE ) -bundle:v$(VERSION )
37
37
38
+ # BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
39
+ BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION ) $(BUNDLE_METADATA_OPTS )
40
+
41
+ # USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
42
+ # You can enable this value if you would like to use SHA Based Digests
43
+ # To enable set flag to true
44
+ USE_IMAGE_DIGESTS ?= false
45
+ ifeq ($(USE_IMAGE_DIGESTS ) , true)
46
+ BUNDLE_GEN_FLAGS += --use-image-digests
47
+ endif
48
+
38
49
# Image URL to use all building/pushing image targets
39
50
IMG ?= $(IMAGE_TAG_BASE ) :$(VERSION )
40
- # Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
41
- CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
51
+
42
52
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
43
53
ENVTEST_K8S_VERSION = 1.21
44
54
@@ -50,11 +60,11 @@ GOBIN=$(shell go env GOBIN)
50
60
endif
51
61
52
62
# Setting SHELL to bash allows bash commands to be executed by recipes.
53
- # This is a requirement for 'setup-envtest.sh' in the test target.
54
63
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
55
64
SHELL = /usr/bin/env bash -o pipefail
56
65
.SHELLFLAGS = -ec
57
66
67
+ .PHONY : all
58
68
all : build
59
69
60
70
# #@ General
@@ -70,87 +80,110 @@ all: build
70
80
# More info on the awk command:
71
81
# http://linuxcommand.org/lc3_adv_awk.php
72
82
83
+ .PHONY : help
73
84
help : # # Display this help.
74
85
@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 )
75
86
76
87
# #@ Development
77
88
89
+ .PHONY : manifests
78
90
manifests : controller-gen # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
79
- $(CONTROLLER_GEN ) $( CRD_OPTIONS ) rbac:roleName=manager-role webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
91
+ $(CONTROLLER_GEN ) rbac:roleName=manager-role crd webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
80
92
93
+ .PHONY : generate
81
94
generate : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
82
95
$(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
83
96
97
+ .PHONY : fmt
84
98
fmt : # # Run go fmt against code.
85
99
go fmt ./...
86
100
101
+ .PHONY : vet
87
102
vet : # # Run go vet against code.
88
103
go vet ./...
89
104
105
+ .PHONY : test
90
106
test : manifests generate fmt vet envtest # # Run tests.
91
107
KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) -p path) " go test ./... -coverprofile cover.out
92
108
93
109
# #@ Build
94
110
111
+ .PHONY : build
95
112
build : generate fmt vet # # Build manager binary.
96
113
go build -o bin/manager main.go
97
114
115
+ .PHONY : run
98
116
run : manifests generate fmt vet # # Run a controller from your host.
99
117
go run ./main.go
100
118
119
+ .PHONY : docker-build
101
120
docker-build : test # # Build docker image with the manager.
102
121
docker build -t ${IMG} .
103
122
123
+ .PHONY : docker-push
104
124
docker-push : # # Push docker image with the manager.
105
125
docker push ${IMG}
106
126
107
127
# #@ Deployment
108
128
129
+ ifndef ignore-not-found
130
+ ignore-not-found = false
131
+ endif
132
+
133
+ .PHONY : install
109
134
install : manifests kustomize # # Install CRDs into the K8s cluster specified in ~/.kube/config.
110
135
$(KUSTOMIZE ) build config/crd | kubectl apply -f -
111
136
112
- uninstall : manifests kustomize # # Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
113
- $(KUSTOMIZE ) build config/crd | kubectl delete -f -
137
+ .PHONY : uninstall
138
+ uninstall : manifests kustomize # # Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
139
+ $(KUSTOMIZE ) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found ) -f -
114
140
141
+ .PHONY : deploy
115
142
deploy : manifests kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
116
143
cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
117
144
$(KUSTOMIZE ) build config/default | kubectl apply -f -
118
145
119
- undeploy : # # Undeploy controller from the K8s cluster specified in ~/.kube/config.
120
- $(KUSTOMIZE ) build config/default | kubectl delete -f -
146
+ .PHONY : undeploy
147
+ undeploy : # # Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
148
+ $(KUSTOMIZE ) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found ) -f -
149
+
150
+ # #@ Build Dependencies
151
+
152
+ # # Location to install dependencies to
153
+ LOCALBIN ?= $(shell pwd) /bin
154
+ $(LOCALBIN ) :
155
+ mkdir -p $(LOCALBIN )
121
156
157
+ # # Tool Binaries
158
+ KUSTOMIZE ?= $(LOCALBIN ) /kustomize
159
+ CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
160
+ ENVTEST ?= $(LOCALBIN ) /setup-envtest
122
161
123
- CONTROLLER_GEN = $( shell pwd) /bin/controller-gen
124
- controller-gen : # # Download controller-gen locally if necessary.
125
- $( call go-get-tool, $( CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen@ v0.6.1)
162
+ # # Tool Versions
163
+ KUSTOMIZE_VERSION ?= v3.8.7
164
+ CONTROLLER_TOOLS_VERSION ?= v0.9.2
126
165
127
- KUSTOMIZE = $(shell pwd) /bin/kustomize
128
- kustomize : # # Download kustomize locally if necessary.
129
- $(call go-get-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/v3@v3.8.7)
166
+ KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
167
+ .PHONY : kustomize
168
+ kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
169
+ $(KUSTOMIZE ) : $(LOCALBIN )
170
+ test -s $(LOCALBIN ) /kustomize || { curl -s $( KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $( subst v,,$( KUSTOMIZE_VERSION) ) $( LOCALBIN) ; }
130
171
131
- ENVTEST = $(shell pwd) /bin/setup-envtest
132
- envtest : # # Download envtest-setup locally if necessary.
133
- $(call go-get-tool,$(ENVTEST ) ,sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
172
+ .PHONY : controller-gen
173
+ controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
174
+ $(CONTROLLER_GEN ) : $(LOCALBIN )
175
+ test -s $(LOCALBIN ) /controller-gen || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
134
176
135
- # go-get-tool will 'go get' any package $2 and install it to $1.
136
- PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
137
- define go-get-tool
138
- @[ -f $(1 ) ] || { \
139
- set -e ;\
140
- TMP_DIR=$$(mktemp -d ) ;\
141
- cd $$TMP_DIR ;\
142
- go mod init tmp ;\
143
- echo "Downloading $(2 ) " ;\
144
- GOBIN=$(PROJECT_DIR ) /bin go get $(2 ) ;\
145
- rm -rf $$TMP_DIR ;\
146
- }
147
- endef
177
+ .PHONY : envtest
178
+ envtest : $(ENVTEST ) # # Download envtest-setup locally if necessary.
179
+ $(ENVTEST ) : $(LOCALBIN )
180
+ test -s $(LOCALBIN ) /setup-envtest || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
148
181
149
182
.PHONY : bundle
150
183
bundle : manifests kustomize # # Generate bundle manifests and metadata, then validate generated files.
151
184
operator-sdk generate kustomize manifests -q
152
185
cd config/manager && $(KUSTOMIZE ) edit set image controller=$(IMG )
153
- $(KUSTOMIZE ) build config/manifests | operator-sdk generate bundle -q --overwrite --version $( VERSION ) $( BUNDLE_METADATA_OPTS )
186
+ $(KUSTOMIZE ) build config/manifests | operator-sdk generate bundle $( BUNDLE_GEN_FLAGS )
154
187
operator-sdk bundle validate ./bundle
155
188
156
189
.PHONY : bundle-build
@@ -170,7 +203,7 @@ ifeq (,$(shell which opm 2>/dev/null))
170
203
set -e ;\
171
204
mkdir -p $(dir $(OPM)) ;\
172
205
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
173
- curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1 /$${OS}-$${ARCH}-opm ;\
206
+ curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0 /$${OS}-$${ARCH}-opm ;\
174
207
chmod +x $(OPM) ;\
175
208
}
176
209
else
0 commit comments