-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a seperate Makefile for operator
- Loading branch information
1 parent
3dbd349
commit a7cd7eb
Showing
2 changed files
with
126 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# Copyright 2021 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# If you update this file, please follow | ||
# https://suva.sh/posts/well-documented-makefiles | ||
|
||
# Ensure Make is run with bash shell as some syntax below is bash-specific | ||
SHELL:=/usr/bin/env bash | ||
|
||
# Path to main repo | ||
ROOT = ../../ | ||
|
||
.DEFAULT_GOAL:=help | ||
|
||
# Use GOPROXY environment variable if set | ||
GOPROXY := $(shell go env GOPROXY) | ||
ifeq ($(GOPROXY),) | ||
GOPROXY := https://proxy.golang.org | ||
endif | ||
export GOPROXY | ||
|
||
# Active module mode, as we use go modules to manage dependencies | ||
export GO111MODULE=on | ||
|
||
# This option is for running docker manifest command | ||
export DOCKER_CLI_EXPERIMENTAL := enabled | ||
|
||
# Directories | ||
TOOLS_DIR := $(ROOT)/hack/tools | ||
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin | ||
|
||
export PATH := $(abspath $(TOOLS_BIN_DIR)):$(PATH) | ||
|
||
# Binaries. | ||
# Need to use abspath so we can invoke these from subdirectories | ||
CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/controller-gen) | ||
|
||
# Define Docker related variables. Releases should modify and double check these vars. | ||
REGISTRY ?= gcr.io/$(shell gcloud config get-value project) | ||
|
||
# Image name | ||
OPERATOR_IMAGE_NAME ?= cluster-api-operator | ||
OPERATOR_CONTROLLER_IMG ?= $(REGISTRY)/$(OPERATOR_IMAGE_NAME) | ||
|
||
# It is set by Prow GIT_TAG, a git-based tag of the form vYYYYMMDD-hash, e.g., v20210120-v0.3.10-308-gc61521971 | ||
TAG ?= dev | ||
ARCH ?= amd64 | ||
ALL_ARCH = amd64 arm arm64 ppc64le s390x | ||
|
||
# Set build time variables including version details | ||
LDFLAGS := $(shell $(ROOT)/hack/version.sh) | ||
|
||
all: generate-go-operator generate-operator-manifests operator | ||
|
||
help: ## Display this help | ||
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[0-9A-Za-z_-]+:.*?##/ { printf " \033[36m%-45s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) | ||
|
||
## -------------------------------------- | ||
## Binaries | ||
## -------------------------------------- | ||
|
||
.PHONY: operator | ||
operator: ## Build operator binary | ||
go build -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/operator sigs.k8s.io/cluster-api/exp/operator | ||
|
||
$(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod # Build controller-gen from tools folder. | ||
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/controller-gen sigs.k8s.io/controller-tools/cmd/controller-gen | ||
|
||
## -------------------------------------- | ||
## Generate / Manifests | ||
## -------------------------------------- | ||
|
||
.PHONY: generate-go-operator | ||
generate-go-operator: $(CONTROLLER_GEN) ## Runs Go related generate targets for the operator | ||
$(CONTROLLER_GEN) \ | ||
object:headerFile=$(ROOT)/hack/boilerplate/boilerplate.generatego.txt \ | ||
paths=./api/... | ||
|
||
.PHONY: generate-operator-manifests | ||
generate-operator-manifests: $(CONTROLLER_GEN) ## Generate manifests for the operator e.g. CRD, RBAC etc. | ||
$(CONTROLLER_GEN) \ | ||
paths=./api/... \ | ||
paths=./controllers/... \ | ||
crd:crdVersions=v1 \ | ||
rbac:roleName=manager-role \ | ||
output:crd:dir=./config/crd/bases \ | ||
output:rbac:dir=./config/rbac \ | ||
output:webhook:dir=./config/webhook \ | ||
webhook | ||
|
||
## -------------------------------------- | ||
## Docker | ||
## -------------------------------------- | ||
|
||
.PHONY: docker-build-operator | ||
docker-build-operator: ## Build the docker image for management cluster operator | ||
DOCKER_BUILDKIT=1 docker build --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg ldflags="$(LDFLAGS)" $(ROOT) -t $(OPERATOR_CONTROLLER_IMG)-$(ARCH):$(TAG) | ||
|
||
.PHONY: docker-push-operator-manifest | ||
docker-push-operator-manifest: ## Push the fat manifest docker image for the operator image. | ||
## Minimum docker version 18.06.0 is required for creating and pushing manifest images. | ||
docker manifest create --amend $(OPERATOR_CONTROLLER_IMG):$(TAG) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(OPERATOR_CONTROLLER_IMG)\-&:$(TAG)~g") | ||
@for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} ${OPERATOR_CONTROLLER_IMG}:${TAG} ${OPERATOR_CONTROLLER_IMG}-$${arch}:${TAG}; done | ||
docker manifest push --purge $(OPERATOR_CONTROLLER_IMG):$(TAG) |