|
| 1 | +# Current Operator version |
| 2 | +VERSION ?= 0.0.1 |
| 3 | +# Default bundle image tag |
| 4 | +BUNDLE_IMG ?= controller-bundle:$(VERSION) |
| 5 | +# Options for 'bundle-build' |
| 6 | +ifneq ($(origin CHANNELS), undefined) |
| 7 | +BUNDLE_CHANNELS := --channels=$(CHANNELS) |
| 8 | +endif |
| 9 | +ifneq ($(origin DEFAULT_CHANNEL), undefined) |
| 10 | +BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL) |
| 11 | +endif |
| 12 | +BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) |
| 13 | + |
| 14 | +# Image URL to use all building/pushing image targets |
| 15 | +IMG ?= controller:latest |
| 16 | +# Produce CRDs that work back to Kubernetes 1.11 (no version conversion) |
| 17 | +CRD_OPTIONS ?= "crd:trivialVersions=true" |
| 18 | + |
| 19 | +# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) |
| 20 | +ifeq (,$(shell go env GOBIN)) |
| 21 | +GOBIN=$(shell go env GOPATH)/bin |
| 22 | +else |
| 23 | +GOBIN=$(shell go env GOBIN) |
| 24 | +endif |
| 25 | + |
| 26 | +all: manager |
| 27 | + |
| 28 | +# Run tests |
| 29 | +test: generate fmt vet manifests |
| 30 | + go test ./... -coverprofile cover.out |
| 31 | + |
| 32 | +# Build manager binary |
| 33 | +manager: generate fmt vet |
| 34 | + go build -o bin/manager main.go |
| 35 | + |
| 36 | +# Run against the configured Kubernetes cluster in ~/.kube/config |
| 37 | +run: generate fmt vet manifests |
| 38 | + go run ./main.go |
| 39 | + |
| 40 | +# Install CRDs into a cluster |
| 41 | +install: manifests kustomize |
| 42 | + $(KUSTOMIZE) build config/crd | kubectl apply -f - |
| 43 | + |
| 44 | +# Uninstall CRDs from a cluster |
| 45 | +uninstall: manifests kustomize |
| 46 | + $(KUSTOMIZE) build config/crd | kubectl delete -f - |
| 47 | + |
| 48 | +# Deploy controller in the configured Kubernetes cluster in ~/.kube/config |
| 49 | +deploy: manifests kustomize |
| 50 | + cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} |
| 51 | + $(KUSTOMIZE) build config/default | kubectl apply -f - |
| 52 | + |
| 53 | +# Generate manifests e.g. CRD, RBAC etc. |
| 54 | +manifests: controller-gen |
| 55 | + $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases |
| 56 | + |
| 57 | +# Run go fmt against code |
| 58 | +fmt: |
| 59 | + go fmt ./... |
| 60 | + |
| 61 | +# Run go vet against code |
| 62 | +vet: |
| 63 | + go vet ./... |
| 64 | + |
| 65 | +# Generate code |
| 66 | +generate: controller-gen |
| 67 | + $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." |
| 68 | + |
| 69 | +# Build the docker image |
| 70 | +docker-build: test |
| 71 | + docker build . -t ${IMG} |
| 72 | + |
| 73 | +# Push the docker image |
| 74 | +docker-push: |
| 75 | + docker push ${IMG} |
| 76 | + |
| 77 | +# find or download controller-gen |
| 78 | +# download controller-gen if necessary |
| 79 | +controller-gen: |
| 80 | +ifeq (, $(shell which controller-gen)) |
| 81 | + @{ \ |
| 82 | + set -e ;\ |
| 83 | + CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\ |
| 84 | + cd $$CONTROLLER_GEN_TMP_DIR ;\ |
| 85 | + go mod init tmp ;\ |
| 86 | + go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.3.0 ;\ |
| 87 | + rm -rf $$CONTROLLER_GEN_TMP_DIR ;\ |
| 88 | + } |
| 89 | +CONTROLLER_GEN=$(GOBIN)/controller-gen |
| 90 | +else |
| 91 | +CONTROLLER_GEN=$(shell which controller-gen) |
| 92 | +endif |
| 93 | + |
| 94 | +kustomize: |
| 95 | +ifeq (, $(shell which kustomize)) |
| 96 | + @{ \ |
| 97 | + set -e ;\ |
| 98 | + KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\ |
| 99 | + cd $$KUSTOMIZE_GEN_TMP_DIR ;\ |
| 100 | + go mod init tmp ;\ |
| 101 | + go get sigs.k8s.io/kustomize/kustomize/v3@v3.5.4 ;\ |
| 102 | + rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\ |
| 103 | + } |
| 104 | +KUSTOMIZE=$(GOBIN)/kustomize |
| 105 | +else |
| 106 | +KUSTOMIZE=$(shell which kustomize) |
| 107 | +endif |
| 108 | + |
| 109 | +# Generate bundle manifests and metadata, then validate generated files. |
| 110 | +bundle: manifests |
| 111 | + operator-sdk generate kustomize manifests -q |
| 112 | + kustomize build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) |
| 113 | + operator-sdk bundle validate ./bundle |
| 114 | + |
| 115 | +# Build the bundle image. |
| 116 | +bundle-build: |
| 117 | + docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . |
0 commit comments