1
+ # Copyright 2023- IBM Inc. All rights reserved
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
1
4
# VERSION defines the project version for the bundle.
2
5
# Update this value when you upgrade the version of your project.
3
6
# To re-generate a bundle for another specific version without changing the standard setup, you can:
@@ -28,17 +31,43 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
28
31
# This variable is used to construct full image tags for bundle and catalog images.
29
32
#
30
33
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
31
- # com. ibm/core-dump-operator-bundle:$VERSION and com. ibm/core-dump-operator-catalog:$VERSION.
34
+ # ibm.com /core-dump-operator-bundle:$VERSION and ibm.com /core-dump-operator-catalog:$VERSION.
32
35
IMAGE_TAG_BASE ?= quay.io/number9/core-dump-operator
33
36
34
37
# BUNDLE_IMG defines the image:tag used for the bundle.
35
38
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
36
39
BUNDLE_IMG ?= $(IMAGE_TAG_BASE ) -bundle:v$(VERSION )
37
40
41
+ # BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
42
+ BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION ) $(BUNDLE_METADATA_OPTS )
43
+
44
+ # USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
45
+ # You can enable this value if you would like to use SHA Based Digests
46
+ # To enable set flag to true
47
+ USE_IMAGE_DIGESTS ?= false
48
+ ifeq ($(USE_IMAGE_DIGESTS ) , true)
49
+ BUNDLE_GEN_FLAGS += --use-image-digests
50
+ endif
51
+
38
52
# Image URL to use all building/pushing image targets
39
53
IMG ?= $(IMAGE_TAG_BASE ) :$(VERSION )
54
+ # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
55
+ ENVTEST_K8S_VERSION = 1.26.0
56
+
57
+ # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
58
+ ifeq (,$(shell go env GOBIN) )
59
+ GOBIN =$(shell go env GOPATH) /bin
60
+ else
61
+ GOBIN =$(shell go env GOBIN)
62
+ endif
63
+
64
+ # Setting SHELL to bash allows bash commands to be executed by recipes.
65
+ # Options are set to exit when a recipe line exits non-zero or a piped command fails.
66
+ SHELL = /usr/bin/env bash -o pipefail
67
+ .SHELLFLAGS = -ec
40
68
41
- all : docker-build
69
+ .PHONY : all
70
+ all : build
42
71
43
72
# #@ General
44
73
@@ -53,75 +82,135 @@ all: docker-build
53
82
# More info on the awk command:
54
83
# http://linuxcommand.org/lc3_adv_awk.php
55
84
85
+ .PHONY : help
56
86
help : # # Display this help.
57
87
@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 )
58
88
89
+ # #@ Development
90
+
91
+ .PHONY : manifests
92
+ manifests : controller-gen # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
93
+ $(CONTROLLER_GEN ) rbac:roleName=manager-role crd webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
94
+
95
+ .PHONY : generate
96
+ generate : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
97
+ $(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
98
+
99
+ .PHONY : fmt
100
+ fmt : # # Run go fmt against code.
101
+ go fmt ./...
102
+
103
+ .PHONY : vet
104
+ vet : # # Run go vet against code.
105
+ go vet ./...
106
+
107
+ .PHONY : operator-test
108
+ operator-test : manifests generate fmt vet envtest # # Run tests.
109
+ KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " go test ./controllers/... -coverprofile operator-cover.out
110
+
59
111
# #@ Build
60
112
61
- run : helm-operator # # Run against the configured Kubernetes cluster in ~/.kube/config
62
- $(HELM_OPERATOR ) run
113
+ .PHONY : build
114
+ build : manifests generate fmt vet # # Build manager binary.
115
+ go build -o bin/manager main.go
116
+
117
+ .PHONY : run
118
+ run : manifests generate fmt vet # # Run a controller from your host.
119
+ go run ./main.go
63
120
64
- docker-build : # # Build docker image with the manager.
121
+ # If you wish built the manager image targeting other platforms you can use the --platform flag.
122
+ # (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
123
+ # More info: https://docs.docker.com/develop/develop-images/build_enhancements/
124
+ .PHONY : docker-build
125
+ docker-build : operator-test # # Build docker image with the manager.
65
126
docker build -t ${IMG} .
66
127
128
+ .PHONY : docker-push
67
129
docker-push : # # Push docker image with the manager.
68
130
docker push ${IMG}
69
131
132
+ # PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
133
+ # architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
134
+ # - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
135
+ # - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
136
+ # - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
137
+ # To properly provided solutions that supports more than one platform you should use this option.
138
+ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
139
+ .PHONY : docker-buildx
140
+ docker-buildx : operator-test # # Build and push docker image for the manager for cross-platform support
141
+ # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
142
+ sed -e ' 1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
143
+ - docker buildx create --name project-v3-builder
144
+ docker buildx use project-v3-builder
145
+ - docker buildx build --push --platform=$(PLATFORMS ) --tag ${IMG} -f Dockerfile.cross .
146
+ - docker buildx rm project-v3-builder
147
+ rm Dockerfile.cross
148
+
70
149
# #@ Deployment
71
150
72
- install : kustomize # # Install CRDs into the K8s cluster specified in ~/.kube/config.
151
+ ifndef ignore-not-found
152
+ ignore-not-found = false
153
+ endif
154
+
155
+ .PHONY : install
156
+ install : manifests kustomize # # Install CRDs into the K8s cluster specified in ~/.kube/config.
73
157
$(KUSTOMIZE ) build config/crd | kubectl apply -f -
74
158
75
- uninstall : kustomize # # Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
76
- $(KUSTOMIZE ) build config/crd | kubectl delete -f -
159
+ .PHONY : uninstall
160
+ 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.
161
+ $(KUSTOMIZE ) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found ) -f -
77
162
78
- deploy : kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
163
+ .PHONY : deploy
164
+ deploy : manifests kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
79
165
cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
80
166
$(KUSTOMIZE ) build config/default | kubectl apply -f -
81
167
82
- undeploy : # # Undeploy controller from the K8s cluster specified in ~/.kube/config.
83
- $(KUSTOMIZE ) build config/default | kubectl delete -f -
168
+ .PHONY : undeploy
169
+ 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.
170
+ $(KUSTOMIZE ) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found ) -f -
171
+
172
+ # #@ Build Dependencies
173
+
174
+ # # Location to install dependencies to
175
+ LOCALBIN ?= $(shell pwd) /bin
176
+ $(LOCALBIN ) :
177
+ mkdir -p $(LOCALBIN )
84
178
85
- OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
86
- ARCH := $(shell uname -m | sed 's/x86_64/amd64/')
179
+ # # Tool Binaries
180
+ KUSTOMIZE ?= $(LOCALBIN ) /kustomize
181
+ CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
182
+ ENVTEST ?= $(LOCALBIN ) /setup-envtest
87
183
184
+ # # Tool Versions
185
+ KUSTOMIZE_VERSION ?= v3.8.7
186
+ CONTROLLER_TOOLS_VERSION ?= v0.11.1
187
+
188
+ KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
88
189
.PHONY : kustomize
89
- KUSTOMIZE = $(shell pwd) /bin/kustomize
90
- kustomize : # # Download kustomize locally if necessary.
91
- ifeq (,$(wildcard $(KUSTOMIZE ) ) )
92
- ifeq (,$(shell which kustomize 2>/dev/null) )
93
- @{ \
94
- set -e ;\
95
- mkdir -p $(dir $(KUSTOMIZE)) ;\
96
- curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v3.5.4/kustomize_v3.5.4_$(OS)_$(ARCH).tar.gz | \
97
- tar xzf - -C bin/ ;\
98
- }
99
- else
100
- KUSTOMIZE = $(shell which kustomize)
101
- endif
102
- endif
190
+ kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
191
+ $(KUSTOMIZE ) : $(LOCALBIN )
192
+ @if test -x $(LOCALBIN ) /kustomize && ! $(LOCALBIN ) /kustomize version | grep -q $(KUSTOMIZE_VERSION ) ; then \
193
+ echo " $( LOCALBIN) /kustomize version is not expected $( KUSTOMIZE_VERSION) . Removing it before installing." ; \
194
+ rm -rf $(LOCALBIN ) /kustomize; \
195
+ fi
196
+ test -s $(LOCALBIN ) /kustomize || { curl -Ss $( KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $( subst v,,$( KUSTOMIZE_VERSION) ) $( LOCALBIN) ; }
103
197
104
- .PHONY : helm-operator
105
- HELM_OPERATOR = $(shell pwd) /bin/helm-operator
106
- helm-operator : # # Download helm-operator locally if necessary, preferring the $(pwd)/bin path over global if both exist.
107
- ifeq (,$(wildcard $(HELM_OPERATOR ) ) )
108
- ifeq (,$(shell which helm-operator 2>/dev/null) )
109
- @{ \
110
- set -e ;\
111
- mkdir -p $(dir $(HELM_OPERATOR)) ;\
112
- curl -sSLo $(HELM_OPERATOR) https://github.com/operator-framework/operator-sdk/releases/download/v1.7.2/helm-operator_$(OS)_$(ARCH) ;\
113
- chmod +x $(HELM_OPERATOR) ;\
114
- }
115
- else
116
- HELM_OPERATOR = $(shell which helm-operator)
117
- endif
118
- endif
198
+ .PHONY : controller-gen
199
+ controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
200
+ $(CONTROLLER_GEN ) : $(LOCALBIN )
201
+ test -s $(LOCALBIN ) /controller-gen && $(LOCALBIN ) /controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION ) || \
202
+ GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
203
+
204
+ .PHONY : envtest
205
+ envtest : $(ENVTEST ) # # Download envtest-setup locally if necessary.
206
+ $(ENVTEST ) : $(LOCALBIN )
207
+ test -s $(LOCALBIN ) /setup-envtest || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
119
208
120
209
.PHONY : bundle
121
- bundle : kustomize # # Generate bundle manifests and metadata, then validate generated files.
210
+ bundle : manifests kustomize # # Generate bundle manifests and metadata, then validate generated files.
122
211
operator-sdk generate kustomize manifests -q
123
212
cd config/manager && $(KUSTOMIZE ) edit set image controller=$(IMG )
124
- $(KUSTOMIZE ) build config/manifests | operator-sdk generate bundle -q --overwrite --version $( VERSION ) $( BUNDLE_METADATA_OPTS )
213
+ $(KUSTOMIZE ) build config/manifests | operator-sdk generate bundle $( BUNDLE_GEN_FLAGS ) --extra-service-accounts core-dump-operator-uploader-sa
125
214
operator-sdk bundle validate ./bundle
126
215
127
216
.PHONY : bundle-build
@@ -140,7 +229,8 @@ ifeq (,$(shell which opm 2>/dev/null))
140
229
@{ \
141
230
set -e ;\
142
231
mkdir -p $(dir $(OPM)) ;\
143
- curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1/$(OS)-$(ARCH)-opm ;\
232
+ OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
233
+ curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\
144
234
chmod +x $(OPM) ;\
145
235
}
146
236
else
@@ -171,3 +261,25 @@ catalog-build: opm ## Build a catalog image.
171
261
.PHONY : catalog-push
172
262
catalog-push : # # Push a catalog image.
173
263
$(MAKE ) docker-push IMG=$(CATALOG_IMG )
264
+
265
+ UPLOADER_IMAGE_TAG_BASE ?= ghcr.io/ibm/core-dump-operator/core-dump-uploader
266
+
267
+ .PHONY : uploader-build
268
+ uploader-build : bin/core-dump-uploader
269
+ bin/core-dump-uploader : uploader-test cmd/core-dump-uploader/uploader.go
270
+ CGO_ENABLED=0 GOOS=linux go build -v -a -ldflags ' -extldflags "-static"' -gcflags=" all=-N -l" -o bin/core-dump-uploader ./cmd/core-dump-uploader/
271
+
272
+ .PHONY : uploader-cbuild
273
+ uploader-cbuild : bin/core-dump-uploader
274
+ cp /etc/ssl/certs/ca-certificates.crt bin/
275
+ docker build bin/ -f cmd/core-dump-uploader/Dockerfile -t $(UPLOADER_IMAGE_TAG_BASE ) :$(VERSION )
276
+
277
+ .PHONY : uploader-push
278
+ uploader-push : uploader-cbuild
279
+ docker push $(UPLOADER_IMAGE_TAG_BASE ) :$(VERSION )
280
+
281
+ .PHONY : uploader-test
282
+ uploader-test : fmt vet envtest # # Run tests.
283
+ KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " go test ./cmd/... -coverprofile uploader-cover.out
284
+ go tool cover -html=uploader-cover.out -o uploader-cover.html
285
+
0 commit comments