|
| 1 | +SHELL := /bin/bash |
| 2 | + |
| 3 | +# VERSION defines the project version for the bundle. |
| 4 | +# Update this value when you upgrade the version of your project. |
| 5 | +# To re-generate a bundle for another specific version without changing the standard setup, you can: |
| 6 | +# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2) |
| 7 | +# - use environment variables to overwrite this value (e.g export VERSION=0.0.2) |
| 8 | +VERSION ?= 0.0.1 |
| 9 | + |
| 10 | +# CHANNELS define the bundle channels used in the bundle. |
| 11 | +# Add a new line here if you would like to change its default config. (E.g CHANNELS = "preview,fast,stable") |
| 12 | +# To re-generate a bundle for other specific channels without changing the standard setup, you can: |
| 13 | +# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=preview,fast,stable) |
| 14 | +# - use environment variables to overwrite this value (e.g export CHANNELS="preview,fast,stable") |
| 15 | +ifneq ($(origin CHANNELS), undefined) |
| 16 | +BUNDLE_CHANNELS := --channels=$(CHANNELS) |
| 17 | +endif |
| 18 | + |
| 19 | +# DEFAULT_CHANNEL defines the default channel used in the bundle. |
| 20 | +# Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable") |
| 21 | +# To re-generate a bundle for any other default channel without changing the default setup, you can: |
| 22 | +# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable) |
| 23 | +# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable") |
| 24 | +ifneq ($(origin DEFAULT_CHANNEL), undefined) |
| 25 | +BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL) |
| 26 | +endif |
| 27 | +BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) |
| 28 | + |
| 29 | +# BUNDLE_IMG defines the image:tag used for the bundle. |
| 30 | +# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>) |
| 31 | +BUNDLE_IMG ?= controller-bundle:$(VERSION) |
| 32 | + |
| 33 | +# Image URL to use all building/pushing image targets |
| 34 | +IMG ?= quay.io/mongodb/mongodb-kubernetes-operator:0.5.0 # replace with localhost:5000/mongodb-kubernetes-operator locally |
| 35 | +DOCKERFILE ?= operator |
| 36 | +# Produce CRDs that work back to Kubernetes 1.11 (no version conversion) |
| 37 | +CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=true,crdVersions=v1beta1" |
| 38 | + |
| 39 | +# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) |
| 40 | +ifeq (,$(shell go env GOBIN)) |
| 41 | +GOBIN=$(shell go env GOPATH)/bin |
| 42 | +else |
| 43 | +GOBIN=$(shell go env GOBIN) |
| 44 | +endif |
| 45 | + |
| 46 | +all: manager |
| 47 | + |
| 48 | +# Run unit tests |
| 49 | +TEST ?= ./pkg/... ./api/... ./cmd/... ./controllers/... ./test/e2e/util/mongotester/... |
| 50 | +ENVTEST_ASSETS_DIR=$(shell pwd)/testbin |
| 51 | +test: generate fmt vet manifests |
| 52 | + mkdir -p ${ENVTEST_ASSETS_DIR} |
| 53 | + 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.7.0/hack/setup-envtest.sh |
| 54 | + source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test $(TEST) -coverprofile cover.out |
| 55 | + |
| 56 | +# Build manager binary |
| 57 | +manager: generate fmt vet |
| 58 | + go build -o bin/manager ./cmd/manager/main.go |
| 59 | + |
| 60 | +# Run against the configured Kubernetes cluster in ~/.kube/config |
| 61 | +run: generate fmt vet manifests |
| 62 | + go run ./cmd/manager/main.go |
| 63 | + |
| 64 | +# Install CRDs into a cluster |
| 65 | +install: manifests kustomize |
| 66 | + $(KUSTOMIZE) build config/crd | kubectl apply -f - |
| 67 | + |
| 68 | +# Uninstall CRDs from a cluster |
| 69 | +uninstall: manifests kustomize |
| 70 | + $(KUSTOMIZE) build config/crd | kubectl delete -f - |
| 71 | + |
| 72 | +# Deploy controller in the configured Kubernetes cluster in ~/.kube/config |
| 73 | +deploy: manifests kustomize |
| 74 | + cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} |
| 75 | + $(KUSTOMIZE) build config/default | kubectl apply -f - |
| 76 | + |
| 77 | +# UnDeploy controller from the configured Kubernetes cluster in ~/.kube/config |
| 78 | +undeploy: |
| 79 | + $(KUSTOMIZE) build config/default | kubectl delete -f - |
| 80 | + |
| 81 | +# Generate manifests e.g. CRD, RBAC etc. |
| 82 | +manifests: controller-gen |
| 83 | + $(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./..." output:crd:artifacts:config=config/crd/bases |
| 84 | + |
| 85 | +# Run go fmt against code |
| 86 | +fmt: |
| 87 | + go fmt ./... |
| 88 | + |
| 89 | +# Run go vet against code |
| 90 | +vet: |
| 91 | + go vet ./... |
| 92 | + |
| 93 | +# Generate code |
| 94 | +generate: controller-gen |
| 95 | + $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." |
| 96 | + |
| 97 | +# Build the docker image |
| 98 | +docker-build: dockerfile |
| 99 | + docker build -t ${IMG} . |
| 100 | + |
| 101 | +# Push the docker image |
| 102 | +docker-push: |
| 103 | + docker push ${IMG} |
| 104 | + |
| 105 | +# Download controller-gen locally if necessary |
| 106 | +CONTROLLER_GEN = $(shell pwd)/bin/controller-gen |
| 107 | +controller-gen: |
| 108 | + $(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1) |
| 109 | + |
| 110 | +# Download kustomize locally if necessary |
| 111 | +KUSTOMIZE = $(shell pwd)/bin/kustomize |
| 112 | +kustomize: |
| 113 | + $(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@v3.8.7) |
| 114 | + |
| 115 | +# go-get-tool will 'go get' any package $2 and install it to $1. |
| 116 | +PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) |
| 117 | +define go-get-tool |
| 118 | +@[ -f $(1) ] || { \ |
| 119 | +set -e ;\ |
| 120 | +TMP_DIR=$$(mktemp -d) ;\ |
| 121 | +cd $$TMP_DIR ;\ |
| 122 | +go mod init tmp ;\ |
| 123 | +echo "Downloading $(2)" ;\ |
| 124 | +GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\ |
| 125 | +rm -rf $$TMP_DIR ;\ |
| 126 | +} |
| 127 | +endef |
| 128 | + |
| 129 | +# Generate bundle manifests and metadata, then validate generated files. |
| 130 | +.PHONY: bundle |
| 131 | +bundle: manifests kustomize |
| 132 | + operator-sdk generate kustomize manifests -q |
| 133 | + cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) |
| 134 | + $(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) |
| 135 | + operator-sdk bundle validate ./bundle |
| 136 | + |
| 137 | +# Build the bundle image. |
| 138 | +.PHONY: bundle-build |
| 139 | +bundle-build: |
| 140 | + docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . |
| 141 | + |
| 142 | +# Generate Dockerfile |
| 143 | +.PHONY: dockerfile |
| 144 | +dockerfile: |
| 145 | + python scripts/dev/dockerfile_generator.py ${DOCKERFILE} > Dockerfile |
0 commit comments