|
| 1 | +# Copyright IBM Corporation 2020 |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +REGISTRYNS := quay.io/konveyor |
| 16 | + |
| 17 | +ifdef VERSION |
| 18 | + BINARY_VERSION = $(VERSION) |
| 19 | +endif |
| 20 | +BINARY_VERSION ?= ${GIT_TAG} |
| 21 | +ifneq ($(BINARY_VERSION),) |
| 22 | + LDFLAGS += -X github.com/konveyor/${BINNAME}/types/info.version=${BINARY_VERSION} |
| 23 | + VERSION ?= $(BINARY_VERSION) |
| 24 | +endif |
| 25 | +VERSION ?= latest |
| 26 | + |
| 27 | +# Default bundle image tag |
| 28 | +BUNDLE_IMG ?= controller-bundle:$(VERSION) |
| 29 | +# Options for 'bundle-build' |
| 30 | +ifneq ($(origin CHANNELS), undefined) |
| 31 | +BUNDLE_CHANNELS := --channels=$(CHANNELS) |
| 32 | +endif |
| 33 | +ifneq ($(origin DEFAULT_CHANNEL), undefined) |
| 34 | +BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL) |
| 35 | +endif |
| 36 | +BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) |
| 37 | + |
| 38 | +GIT_COMMIT = $(shell git rev-parse HEAD) |
| 39 | +GIT_SHA = $(shell git rev-parse --short HEAD) |
| 40 | +GIT_TAG = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null) |
| 41 | +GIT_DIRTY = $(shell test -n "`git status --porcelain`" && echo "dirty" || echo "clean") |
| 42 | + |
| 43 | +# Image URL to use all building/pushing image targets |
| 44 | +IMG ?= quay.io/konveyor/move2kube-operator:latest |
| 45 | + |
| 46 | +# HELP |
| 47 | +# This will output the help for each task |
| 48 | +.PHONY: help |
| 49 | +help: ## This help. |
| 50 | + @awk 'BEGIN {FS = ":.*?## "} /^[0-9a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) |
| 51 | + |
| 52 | +all: docker-build |
| 53 | + |
| 54 | +# Run against the configured Kubernetes cluster in ~/.kube/config |
| 55 | +run: helm-operator |
| 56 | + $(HELM_OPERATOR) run |
| 57 | + |
| 58 | +# Install CRDs into a cluster |
| 59 | +install: kustomize |
| 60 | + $(KUSTOMIZE) build config/crd | kubectl apply -f - |
| 61 | + |
| 62 | +# Uninstall CRDs from a cluster |
| 63 | +uninstall: kustomize |
| 64 | + $(KUSTOMIZE) build config/crd | kubectl delete -f - |
| 65 | + |
| 66 | +# Deploy controller in the configured Kubernetes cluster in ~/.kube/config |
| 67 | +deploy: kustomize |
| 68 | + cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} |
| 69 | + $(KUSTOMIZE) build config/default | kubectl apply -f - |
| 70 | + |
| 71 | +# Undeploy controller in the configured Kubernetes cluster in ~/.kube/config |
| 72 | +undeploy: kustomize |
| 73 | + $(KUSTOMIZE) build config/default | kubectl delete -f - |
| 74 | + |
| 75 | +# Build the docker image |
| 76 | +docker-build: |
| 77 | + docker build . -t ${IMG} |
| 78 | + |
| 79 | +# Push the docker image |
| 80 | +docker-push: |
| 81 | + docker push ${IMG} |
| 82 | + |
| 83 | +PATH := $(PATH):$(PWD)/bin |
| 84 | +SHELL := env PATH=$(PATH) /bin/sh |
| 85 | +OS = $(shell uname -s | tr '[:upper:]' '[:lower:]') |
| 86 | +ARCH = $(shell uname -m | sed 's/x86_64/amd64/') |
| 87 | +OSOPER = $(shell uname -s | tr '[:upper:]' '[:lower:]' | sed 's/darwin/apple-darwin/' | sed 's/linux/linux-gnu/') |
| 88 | +ARCHOPER = $(shell uname -m ) |
| 89 | + |
| 90 | +kustomize: |
| 91 | +ifeq (, $(shell which kustomize 2>/dev/null)) |
| 92 | + @{ \ |
| 93 | + set -e ;\ |
| 94 | + mkdir -p bin ;\ |
| 95 | + curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v3.5.4/kustomize_v3.5.4_$(OS)_$(ARCH).tar.gz | tar xzf - -C bin/ ;\ |
| 96 | + } |
| 97 | +KUSTOMIZE=$(realpath ./bin/kustomize) |
| 98 | +else |
| 99 | +KUSTOMIZE=$(shell which kustomize) |
| 100 | +endif |
| 101 | + |
| 102 | +helm-operator: |
| 103 | +ifeq (, $(shell which helm-operator 2>/dev/null)) |
| 104 | + @{ \ |
| 105 | + set -e ;\ |
| 106 | + mkdir -p bin ;\ |
| 107 | + curl -LO https://github.com/operator-framework/operator-sdk/releases/download/v1.0.1/helm-operator-v1.0.1-$(ARCHOPER)-$(OSOPER) ;\ |
| 108 | + mv helm-operator-v1.0.1-$(ARCHOPER)-$(OSOPER) ./bin/helm-operator ;\ |
| 109 | + chmod +x ./bin/helm-operator ;\ |
| 110 | + } |
| 111 | +HELM_OPERATOR=$(realpath ./bin/helm-operator) |
| 112 | +else |
| 113 | +HELM_OPERATOR=$(shell which helm-operator) |
| 114 | +endif |
| 115 | + |
| 116 | +# Generate bundle manifests and metadata, then validate generated files. |
| 117 | +.PHONY: bundle |
| 118 | +bundle: kustomize |
| 119 | + operator-sdk generate kustomize manifests -q |
| 120 | + cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) |
| 121 | + $(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) |
| 122 | + operator-sdk bundle validate ./bundle |
| 123 | + |
| 124 | +# Build the bundle image. |
| 125 | +.PHONY: bundle-build |
| 126 | +bundle-build: |
| 127 | + docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . |
0 commit comments