|
1 |
| -OLD_TAG = 0.1.0 |
2 |
| -TAG = 0.2.0 |
| 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.3.0 |
3 | 7 |
|
4 |
| -IMAGE = nginx/nginx-ingress-operator |
| 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 = "preview,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=preview,fast,stable) |
| 12 | +# - use environment variables to overwrite this value (e.g export CHANNELS="preview,fast,stable") |
| 13 | +ifneq ($(origin CHANNELS), undefined) |
| 14 | +BUNDLE_CHANNELS := --channels=$(CHANNELS) |
| 15 | +endif |
5 | 16 |
|
6 |
| -test: |
7 |
| - GO111MODULE=on go test ./... |
| 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) |
8 | 26 |
|
9 |
| -binary: |
10 |
| - $(eval GOPATH=$(shell go env GOPATH)) |
11 |
| - CGO_ENABLED=0 GO111MODULE=on GOFLAGS="-gcflags=-trimpath=${GOPATH} -asmflags=-trimpath=${GOPATH}" GOOS=linux go build -trimpath -ldflags "-s -w" -o build/_output/bin/nginx-ingress-operator github.com/nginxinc/nginx-ingress-operator/cmd/manager |
| 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 | +# nginx/nginx-ingress-operator-bundle:$VERSION and nginx/nginx-ingress-operator-catalog:$VERSION. |
| 32 | +IMAGE_TAG_BASE ?= nginx/nginx-ingress-operator |
12 | 33 |
|
13 |
| -build: binary |
14 |
| - docker build -f build/Dockerfile -t $(IMAGE):$(TAG) . |
| 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) |
15 | 37 |
|
16 |
| -run-local: |
17 |
| - go run github.com/operator-framework/operator-sdk/cmd/operator-sdk run local |
| 38 | +# Image URL to use all building/pushing image targets |
| 39 | +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" |
18 | 42 |
|
19 |
| -generate-crds: |
20 |
| - go run github.com/operator-framework/operator-sdk/cmd/operator-sdk generate k8s && operator-sdk generate crds --crd-version v1beta1 |
| 43 | +# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) |
| 44 | +ifeq (,$(shell go env GOBIN)) |
| 45 | +GOBIN=$(shell go env GOPATH)/bin |
| 46 | +else |
| 47 | +GOBIN=$(shell go env GOBIN) |
| 48 | +endif |
21 | 49 |
|
22 |
| -lint: |
23 |
| - go run github.com/golangci/golangci-lint/cmd/golangci-lint run |
| 50 | +# Setting SHELL to bash allows bash commands to be executed by recipes. |
| 51 | +# This is a requirement for 'setup-envtest.sh' in the test target. |
| 52 | +# Options are set to exit when a recipe line exits non-zero or a piped command fails. |
| 53 | +SHELL = /usr/bin/env bash -o pipefail |
| 54 | +.SHELLFLAGS = -ec |
24 | 55 |
|
25 |
| -generate-metadata: generate-crds |
26 |
| - go run github.com/operator-framework/operator-sdk/cmd/operator-sdk generate csv --csv-version=$(TAG) --from-version=$(OLD_TAG) --make-manifests=false |
27 |
| - echo "Metadata generated, please make sure you add/update fields in nginx-ingress-operator.v$(TAG).clusterserviceversion.yaml" |
| 56 | +all: build |
28 | 57 |
|
29 |
| -generate-bundle: |
30 |
| - @mkdir bundle/$(TAG) |
31 |
| - @cp deploy/crds/* bundle/$(TAG) |
32 |
| - @cp deploy/olm-catalog/nginx-ingress-operator/nginx-ingress-operator.package.yaml bundle/ |
33 |
| - @cp -R deploy/olm-catalog/nginx-ingress-operator/$(TAG)/ bundle/$(TAG)/ |
34 |
| - cd bundle && opm alpha bundle generate -d ./$(TAG)/ -u ./$(TAG)/ |
35 |
| - @mv bundle/bundle.Dockerfile bundle/bundle-$(TAG).Dockerfile |
36 |
| - @echo '\nLABEL com.redhat.openshift.versions="v4.5,v4.6"\nLABEL com.redhat.delivery.operator.bundle=true\nLABEL com.redhat.delivery.backport=true' >> bundle/bundle-$(TAG).Dockerfile |
37 |
| - docker build -t bundle:$(TAG) -f bundle/bundle-$(TAG).Dockerfile ./bundle |
| 58 | +##@ General |
38 | 59 |
|
39 |
| -.PHONY: build |
| 60 | +# The help target prints out all targets with their descriptions organized |
| 61 | +# beneath their categories. The categories are represented by '##@' and the |
| 62 | +# target descriptions by '##'. The awk commands is responsible for reading the |
| 63 | +# entire set of makefiles included in this invocation, looking for lines of the |
| 64 | +# file as xyz: ## something, and then pretty-format the target and help. Then, |
| 65 | +# if there's a line with ##@ something, that gets pretty-printed as a category. |
| 66 | +# More info on the usage of ANSI control characters for terminal formatting: |
| 67 | +# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters |
| 68 | +# More info on the awk command: |
| 69 | +# http://linuxcommand.org/lc3_adv_awk.php |
| 70 | + |
| 71 | +help: ## Display this help. |
| 72 | + @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) |
| 73 | + |
| 74 | +##@ Development |
| 75 | + |
| 76 | +manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. |
| 77 | + $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases |
| 78 | + |
| 79 | +generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. |
| 80 | + $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." |
| 81 | + |
| 82 | +fmt: ## Run go fmt against code. |
| 83 | + go fmt ./... |
| 84 | + |
| 85 | +vet: ## Run go vet against code. |
| 86 | + go vet ./... |
| 87 | + |
| 88 | +ENVTEST_ASSETS_DIR=$(shell pwd)/testbin |
| 89 | +test: manifests generate fmt vet ## Run tests. |
| 90 | + mkdir -p ${ENVTEST_ASSETS_DIR} |
| 91 | + test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.3/hack/setup-envtest.sh |
| 92 | + source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out |
| 93 | + |
| 94 | +##@ Build |
| 95 | + |
| 96 | +build: generate fmt vet ## Build manager binary. |
| 97 | + go build -ldflags "-X main.version=${VERSION}" -o bin/manager main.go |
| 98 | + |
| 99 | +run: manifests generate fmt vet ## Run a controller from your host. |
| 100 | + go run -ldflags "-X main.version=${VERSION}" ./main.go $(ARGS) |
| 101 | + |
| 102 | +docker-build: test ## Build docker image with the manager. |
| 103 | + docker build -t ${IMG} . --build-arg VERSION=${VERSION} |
| 104 | + |
| 105 | +docker-push: ## Push docker image with the manager. |
| 106 | + docker push ${IMG} |
| 107 | + |
| 108 | +##@ Deployment |
| 109 | + |
| 110 | +install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. |
| 111 | + $(KUSTOMIZE) build config/crd | kubectl apply -f - |
| 112 | + |
| 113 | +uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. |
| 114 | + $(KUSTOMIZE) build config/crd | kubectl delete -f - |
| 115 | + |
| 116 | +deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. |
| 117 | + cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} |
| 118 | + $(KUSTOMIZE) build config/default | kubectl apply -f - |
| 119 | + |
| 120 | +undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. |
| 121 | + $(KUSTOMIZE) build config/default | kubectl delete -f - |
| 122 | + |
| 123 | + |
| 124 | +CONTROLLER_GEN = $(shell pwd)/bin/controller-gen |
| 125 | +controller-gen: ## Download controller-gen locally if necessary. |
| 126 | + $(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected]) |
| 127 | + |
| 128 | +KUSTOMIZE = $(shell pwd)/bin/kustomize |
| 129 | +kustomize: ## Download kustomize locally if necessary. |
| 130 | + $(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected]) |
| 131 | + |
| 132 | +# go-get-tool will 'go get' any package $2 and install it to $1. |
| 133 | +PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) |
| 134 | +define go-get-tool |
| 135 | +@[ -f $(1) ] || { \ |
| 136 | +set -e ;\ |
| 137 | +TMP_DIR=$$(mktemp -d) ;\ |
| 138 | +cd $$TMP_DIR ;\ |
| 139 | +go mod init tmp ;\ |
| 140 | +echo "Downloading $(2)" ;\ |
| 141 | +GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\ |
| 142 | +rm -rf $$TMP_DIR ;\ |
| 143 | +} |
| 144 | +endef |
| 145 | + |
| 146 | +.PHONY: bundle |
| 147 | +bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files. |
| 148 | + operator-sdk generate kustomize manifests -q |
| 149 | + cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) |
| 150 | + $(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) |
| 151 | + operator-sdk bundle validate ./bundle |
| 152 | + |
| 153 | +.PHONY: bundle-build |
| 154 | +bundle-build: ## Build the bundle image. |
| 155 | + docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . |
| 156 | + |
| 157 | +.PHONY: bundle-push |
| 158 | +bundle-push: ## Push the bundle image. |
| 159 | + $(MAKE) docker-push IMG=$(BUNDLE_IMG) |
| 160 | + |
| 161 | +.PHONY: opm |
| 162 | +OPM = ./bin/opm |
| 163 | +opm: ## Download opm locally if necessary. |
| 164 | +ifeq (,$(wildcard $(OPM))) |
| 165 | +ifeq (,$(shell which opm 2>/dev/null)) |
| 166 | + @{ \ |
| 167 | + set -e ;\ |
| 168 | + mkdir -p $(dir $(OPM)) ;\ |
| 169 | + OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \ |
| 170 | + curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.17.2/$${OS}-$${ARCH}-opm ;\ |
| 171 | + chmod +x $(OPM) ;\ |
| 172 | + } |
| 173 | +else |
| 174 | +OPM = $(shell which opm) |
| 175 | +endif |
| 176 | +endif |
| 177 | + |
| 178 | +# 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). |
| 179 | +# These images MUST exist in a registry and be pull-able. |
| 180 | +BUNDLE_IMGS ?= $(BUNDLE_IMG) |
| 181 | + |
| 182 | +# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0). |
| 183 | +CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION) |
| 184 | + |
| 185 | +# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image. |
| 186 | +ifneq ($(origin CATALOG_BASE_IMG), undefined) |
| 187 | +FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG) |
| 188 | +endif |
| 189 | + |
| 190 | +# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'. |
| 191 | +# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see: |
| 192 | +# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator |
| 193 | +.PHONY: catalog-build |
| 194 | +catalog-build: opm ## Build a catalog image. |
| 195 | + $(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) |
| 196 | + |
| 197 | +# Push the catalog image. |
| 198 | +.PHONY: catalog-push |
| 199 | +catalog-push: ## Push a catalog image. |
| 200 | + $(MAKE) docker-push IMG=$(CATALOG_IMG) |
0 commit comments