github.com/operator-framework/operator-lifecycle-manager@v0.30.0/Makefile (about) 1 ##################################################### 2 # Operator-Framework - Operator Lifecycle Manager # 3 ##################################################### 4 5 # Setting SHELL to bash allows bash commands to be executed by recipes. 6 # Options are set to exit when a recipe line exits non-zero or a piped command fails. 7 SHELL := /usr/bin/env bash -o pipefail 8 .SHELLFLAGS := -ec 9 10 # Undefine GOFLAGS environment variable. 11 ifdef GOFLAGS 12 $(warning Undefining GOFLAGS set in CI) 13 undefine GOFLAGS 14 endif 15 16 # Tools # 17 18 # The tools required to build and test the project come from three sources: 19 # 1. .bingo/Variables.mk: tools that are orthogonal to OLM, e.g. 20 # - golangci-lint 21 # - helm 22 # - kind 23 # - setup-envtest 24 # - yq 25 # 2. go.mod/tools.go: imports testing libraries, modules that need to be vendored and/or have a low tolerance for skew with the main module 26 # or because they are already imported by the main module but we want to pull down the whole dependency 27 # to run some cmd or script, or get some resource (e.g. CRD yaml files). 28 # - OLM API CRDs 29 # - Code generation tools, e.g. k8s.io/code-generator 30 31 # bingo manages the type 1 tools. If 32 # a) we don't want their dependencies affecting ours, and 33 # b) the tool's version doesn't need to track closely with OLM 34 # the tool goes here 35 include .bingo/Variables.mk 36 37 # go.mod/tools.go manages type 2 tools. If 38 # a) we use the library for development, e.g testing, assertion, etc. 39 # b) we need some resource (e.g. yaml file) 40 # c) need to run a script that is in the library 41 # c) need to track tools closely with OLM (e.g. have the same k8s library version) 42 # the tools belongs in go.mod. If your normal imports don't pull down everything you need into vendor 43 # then add the import to tools.go 44 # Note: The code generation tools are either being used in go:generate directives or 45 # they are setup in a different script, e.g. ./scripts/update_codegen.sh 46 TOOL_EXEC := go run -mod=vendor 47 GINKGO := $(TOOL_EXEC) github.com/onsi/ginkgo/v2/ginkgo 48 49 # Target environment and Dependencies # 50 51 # Minor Kubernetes version to build against derived from the client-go dependency version 52 KUBE_MINOR ?= $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1/') 53 54 # operator registry version to build against 55 OPERATOR_REGISTRY_VERSION ?= $(shell go list -m github.com/operator-framework/operator-registry | cut -d" " -f2 | sed 's/^v//') 56 57 # Pin operator registry images to the same version as the operator registry 58 export OPERATOR_REGISTRY_TAG ?= v$(OPERATOR_REGISTRY_VERSION) 59 export OPERATOR_REGISTRY_IMAGE ?= quay.io/operator-framework/opm:$(OPERATOR_REGISTRY_TAG) 60 export CONFIGMAP_SERVER_IMAGE ?= quay.io/operator-framework/configmap-operator-registry:$(OPERATOR_REGISTRY_TAG) 61 62 # Artifact settings # 63 64 PKG := github.com/operator-framework/operator-lifecycle-manager 65 IMAGE_REPO ?= quay.io/operator-framework/olm 66 IMAGE_TAG ?= "dev" 67 68 # Go build settings # 69 70 export CGO_ENABLED ?= 0 71 export GO111MODULE ?= on 72 export GIT_REPO := $(shell go list -m) 73 export GIT_COMMIT := $(shell git rev-parse HEAD) 74 export VERSION_PATH := ${GIT_REPO}/pkg/version 75 76 ifeq ($(origin VERSION), undefined) 77 VERSION := $(shell git describe --tags --always --dirty) 78 endif 79 export VERSION 80 81 # GO_BUILD flags are set with = to allow for re-evaluation of the variables 82 export GO_BUILD_ASMFLAGS = all=-trimpath=$(PWD) 83 export GO_BUILD_GCFLAGS = all=-trimpath=$(PWD) 84 export GO_BUILD_FLAGS = -mod=vendor -buildvcs=false 85 export GO_BUILD_LDFLAGS = -s -w -X '$(VERSION_PATH).OLMVersion=$(VERSION)' -X '$(VERSION_PATH).GitCommit=$(GIT_COMMIT)' -extldflags "-static" 86 export GO_BUILD_TAGS = json1 87 88 # GO_TEST flags are set with = to allow for re-evaluation of the variables 89 # CGO_ENABLED=1 is required by the go test -race flag 90 GO_TEST_FLAGS = -race -count=1 $(if $(TEST),-run '$(TEST)',) 91 GO_TEST_ENV = CGO_ENABLED=1 92 93 # Test environment configuration # 94 95 # By default setup-envtest will write to $XDG_DATA_HOME, or $HOME/.local/share if that is not defined. 96 # If $HOME is not set, we need to specify a binary directory to prevent an error in setup-envtest. 97 # Useful for some CI/CD environments that set neither $XDG_DATA_HOME nor $HOME. 98 SETUP_ENVTEST_BIN_DIR_OVERRIDE= 99 ifeq ($(shell [[ $$HOME == "" || $$HOME == "/" ]] && [[ $$XDG_DATA_HOME == "" ]] && echo true ), true) 100 SETUP_ENVTEST_BIN_DIR_OVERRIDE += --bin-dir /tmp/envtest-binaries 101 endif 102 103 # Unit test against the latest available version for the minor version of kubernetes we are building against e.g. 1.30.x 104 ENVTEST_KUBE_VERSION ?= $(KUBE_MINOR).x 105 KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use -p path $(KUBE_MINOR).x) 106 107 # Kind node image tags are in the format x.y.z we pin to version x.y.0 because patch releases and node images 108 # are not guaranteed to be available when a new version of the kube apis is released 109 KIND_CLUSTER_IMAGE := kindest/node:v$(KUBE_MINOR).0 110 KIND_CLUSTER_NAME ?= kind-olmv0 111 112 # Targets # 113 # Disable -j flag for make 114 .NOTPARALLEL: 115 116 .DEFAULT_GOAL := build 117 118 #SECTION General 119 120 .PHONY: all 121 all: test image #HELP Unit test, and build operator image 122 123 .PHONY: help 124 help: #HELP Display this help message 125 @awk 'BEGIN {FS = ":.*#(EX)?HELP"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*#(EX)?HELP / { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^#SECTION / { printf "\n\033[1m%s\033[0m\n", substr($$0, 10) } ' $(MAKEFILE_LIST) 126 127 #SECTION Build 128 129 # Note: We want to use BUILDCMD = because we need it to be re-evaluated every time it is used 130 # since different targets might have different go build flags 131 BUILD_CMD = go build $(GO_BUILD_FLAGS) -ldflags '$(GO_BUILD_LDFLAGS)' -tags '$(GO_BUILD_TAGS)' -gcflags '$(GO_BUILD_GCFLAGS)' -asmflags '$(GO_BUILD_ASMFLAGS)' 132 133 CMDS := $(shell go list $(GO_BUILD_FLAGS) ./cmd/...) 134 $(CMDS): FORCE 135 @echo "Building $(@)" 136 $(BUILD_CMD) -o ./bin/$(shell basename $@) ./cmd/$(notdir $@) 137 138 .PHONY: build-utils 139 build-utils: #HELP Build utility binaries for local OS/ARCH 140 $(BUILD_CMD) -o ./bin/cpb ./util/cpb 141 142 .PHONY: build #HELP Build binaries for local OS/ARCH 143 build: build-utils $(CMDS) 144 145 .PHONY: image 146 # Set GOOS to linux to build a linux binary for the image 147 # Don't set GOARCH because we want the default host architecture - this is important for developers on MacOS 148 image: export GOOS = linux 149 image: clean build #HELP Build image image for linux on host architecture 150 docker build -t $(IMAGE_REPO):$(IMAGE_TAG) -f Dockerfile bin 151 152 .PHONY: e2e-build 153 # the e2e and experimental_metrics tags are required to get e2e tests to pass 154 # search the code for go:build e2e or go:build experimental_metrics to see where these tags are used 155 e2e-build: export GO_BUILD_TAGS += e2e experimental_metrics #HELP Build image for e2e testing 156 e2e-build: IMAGE_TAG = local 157 e2e-build: image 158 159 .PHONY: clean 160 clean: #HELP Clean up build artifacts 161 @rm -rf cover.out 162 @rm -rf bin 163 164 #SECTION Development 165 166 .PHONY: lint 167 lint: $(GOLANGCI_LINT) #HELP Run linters 168 $(GOLANGCI_LINT) run $(GOLANGCI_LINT_ARGS) 169 170 .PHONY: vet 171 vet: #HELP Run go vet 172 go vet $(GO_BUILD_FLAGS) ./... 173 174 .PHONY: fmt 175 fmt: #HELP Run go fmt 176 go fmt ./... 177 178 vendor: #HELP Update vendored dependencies 179 go mod tidy 180 go mod vendor 181 182 #SECTION Testing 183 184 # Note: We want to use TESTCMD = because we need it to be re-evaluated every time it is used 185 # since different targets might have different settings 186 UNIT_TEST_CMD = $(GO_TEST_ENV) go test $(GO_BUILD_FLAGS) -tags '$(GO_BUILD_TAGS)' $(GO_TEST_FLAGS) 187 188 .PHONE: test 189 test: clean unit test-split #HELP Run all tests 190 191 .PHONY: unit 192 unit: GO_TEST_ENV += KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" 193 unit: $(SETUP_ENVTEST) #HELP Run OLM unit tests with setup-envtest for kubernetes $(KUBE_MINOR).x 194 $(UNIT_TEST_CMD) ./pkg/controller/... ./pkg/... 195 196 .PHONY: test-split 197 test-split: #HELP Run e2e test split utility unit tests 198 # Test the e2e test split utility 199 $(UNIT_TEST_CMD) ./test/e2e/split/... 200 201 .PHONY: coverage 202 coverage: GO_TEST_FLAGS += -coverprofile=cover.out -covermode=atomic -coverpkg 203 coverage: unit #HELP Run OLM unit tests with coverage 204 go tool cover -func=cover.out 205 206 #SECTION Deployment 207 208 .PHONY: kind-clean 209 kind-clean: $(KIND) #HELP Delete kind cluster $KIND_CLUSTER_NAME (default: kind-olmv0) 210 $(KIND) delete cluster --name $(KIND_CLUSTER_NAME) || true 211 212 .PHONY: kind-create 213 kind-create: kind-clean #HELP Create a new kind cluster $KIND_CLUSTER_NAME (default: kind-olmv0) 214 $(KIND) create cluster --name $(KIND_CLUSTER_NAME) --image $(KIND_CLUSTER_IMAGE) $(KIND_CREATE_OPTS) 215 $(KIND) export kubeconfig --name $(KIND_CLUSTER_NAME) 216 217 .PHONY: deploy 218 OLM_IMAGE := quay.io/operator-framework/olm:local 219 deploy: $(KIND) $(HELM) #HELP Deploy OLM to kind cluster $KIND_CLUSTER_NAME (default: kind-olmv0) using $OLM_IMAGE (default: quay.io/operator-framework/olm:local) 220 $(KIND) load docker-image $(OLM_IMAGE) --name $(KIND_CLUSTER_NAME); \ 221 $(HELM) upgrade --install olm deploy/chart \ 222 --set debug=true \ 223 --set olm.image.ref=$(OLM_IMAGE) \ 224 --set olm.image.pullPolicy=IfNotPresent \ 225 --set catalog.image.ref=$(OLM_IMAGE) \ 226 --set catalog.image.pullPolicy=IfNotPresent \ 227 --set catalog.commandArgs=--configmapServerImage=$(CONFIGMAP_SERVER_IMAGE) \ 228 --set catalog.opmImageArgs=--opmImage=$(OPERATOR_REGISTRY_IMAGE) \ 229 --set package.image.ref=$(OLM_IMAGE) \ 230 --set package.image.pullPolicy=IfNotPresent \ 231 $(HELM_INSTALL_OPTS) \ 232 --wait; 233 234 .PHONY: undeploy 235 undeploy: $(KIND) $(HELM) #HELP Uninstall OLM from kind cluster $KIND_CLUSTER_NAME (default: kind-olmv0) 236 $(KIND) export kubeconfig --name $(KIND_CLUSTER_NAME) 237 238 # Uninstall Helm chart and remove CRDs 239 kubectl delete --all-namespaces --all sub 240 kubectl delete --all-namespaces --all ip 241 kubectl delete --all-namespaces --all csv 242 kubectl delete --all-namespaces --all catsrc 243 $(HELM) uninstall olm 244 kubectl delete -f deploy/chart/crds 245 246 #SECTION e2e 247 248 # E2E test configuration 249 # Can be overridden when running make e2e, e.g. E2E_TIMEOUT=60m make e2e/e2e-local 250 E2E_TIMEOUT ?= 90m 251 E2E_TEST_NS ?= operators 252 E2E_INSTALL_NS ?= operator-lifecycle-manager 253 E2E_CATALOG_NS ?= $(E2E_INSTALL_NS) 254 GINKGO_OPTS += -v -randomize-suites -race -trace $(if $(E2E_FLAKE_ATTEMPTS),--flake-attempts='$(E2E_FLAKE_ATTEMPTS)') $(if $(E2E_SEED),-seed '$(E2E_SEED)') $(if $(TEST),-focus '$(TEST)',) $(if $(SKIP), -skip '$(SKIP)') 255 256 .PHONY: e2e 257 e2e: #HELP Run e2e tests against a cluster running OLM (params: $E2E_TEST_NS (operator), $E2E_INSTALL_NS (operator-lifecycle-manager), $E2E_CATALOG_NS (operator-lifecycle-manager), $E2E_TIMEOUT (90m), $E2E_FLAKE_ATTEMPTS (1), $TEST(undefined)) 258 $(GO_TEST_ENV) $(GINKGO) -timeout $(E2E_TIMEOUT) $(GINKGO_OPTS) $(E2E_GINKGO_OPTS) ./test/e2e -- -namespace=$(E2E_TEST_NS) -olmNamespace=$(E2E_INSTALL_NS) -catalogNamespace=$(E2E_CATALOG_NS) $(E2E_OPTS) 259 260 .PHONY: e2e-local 261 e2e-local: e2e-build kind-create deploy e2e 262 263 #SECTION Code Generation 264 265 .PHONY: gen-all #HELP Update OLM API, generate code and mocks 266 gen-all: manifests codegen mockgen 267 268 .PHONY: manifests 269 manifests: vendor #HELP Copy OLM API CRD manifests to deploy/chart/crds 270 ./scripts/copy_crds.sh 271 272 .PHONY: codegen 273 codegen: #HELP Generate clients, deepcopy, listers, and informers 274 ./scripts/update_codegen.sh 275 276 .PHONY: mockgen 277 mockgen: #HELP Generate mocks 278 # Generate mocks and silence the followign warning: 279 # WARNING: Invoking counterfeiter multiple times from "go generate" is slow. 280 # Consider using counterfeiter:generate directives to speed things up. 281 # See https://github.com/maxbrunsfeld/counterfeiter#step-2b---add-counterfeitergenerate-directives for more information. 282 # Set the "COUNTERFEITER_NO_GENERATE_WARNING" environment variable to suppress this message. 283 COUNTERFEITER_NO_GENERATE_WARNING=1 go generate ./pkg/... 284 285 #SECTION Verification 286 287 .PHONY: diff 288 diff: 289 git diff --exit-code 290 291 .PHONY: verify-codegen 292 verify-codegen: codegen #HELP Check client, deepcopy, listers, and informers are up to date 293 $(MAKE) diff 294 295 .PHONY: verify-mockgen 296 verify-mockgen: mockgen #HELP Check mocks are up to date 297 $(MAKE) diff 298 299 .PHONY: verify-manifests 300 verify-manifests: manifests #HELP Check CRD manifests are up to date 301 $(MAKE) diff 302 303 .PHONY: verify 304 verify: vendor verify-codegen verify-mockgen verify-manifests #HELP Run all verification checks 305 $(MAKE) diff 306 307 #SECTION Release 308 309 .PHONY: pull-opm 310 pull-opm: 311 docker pull $(OPERATOR_REGISTRY_IMAGE) 312 313 .PHONY: package 314 package: $(YQ) $(HELM) #HELP Package OLM for release 315 package: OLM_RELEASE_IMG_REF=$(shell docker inspect --format='{{index .RepoDigests 0}}' $(IMAGE_REPO):$(RELEASE_VERSION)) 316 package: OPM_IMAGE_REF=$(shell docker inspect --format='{{index .RepoDigests 0}}' $(OPERATOR_REGISTRY_IMAGE)) 317 package: 318 ifndef TARGET 319 $(error TARGET is undefined) 320 endif 321 ifndef RELEASE_VERSION 322 $(error RELEASE_VERSION is undefined) 323 endif 324 @echo "Getting operator registry image" 325 docker pull $(OPERATOR_REGISTRY_IMAGE) 326 $(YQ) w -i deploy/$(TARGET)/values.yaml olm.image.ref $(OLM_RELEASE_IMG_REF) 327 $(YQ) w -i deploy/$(TARGET)/values.yaml catalog.image.ref $(OLM_RELEASE_IMG_REF) 328 $(YQ) w -i deploy/$(TARGET)/values.yaml package.image.ref $(OLM_RELEASE_IMG_REF) 329 $(YQ) w -i deploy/$(TARGET)/values.yaml -- catalog.opmImageArgs "--opmImage=$(OPM_IMAGE_REF)" 330 ./scripts/package_release.sh $(RELEASE_VERSION) deploy/$(TARGET)/manifests/$(RELEASE_VERSION) deploy/$(TARGET)/values.yaml 331 ln -sfFn ./$(RELEASE_VERSION) deploy/$(TARGET)/manifests/latest 332 ifeq ($(PACKAGE_QUICKSTART), true) 333 ./scripts/package_quickstart.sh deploy/$(TARGET)/manifests/$(RELEASE_VERSION) deploy/$(TARGET)/quickstart/olm.yaml deploy/$(TARGET)/quickstart/crds.yaml deploy/$(TARGET)/quickstart/install.sh 334 endif 335 336 .PHONY: release 337 release: pull-opm manifests # pull the opm image to get the digest 338 @echo "Generating the $(RELEASE_VERSION) release" 339 docker pull $(IMAGE_REPO):$(RELEASE_VERSION) 340 $(MAKE) TARGET=upstream RELEASE_VERSION=$(RELEASE_VERSION) PACKAGE_QUICKSTART=true package 341 342 .PHONY: FORCE 343 FORCE: