github.com/argoproj-labs/argocd-operator@v0.10.0/Makefile (about) 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.9.0 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 # /argocd-operator-bundle:$VERSION and /argocd-operator-catalog:$VERSION. 32 IMAGE_TAG_BASE ?= quay.io/argoprojlabs/argocd-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 ?= $(IMAGE_TAG_BASE):v$(VERSION) 40 # Produce CRDs that work back to Kubernetes 1.11 (no version conversion) 41 CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false" 42 43 LD_FLAGS = "-X github.com/argoproj-labs/argocd-operator/version.Version=$(VERSION)" 44 45 # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) 46 ifeq (,$(shell go env GOBIN)) 47 GOBIN=$(shell go env GOPATH)/bin 48 else 49 GOBIN=$(shell go env GOBIN) 50 endif 51 52 # Setting SHELL to bash allows bash commands to be executed by recipes. 53 # This is a requirement for 'setup-envtest.sh' in the test target. 54 # Options are set to exit when a recipe line exits non-zero or a piped command fails. 55 SHELL = /usr/bin/env bash -o pipefail 56 .SHELLFLAGS = -ec 57 58 all: build 59 60 ##@ General 61 62 # The help target prints out all targets with their descriptions organized 63 # beneath their categories. The categories are represented by '##@' and the 64 # target descriptions by '##'. The awk commands is responsible for reading the 65 # entire set of makefiles included in this invocation, looking for lines of the 66 # file as xyz: ## something, and then pretty-format the target and help. Then, 67 # if there's a line with ##@ something, that gets pretty-printed as a category. 68 # More info on the usage of ANSI control characters for terminal formatting: 69 # https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters 70 # More info on the awk command: 71 # http://linuxcommand.org/lc3_adv_awk.php 72 73 help: ## Display this help. 74 @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) 75 76 ##@ Development 77 78 manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. 79 $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases 80 81 generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. 82 $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." 83 84 fmt: ## Run go fmt against code. 85 go fmt ./... 86 87 vet: ## Run go vet against code. 88 go vet ./... 89 90 test: manifests generate fmt vet envtest ## Run tests. 91 go test ./... -coverprofile cover.out 92 93 ##@ Build 94 95 build: generate fmt vet ## Build manager binary. 96 go build -ldflags=$(LD_FLAGS) -o bin/manager main.go 97 98 run: manifests generate fmt vet ## Run a controller from your host. 99 REDIS_CONFIG_PATH="build/redis" go run -ldflags=$(LD_FLAGS) ./main.go 100 101 docker-build: test ## Build docker image with the manager. 102 docker build --build-arg LD_FLAGS=$(LD_FLAGS) -t ${IMG} . 103 104 docker-push: ## Push docker image with the manager. 105 docker push ${IMG} 106 107 ##@ Deployment 108 109 install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. 110 ## TODO: Remove sed usage after all v1alpha1 references are updated to v1beta1 in codebase. 111 ## For local testing, conversion webhook defined in crd makes call to webhook for each v1alpha1 reference 112 ## causing failures as we don't set up the webhook for local testing. 113 $(KUSTOMIZE) build config/crd | sed '/conversion:/,/- v1beta1/d' |kubectl apply --server-side=true -f - 114 115 uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. 116 $(KUSTOMIZE) build config/crd | kubectl delete -f - 117 118 deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. 119 cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} 120 $(KUSTOMIZE) build config/default | kubectl apply --server-side=true -f - 121 122 undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. 123 $(KUSTOMIZE) build config/default | kubectl delete -f - 124 125 ##@ E2E 126 127 e2e: ## Run operator e2e tests 128 kubectl kuttl test ./tests/k8s --config ./tests/kuttl-tests.yaml 129 130 all: test install run e2e ## UnitTest, Run the operator locally and execute e2e tests. 131 132 CONTROLLER_GEN = $(shell pwd)/bin/controller-gen 133 controller-gen: ## Download controller-gen locally if necessary. 134 $(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.6.1) 135 136 KUSTOMIZE = $(shell pwd)/bin/kustomize 137 kustomize: ## Download kustomize locally if necessary. 138 $(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v4@v4.5.2) 139 140 ENVTEST = $(shell pwd)/bin/setup-envtest 141 envtest: ## Download envtest-setup locally if necessary. 142 $(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest) 143 $(ENVTEST) use 1.26 144 145 # go-install-tool will 'go install' any package $2 and install it to $1. 146 PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) 147 define go-install-tool 148 @[ -f $(1) ] || { \ 149 set -e ;\ 150 TMP_DIR=$$(mktemp -d) ;\ 151 cd $$TMP_DIR ;\ 152 go mod init tmp ;\ 153 echo "Downloading $(2)" ;\ 154 GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\ 155 rm -rf $$TMP_DIR ;\ 156 } 157 endef 158 159 .PHONY: bundle 160 bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files. 161 operator-sdk generate kustomize manifests -q 162 cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) 163 $(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) 164 operator-sdk bundle validate ./bundle 165 rm -fr deploy/olm-catalog/argocd-operator/$(VERSION) 166 mkdir -p deploy/olm-catalog/argocd-operator/$(VERSION) 167 cp -r bundle/manifests/* deploy/olm-catalog/argocd-operator/$(VERSION)/ 168 mv deploy/olm-catalog/argocd-operator/$(VERSION)/argocd-operator.clusterserviceversion.yaml deploy/olm-catalog/argocd-operator/$(VERSION)/argocd-operator.v$(VERSION).clusterserviceversion.yaml 169 170 .PHONY: bundle-build 171 bundle-build: ## Build the bundle image. 172 docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . 173 174 .PHONY: bundle-push 175 bundle-push: ## Push the bundle image. 176 $(MAKE) docker-push IMG=$(BUNDLE_IMG) 177 178 # UTIL_IMG defines the image:tag used for the utility image (for backup). 179 # You can use it as an arg. (E.g make bundle-build UTIL_IMG=<some-registry>/<project-name-bundle>:<tag>) 180 UTIL_IMG ?= $(IMAGE_TAG_BASE)-util:v$(VERSION) 181 182 .PHONY: util-build 183 util-build: ## Build the util container image (for backup) 184 docker build --no-cache -t $(UTIL_IMG) build/util 185 186 .PHONY: util-push 187 util-push: ## Push the util container image 188 $(MAKE) docker-push IMG=$(UTIL_IMG) 189 190 # REGISTRY_IMG defines the image:tag used for the (legacy) registry container image. 191 # You can use it as an arg. (E.g make bundle-build UTIL_IMG=<some-registry>/<project-name-bundle>:<tag>) 192 REGISTRY_IMG ?= $(IMAGE_TAG_BASE)-registry:v$(VERSION) 193 194 .PHONY: registry-build 195 registry-build: ## Build the registry container image 196 rm -fr build/_output 197 mkdir -p build/_output/registry 198 cp -r deploy/registry/* build/_output/registry/ 199 mkdir -p build/_output/registry/manifests 200 cp -r deploy/olm-catalog/argocd-operator build/_output/registry/manifests/ 201 docker build -t $(REGISTRY_IMG) build/_output/registry 202 203 .PHONY: registry-push 204 registry-push: ## Push the util container image 205 $(MAKE) docker-push IMG=$(REGISTRY_IMG) 206 207 .PHONY: opm 208 OPM = ./bin/opm 209 opm: ## Download opm locally if necessary. 210 ifeq (,$(wildcard $(OPM))) 211 ifeq (,$(shell which opm 2>/dev/null)) 212 @{ \ 213 set -e ;\ 214 mkdir -p $(dir $(OPM)) ;\ 215 OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \ 216 curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.20.0/$${OS}-$${ARCH}-opm ;\ 217 chmod +x $(OPM) ;\ 218 } 219 else 220 OPM = $(shell which opm) 221 endif 222 endif 223 224 # 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). 225 # These images MUST exist in a registry and be pull-able. 226 BUNDLE_IMGS ?= $(BUNDLE_IMG) 227 228 # The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0). 229 CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION) 230 231 # Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image. 232 ifneq ($(origin CATALOG_BASE_IMG), undefined) 233 FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG) 234 endif 235 236 # Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'. 237 # This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see: 238 # https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator 239 .PHONY: catalog-build 240 catalog-build: opm ## Build a catalog image. 241 $(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) 242 243 # Push the catalog image. 244 .PHONY: catalog-push 245 catalog-push: ## Push a catalog image. 246 $(MAKE) docker-push IMG=$(CATALOG_IMG)