|
| 1 | +# VERSION defines the project version for the bundle. |
| 2 | +# Update this value when you upgrade the version of your project. |
| 3 | +# To re-generate a bundle for another specific version without changing the standard setup, you can: |
| 4 | +# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2) |
| 5 | +# - use environment variables to overwrite this value (e.g export VERSION=0.0.2) |
| 6 | +VERSION ?= 0.0.1 |
| 7 | + |
| 8 | +# CHANNELS define the bundle channels used in the bundle. |
| 9 | +# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable") |
| 10 | +# To re-generate a bundle for other specific channels without changing the standard setup, you can: |
| 11 | +# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable) |
| 12 | +# - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable") |
| 13 | +ifneq ($(origin CHANNELS), undefined) |
| 14 | +BUNDLE_CHANNELS := --channels=$(CHANNELS) |
| 15 | +endif |
| 16 | + |
| 17 | +# DEFAULT_CHANNEL defines the default channel used in the bundle. |
| 18 | +# Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable") |
| 19 | +# To re-generate a bundle for any other default channel without changing the default setup, you can: |
| 20 | +# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable) |
| 21 | +# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable") |
| 22 | +ifneq ($(origin DEFAULT_CHANNEL), undefined) |
| 23 | +BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL) |
| 24 | +endif |
| 25 | +BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) |
| 26 | + |
| 27 | +# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images. |
| 28 | +# This variable is used to construct full image tags for bundle and catalog images. |
| 29 | +# |
| 30 | +# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both |
| 31 | +# kube-ovn-operator.com/vpn-gw-bundle:$VERSION and kube-ovn-operator.com/vpn-gw-catalog:$VERSION. |
| 32 | +IMAGE_TAG_BASE ?= kube-ovn-operator.com/vpn-gw |
| 33 | + |
| 34 | +# BUNDLE_IMG defines the image:tag used for the bundle. |
| 35 | +# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>) |
| 36 | +BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION) |
| 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 | + |
| 49 | +# Image URL to use all building/pushing image targets |
| 50 | +IMG ?= controller:latest |
| 51 | +# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. |
| 52 | +ENVTEST_K8S_VERSION = 1.26.0 |
| 53 | + |
| 54 | +# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) |
| 55 | +ifeq (,$(shell go env GOBIN)) |
| 56 | +GOBIN=$(shell go env GOPATH)/bin |
| 57 | +else |
| 58 | +GOBIN=$(shell go env GOBIN) |
| 59 | +endif |
| 60 | + |
| 61 | +# Setting SHELL to bash allows bash commands to be executed by recipes. |
| 62 | +# Options are set to exit when a recipe line exits non-zero or a piped command fails. |
| 63 | +SHELL = /usr/bin/env bash -o pipefail |
| 64 | +.SHELLFLAGS = -ec |
| 65 | + |
| 66 | +.PHONY: all |
| 67 | +all: build |
| 68 | + |
| 69 | +##@ General |
| 70 | + |
| 71 | +# The help target prints out all targets with their descriptions organized |
| 72 | +# beneath their categories. The categories are represented by '##@' and the |
| 73 | +# target descriptions by '##'. The awk commands is responsible for reading the |
| 74 | +# entire set of makefiles included in this invocation, looking for lines of the |
| 75 | +# file as xyz: ## something, and then pretty-format the target and help. Then, |
| 76 | +# if there's a line with ##@ something, that gets pretty-printed as a category. |
| 77 | +# More info on the usage of ANSI control characters for terminal formatting: |
| 78 | +# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters |
| 79 | +# More info on the awk command: |
| 80 | +# http://linuxcommand.org/lc3_adv_awk.php |
| 81 | + |
| 82 | +.PHONY: help |
| 83 | +help: ## Display this help. |
| 84 | + @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) |
| 85 | + |
| 86 | +##@ Development |
| 87 | + |
| 88 | +.PHONY: manifests |
| 89 | +manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. |
| 90 | + $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases |
| 91 | + |
| 92 | +.PHONY: generate |
| 93 | +generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. |
| 94 | + $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." |
| 95 | + |
| 96 | +.PHONY: fmt |
| 97 | +fmt: ## Run go fmt against code. |
| 98 | + go fmt ./... |
| 99 | + |
| 100 | +.PHONY: vet |
| 101 | +vet: ## Run go vet against code. |
| 102 | + go vet ./... |
| 103 | + |
| 104 | +.PHONY: test |
| 105 | +test: manifests generate fmt vet envtest ## Run tests. |
| 106 | + KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out |
| 107 | + |
| 108 | +##@ Build |
| 109 | + |
| 110 | +.PHONY: build |
| 111 | +build: manifests generate fmt vet ## Build manager binary. |
| 112 | + go build -o bin/manager cmd/main.go |
| 113 | + |
| 114 | +.PHONY: run |
| 115 | +run: manifests generate fmt vet ## Run a controller from your host. |
| 116 | + go run ./cmd/main.go |
| 117 | + |
| 118 | +# If you wish built the manager image targeting other platforms you can use the --platform flag. |
| 119 | +# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it. |
| 120 | +# More info: https://docs.docker.com/develop/develop-images/build_enhancements/ |
| 121 | +.PHONY: docker-build |
| 122 | +docker-build: test ## Build docker image with the manager. |
| 123 | + docker build -t ${IMG} . |
| 124 | + |
| 125 | +.PHONY: docker-push |
| 126 | +docker-push: ## Push docker image with the manager. |
| 127 | + docker push ${IMG} |
| 128 | + |
| 129 | +# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple |
| 130 | +# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to: |
| 131 | +# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/ |
| 132 | +# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/ |
| 133 | +# - 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) |
| 134 | +# To properly provided solutions that supports more than one platform you should use this option. |
| 135 | +PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le |
| 136 | +.PHONY: docker-buildx |
| 137 | +docker-buildx: test ## Build and push docker image for the manager for cross-platform support |
| 138 | + # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile |
| 139 | + sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross |
| 140 | + - docker buildx create --name project-v3-builder |
| 141 | + docker buildx use project-v3-builder |
| 142 | + - docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross . |
| 143 | + - docker buildx rm project-v3-builder |
| 144 | + rm Dockerfile.cross |
| 145 | + |
| 146 | +##@ Deployment |
| 147 | + |
| 148 | +ifndef ignore-not-found |
| 149 | + ignore-not-found = false |
| 150 | +endif |
| 151 | + |
| 152 | +.PHONY: install |
| 153 | +install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. |
| 154 | + $(KUSTOMIZE) build config/crd | kubectl apply -f - |
| 155 | + |
| 156 | +.PHONY: uninstall |
| 157 | +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. |
| 158 | + $(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f - |
| 159 | + |
| 160 | +.PHONY: deploy |
| 161 | +deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. |
| 162 | + cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} |
| 163 | + $(KUSTOMIZE) build config/default | kubectl apply -f - |
| 164 | + |
| 165 | +.PHONY: undeploy |
| 166 | +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. |
| 167 | + $(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f - |
| 168 | + |
| 169 | +##@ Build Dependencies |
| 170 | + |
| 171 | +## Location to install dependencies to |
| 172 | +LOCALBIN ?= $(shell pwd)/bin |
| 173 | +$(LOCALBIN): |
| 174 | + mkdir -p $(LOCALBIN) |
| 175 | + |
| 176 | +## Tool Binaries |
| 177 | +KUSTOMIZE ?= $(LOCALBIN)/kustomize |
| 178 | +CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen |
| 179 | +ENVTEST ?= $(LOCALBIN)/setup-envtest |
| 180 | + |
| 181 | +## Tool Versions |
| 182 | +KUSTOMIZE_VERSION ?= v4.5.7 |
| 183 | +CONTROLLER_TOOLS_VERSION ?= v0.11.1 |
| 184 | + |
| 185 | +KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" |
| 186 | +.PHONY: kustomize |
| 187 | +kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading. |
| 188 | +$(KUSTOMIZE): $(LOCALBIN) |
| 189 | + @if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \ |
| 190 | + echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \ |
| 191 | + rm -rf $(LOCALBIN)/kustomize; \ |
| 192 | + fi |
| 193 | + test -s $(LOCALBIN)/kustomize || { curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); } |
| 194 | + |
| 195 | +.PHONY: controller-gen |
| 196 | +controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten. |
| 197 | +$(CONTROLLER_GEN): $(LOCALBIN) |
| 198 | + test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \ |
| 199 | + GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) |
| 200 | + |
| 201 | +.PHONY: envtest |
| 202 | +envtest: $(ENVTEST) ## Download envtest-setup locally if necessary. |
| 203 | +$(ENVTEST): $(LOCALBIN) |
| 204 | + test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest |
| 205 | + |
| 206 | +.PHONY: bundle |
| 207 | +bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files. |
| 208 | + operator-sdk generate kustomize manifests -q |
| 209 | + cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) |
| 210 | + $(KUSTOMIZE) build config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS) |
| 211 | + operator-sdk bundle validate ./bundle |
| 212 | + |
| 213 | +.PHONY: bundle-build |
| 214 | +bundle-build: ## Build the bundle image. |
| 215 | + docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . |
| 216 | + |
| 217 | +.PHONY: bundle-push |
| 218 | +bundle-push: ## Push the bundle image. |
| 219 | + $(MAKE) docker-push IMG=$(BUNDLE_IMG) |
| 220 | + |
| 221 | +.PHONY: opm |
| 222 | +OPM = ./bin/opm |
| 223 | +opm: ## Download opm locally if necessary. |
| 224 | +ifeq (,$(wildcard $(OPM))) |
| 225 | +ifeq (,$(shell which opm 2>/dev/null)) |
| 226 | + @{ \ |
| 227 | + set -e ;\ |
| 228 | + mkdir -p $(dir $(OPM)) ;\ |
| 229 | + OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \ |
| 230 | + curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\ |
| 231 | + chmod +x $(OPM) ;\ |
| 232 | + } |
| 233 | +else |
| 234 | +OPM = $(shell which opm) |
| 235 | +endif |
| 236 | +endif |
| 237 | + |
| 238 | +# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0). |
| 239 | +# These images MUST exist in a registry and be pull-able. |
| 240 | +BUNDLE_IMGS ?= $(BUNDLE_IMG) |
| 241 | + |
| 242 | +# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0). |
| 243 | +CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION) |
| 244 | + |
| 245 | +# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image. |
| 246 | +ifneq ($(origin CATALOG_BASE_IMG), undefined) |
| 247 | +FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG) |
| 248 | +endif |
| 249 | + |
| 250 | +# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'. |
| 251 | +# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see: |
| 252 | +# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator |
| 253 | +.PHONY: catalog-build |
| 254 | +catalog-build: opm ## Build a catalog image. |
| 255 | + $(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) |
| 256 | + |
| 257 | +# Push the catalog image. |
| 258 | +.PHONY: catalog-push |
| 259 | +catalog-push: ## Push a catalog image. |
| 260 | + $(MAKE) docker-push IMG=$(CATALOG_IMG) |
0 commit comments