|
| 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 | +# external-secrets.io/external-secrets-operator-bundle:$VERSION and external-secrets.io/external-secrets-operator-catalog:$VERSION. |
| 32 | +IMAGE_TAG_BASE ?= external-secrets.io/external-secrets-operator |
| 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 | +# Image URL to use all building/pushing image targets |
| 39 | +IMG ?= controller:latest |
| 40 | + |
| 41 | +all: docker-build |
| 42 | + |
| 43 | +##@ General |
| 44 | + |
| 45 | +# The help target prints out all targets with their descriptions organized |
| 46 | +# beneath their categories. The categories are represented by '##@' and the |
| 47 | +# target descriptions by '##'. The awk commands is responsible for reading the |
| 48 | +# entire set of makefiles included in this invocation, looking for lines of the |
| 49 | +# file as xyz: ## something, and then pretty-format the target and help. Then, |
| 50 | +# if there's a line with ##@ something, that gets pretty-printed as a category. |
| 51 | +# More info on the usage of ANSI control characters for terminal formatting: |
| 52 | +# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters |
| 53 | +# More info on the awk command: |
| 54 | +# http://linuxcommand.org/lc3_adv_awk.php |
| 55 | + |
| 56 | +help: ## Display this help. |
| 57 | + @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 | + |
| 59 | +##@ Build |
| 60 | + |
| 61 | +run: helm-operator ## Run against the configured Kubernetes cluster in ~/.kube/config |
| 62 | + $(HELM_OPERATOR) run |
| 63 | + |
| 64 | +docker-build: ## Build docker image with the manager. |
| 65 | + docker build -t ${IMG} . |
| 66 | + |
| 67 | +docker-push: ## Push docker image with the manager. |
| 68 | + docker push ${IMG} |
| 69 | + |
| 70 | +##@ Deployment |
| 71 | + |
| 72 | +install: kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. |
| 73 | + $(KUSTOMIZE) build config/crd | kubectl apply -f - |
| 74 | + |
| 75 | +uninstall: kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. |
| 76 | + $(KUSTOMIZE) build config/crd | kubectl delete -f - |
| 77 | + |
| 78 | +deploy: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. |
| 79 | + cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} |
| 80 | + $(KUSTOMIZE) build config/default | kubectl apply -f - |
| 81 | + |
| 82 | +undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. |
| 83 | + $(KUSTOMIZE) build config/default | kubectl delete -f - |
| 84 | + |
| 85 | +OS := $(shell uname -s | tr '[:upper:]' '[:lower:]') |
| 86 | +ARCH := $(shell uname -m | sed 's/x86_64/amd64/') |
| 87 | + |
| 88 | +.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.8.7/kustomize_v3.8.7_$(OS)_$(ARCH).tar.gz | \ |
| 97 | + tar xzf - -C bin/ ;\ |
| 98 | + } |
| 99 | +else |
| 100 | +KUSTOMIZE = $(shell which kustomize) |
| 101 | +endif |
| 102 | +endif |
| 103 | + |
| 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.15.0/helm-operator_$(OS)_$(ARCH) ;\ |
| 113 | + chmod +x $(HELM_OPERATOR) ;\ |
| 114 | + } |
| 115 | +else |
| 116 | +HELM_OPERATOR = $(shell which helm-operator) |
| 117 | +endif |
| 118 | +endif |
| 119 | + |
| 120 | +.PHONY: bundle |
| 121 | +bundle: kustomize ## Generate bundle manifests and metadata, then validate generated files. |
| 122 | + operator-sdk generate kustomize manifests -q |
| 123 | + 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) |
| 125 | + operator-sdk bundle validate ./bundle |
| 126 | + |
| 127 | +.PHONY: bundle-build |
| 128 | +bundle-build: ## Build the bundle image. |
| 129 | + docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . |
| 130 | + |
| 131 | +.PHONY: bundle-push |
| 132 | +bundle-push: ## Push the bundle image. |
| 133 | + $(MAKE) docker-push IMG=$(BUNDLE_IMG) |
| 134 | + |
| 135 | +.PHONY: opm |
| 136 | +OPM = ./bin/opm |
| 137 | +opm: ## Download opm locally if necessary. |
| 138 | +ifeq (,$(wildcard $(OPM))) |
| 139 | +ifeq (,$(shell which opm 2>/dev/null)) |
| 140 | + @{ \ |
| 141 | + set -e ;\ |
| 142 | + mkdir -p $(dir $(OPM)) ;\ |
| 143 | + curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1/$(OS)-$(ARCH)-opm ;\ |
| 144 | + chmod +x $(OPM) ;\ |
| 145 | + } |
| 146 | +else |
| 147 | +OPM = $(shell which opm) |
| 148 | +endif |
| 149 | +endif |
| 150 | + |
| 151 | +# 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). |
| 152 | +# These images MUST exist in a registry and be pull-able. |
| 153 | +BUNDLE_IMGS ?= $(BUNDLE_IMG) |
| 154 | + |
| 155 | +# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0). |
| 156 | +CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION) |
| 157 | + |
| 158 | +# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image. |
| 159 | +ifneq ($(origin CATALOG_BASE_IMG), undefined) |
| 160 | +FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG) |
| 161 | +endif |
| 162 | + |
| 163 | +# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'. |
| 164 | +# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see: |
| 165 | +# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator |
| 166 | +.PHONY: catalog-build |
| 167 | +catalog-build: opm ## Build a catalog image. |
| 168 | + $(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) |
| 169 | + |
| 170 | +# Push the catalog image. |
| 171 | +.PHONY: catalog-push |
| 172 | +catalog-push: ## Push a catalog image. |
| 173 | + $(MAKE) docker-push IMG=$(CATALOG_IMG) |
0 commit comments