|
| 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 = "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 |
| 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 | +# BUNDLE_IMG defines the image:tag used for the bundle. |
| 28 | +# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>) |
| 29 | +BUNDLE_IMG ?= controller-bundle:$(VERSION) |
| 30 | + |
| 31 | +# Image URL to use all building/pushing image targets |
| 32 | +IMG ?= controller:latest |
| 33 | + |
| 34 | +all: docker-build |
| 35 | + |
| 36 | +# Run against the configured Kubernetes cluster in ~/.kube/config |
| 37 | +run: ansible-operator |
| 38 | + $(ANSIBLE_OPERATOR) run |
| 39 | + |
| 40 | +# Install CRDs into a cluster |
| 41 | +install: kustomize |
| 42 | + $(KUSTOMIZE) build config/crd | kubectl apply -f - |
| 43 | + |
| 44 | +# Uninstall CRDs from a cluster |
| 45 | +uninstall: kustomize |
| 46 | + $(KUSTOMIZE) build config/crd | kubectl delete -f - |
| 47 | + |
| 48 | +# Deploy controller in the configured Kubernetes cluster in ~/.kube/config |
| 49 | +deploy: kustomize |
| 50 | + cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} |
| 51 | + $(KUSTOMIZE) build config/default | kubectl apply -f - |
| 52 | + |
| 53 | +# Undeploy controller in the configured Kubernetes cluster in ~/.kube/config |
| 54 | +undeploy: kustomize |
| 55 | + $(KUSTOMIZE) build config/default | kubectl delete -f - |
| 56 | + |
| 57 | +# Build the docker image |
| 58 | +docker-build: |
| 59 | + docker build -t ${IMG} . |
| 60 | + |
| 61 | +# Push the docker image |
| 62 | +docker-push: |
| 63 | + docker push ${IMG} |
| 64 | + |
| 65 | +PATH := $(PATH):$(PWD)/bin |
| 66 | +SHELL := env 'PATH=$(PATH)' /bin/sh |
| 67 | +OS := $(shell uname -s | tr '[:upper:]' '[:lower:]') |
| 68 | +ARCH := $(shell uname -m | sed 's/x86_64/amd64/') |
| 69 | + |
| 70 | +# Download kustomize locally if necessary, preferring the $(pwd)/bin path over global if both exist. |
| 71 | +.PHONY: kustomize |
| 72 | +KUSTOMIZE = $(shell pwd)/bin/kustomize |
| 73 | +kustomize: |
| 74 | +ifeq (,$(wildcard $(KUSTOMIZE))) |
| 75 | +ifeq (,$(shell which kustomize 2>/dev/null)) |
| 76 | + @{ \ |
| 77 | + set -e ;\ |
| 78 | + mkdir -p $(dir $(KUSTOMIZE)) ;\ |
| 79 | + curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v3.5.4/kustomize_v3.5.4_$(OS)_$(ARCH).tar.gz | \ |
| 80 | + tar xzf - -C bin/ ;\ |
| 81 | + } |
| 82 | +else |
| 83 | +KUSTOMIZE = $(shell which kustomize) |
| 84 | +endif |
| 85 | +endif |
| 86 | + |
| 87 | +# Download ansible-operator locally if necessary, preferring the $(pwd)/bin path over global if both exist. |
| 88 | +.PHONY: ansible-operator |
| 89 | +ANSIBLE_OPERATOR = $(shell pwd)/bin/ansible-operator |
| 90 | +ansible-operator: |
| 91 | +ifeq (,$(wildcard $(ANSIBLE_OPERATOR))) |
| 92 | +ifeq (,$(shell which ansible-operator 2>/dev/null)) |
| 93 | + @{ \ |
| 94 | + set -e ;\ |
| 95 | + mkdir -p $(dir $(ANSIBLE_OPERATOR)) ;\ |
| 96 | + curl -sSLo $(ANSIBLE_OPERATOR) https://github.com/operator-framework/operator-sdk/releases/download/v1.4.0/ansible-operator_$(OS)_$(ARCH) ;\ |
| 97 | + chmod +x $(ANSIBLE_OPERATOR) ;\ |
| 98 | + } |
| 99 | +else |
| 100 | +ANSIBLE_OPERATOR = $(shell which ansible-operator) |
| 101 | +endif |
| 102 | +endif |
| 103 | + |
| 104 | +# Generate bundle manifests and metadata, then validate generated files. |
| 105 | +.PHONY: bundle |
| 106 | +bundle: kustomize |
| 107 | + operator-sdk generate kustomize manifests -q |
| 108 | + cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) |
| 109 | + $(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) |
| 110 | + operator-sdk bundle validate ./bundle |
| 111 | + |
| 112 | +# Build the bundle image. |
| 113 | +.PHONY: bundle-build |
| 114 | +bundle-build: |
| 115 | + docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . |
0 commit comments