sigs.k8s.io/cluster-api/bootstrap/kubeadm@v0.0.0-20191016155141-23a891785b60/Makefile (about) 1 # Copyright 2019 The Kubernetes Authors. 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 # If you update this file, please follow: 16 # https://suva.sh/posts/well-documented-makefiles/ 17 18 .DEFAULT_GOAL := help 19 20 # Active go module, as we use it to manage dependencies 21 export GO111MODULE := on 22 23 # Use GOPROXY environment variable if set 24 GOPROXY := $(shell go env GOPROXY) 25 ifeq ($(GOPROXY),) 26 GOPROXY := https://proxy.golang.org 27 endif 28 export GOPROXY 29 30 REGISTRY ?= gcr.io/$(shell gcloud config get-value project) 31 # A release does not need to define this 32 MANAGER_IMAGE_NAME ?= cluster-api-bootstrap-provider-kubeadm 33 MANAGER_IMAGE_TAG ?= dev 34 PULL_POLICY ?= Always 35 36 # Define Docker related variables. Releases should modify and double check these vars. 37 REGISTRY ?= gcr.io/$(shell gcloud config get-value project) 38 STAGING_REGISTRY := gcr.io/k8s-staging-capi-kubeadm 39 PROD_REGISTRY := us.gcr.io/k8s-artifacts-prod/capi-kubeadm 40 IMAGE_NAME ?= cluster-api-kubeadm-controller 41 CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME) 42 TAG ?= dev 43 ARCH ?= amd64 44 ALL_ARCH = amd64 arm arm64 ppc64le s390x 45 46 # Produce CRDs that work back to Kubernetes 1.11 (no version conversion) 47 CRD_OPTIONS ?= "crd:trivialVersions=true" 48 49 TOOLS_DIR := hack/tools 50 CONTROLLER_GEN_BIN := bin/controller-gen 51 CONTROLLER_GEN := $(TOOLS_DIR)/$(CONTROLLER_GEN_BIN) 52 GOLANGCI_LINT_BIN := bin/golangci-lint 53 GOLANGCI_LINT := $(TOOLS_DIR)/$(GOLANGCI_LINT_BIN) 54 RELEASE_NOTES_BIN := bin/release-notes 55 RELEASE_NOTES := $(TOOLS_DIR)/$(RELEASE_NOTES_BIN) 56 57 # Allow overriding manifest generation destination directory 58 MANIFEST_ROOT ?= "config" 59 CRD_ROOT ?= "$(MANIFEST_ROOT)/crd/bases" 60 WEBHOOK_ROOT ?= "$(MANIFEST_ROOT)/webhook" 61 RBAC_ROOT ?= "$(MANIFEST_ROOT)/rbac" 62 63 .PHONY: all 64 all: manager 65 66 help: ## Display this help 67 @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-22s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) 68 69 ## -------------------------------------- 70 ## Testing 71 ## -------------------------------------- 72 73 .PHONY: test 74 test: generate lint ## Run tests 75 go test ./... -coverprofile cover.out 76 77 ## -------------------------------------- 78 ## Binaries 79 ## -------------------------------------- 80 81 .PHONY: manager 82 manager: generate lint ## Build manager binary 83 go build -o bin/manager main.go 84 85 # Build controller-gen 86 $(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod 87 cd $(TOOLS_DIR) && go build -o $(CONTROLLER_GEN_BIN) sigs.k8s.io/controller-tools/cmd/controller-gen 88 89 # Build golangci-lint 90 $(GOLANGCI_LINT): $(TOOLS_DIR)/go.mod 91 cd $(TOOLS_DIR) && go build -o $(GOLANGCI_LINT_BIN) github.com/golangci/golangci-lint/cmd/golangci-lint 92 93 $(RELEASE_NOTES) : $(TOOLS_DIR)/go.mod 94 cd $(TOOLS_DIR) && go build -o $(RELEASE_NOTES_BIN) -tags tools sigs.k8s.io/cluster-api/hack/tools/release 95 96 ## -------------------------------------- 97 ## Linting 98 ## -------------------------------------- 99 100 .PHONY: lint 101 lint: $(GOLANGCI_LINT) ## Lint quickly using `golangci-lint --fast=true` 102 $(GOLANGCI_LINT) run -v --fast=true 103 104 .PHONY: lint-full 105 lint-full: $(GOLANGCI_LINT) ## Lint thoroughly using `golangci-lint --fase=false` 106 $(GOLANGCI_LINT) run -v --fast=false 107 108 ## -------------------------------------- 109 ## Generate / Manifests 110 ## -------------------------------------- 111 112 .PHONY: generate 113 generate: $(CONTROLLER_GEN) ## Generate code 114 $(MAKE) generate-manifests 115 $(MAKE) generate-deepcopy 116 117 .PHONY: generate-deepcopy 118 generate-deepcopy: $(CONTROLLER_GEN) ## Generate deepcopy files 119 $(CONTROLLER_GEN) object:headerFile=./hack/boilerplate/boilerplate.generatego.txt paths=./api/... 120 121 .PHONY: generate-manifests 122 generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc 123 $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:dir=$(CRD_ROOT) output:webhook:dir=$(WEBHOOK_ROOT) output:rbac:dir=$(RBAC_ROOT) 124 125 .PHONY: modules 126 modules: ## Runs go mod to ensure modules are up to date. 127 go mod tidy 128 cd $(TOOLS_DIR); go mod tidy 129 130 ## -------------------------------------- 131 ## Docker 132 ## -------------------------------------- 133 134 .PHONY: docker-build 135 docker-build: ## Build the docker image for controller-manager 136 docker build --pull --build-arg ARCH=$(ARCH) . -t $(CONTROLLER_IMG)-$(ARCH):$(TAG) 137 MANIFEST_IMG=$(CONTROLLER_IMG)-$(ARCH) MANIFEST_TAG=$(TAG) $(MAKE) set-manifest-image 138 139 .PHONY: docker-push 140 docker-push: ## Push the docker image 141 docker push $(CONTROLLER_IMG)-$(ARCH):$(TAG) 142 143 ## -------------------------------------- 144 ## Docker — All ARCH 145 ## -------------------------------------- 146 147 .PHONY: docker-build-all ## Build all the architecture docker images 148 docker-build-all: $(addprefix docker-build-,$(ALL_ARCH)) 149 150 docker-build-%: 151 $(MAKE) ARCH=$* docker-build 152 153 .PHONY: docker-push-all ## Push all the architecture docker images 154 docker-push-all: $(addprefix docker-push-,$(ALL_ARCH)) 155 $(MAKE) docker-push-manifest 156 157 docker-push-%: 158 $(MAKE) ARCH=$* docker-push 159 160 .PHONY: docker-push-manifest 161 docker-push-manifest: ## Push the fat manifest docker image. 162 ## Minimum docker version 18.06.0 is required for creating and pushing manifest images. 163 docker manifest create --amend $(CONTROLLER_IMG):$(TAG) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(CONTROLLER_IMG)\-&:$(TAG)~g") 164 @for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} ${CONTROLLER_IMG}:${TAG} ${CONTROLLER_IMG}-$${arch}:${TAG}; done 165 docker manifest push --purge ${CONTROLLER_IMG}:${TAG} 166 MANIFEST_IMG=$(CONTROLLER_IMG) MANIFEST_TAG=$(TAG) $(MAKE) set-manifest-image 167 168 .PHONY: set-manifest-image 169 set-manifest-image: 170 $(info Updating kustomize image patch file for manager resource) 171 sed -i'' -e 's@image: .*@image: '"${MANIFEST_IMG}:$(MANIFEST_TAG)"'@' ./config/default/manager_image_patch.yaml 172 173 ## -------------------------------------- 174 ## Release 175 ## -------------------------------------- 176 177 RELEASE_TAG := $(shell git describe --abbrev=0 2>/dev/null) 178 RELEASE_DIR := out 179 180 $(RELEASE_DIR): 181 mkdir -p $(RELEASE_DIR)/ 182 183 .PHONY: release 184 release: clean-release ## Builds and push container images using the latest git tag for the commit. 185 @if [ -z "${RELEASE_TAG}" ]; then echo "RELEASE_TAG is not set"; exit 1; fi 186 # Push the release image to the staging bucket first. 187 REGISTRY=$(STAGING_REGISTRY) TAG=$(RELEASE_TAG) \ 188 $(MAKE) docker-build-all docker-push-all 189 # Set the manifest image to the production bucket. 190 MANIFEST_IMG=$(PROD_REGISTRY)/$(IMAGE_NAME) MANIFEST_TAG=$(RELEASE_TAG) \ 191 $(MAKE) set-manifest-image 192 $(MAKE) release-manifests 193 194 .PHONY: release-manifests 195 release-manifests: $(RELEASE_DIR) ## Builds the manifests to publish with a release 196 kustomize build config/default > $(RELEASE_DIR)/bootstrap-components.yaml 197 198 .PHONY: release-staging 199 release-staging: ## Builds and push container images to the staging bucket. 200 REGISTRY=$(STAGING_REGISTRY) $(MAKE) docker-build-all docker-push-all release-alias-tag 201 202 RELEASE_ALIAS_TAG=$(shell if [ "$(PULL_BASE_REF)" = "master" ]; then echo "latest"; else echo "$(PULL_BASE_REF)"; fi) 203 204 .PHONY: release-alias-tag 205 release-alias-tag: # Adds the tag to the last build tag. 206 gcloud container images add-tag $(CONTROLLER_IMG):$(TAG) $(CONTROLLER_IMG):$(RELEASE_ALIAS_TAG) 207 208 .PHONY: release-notes 209 release-notes: $(RELEASE_NOTES) 210 $(RELEASE_NOTES) 211 212 ## -------------------------------------- 213 ## Cleanup / Verification 214 ## -------------------------------------- 215 216 .PHONY: clean 217 clean: ## Remove all generated files 218 $(MAKE) clean-release 219 220 .PHONY: clean-release 221 clean-release: ## Remove the release folder 222 rm -rf $(RELEASE_DIR) 223 224 ## -------------------------------------- 225 ## Others / Utilities 226 ## -------------------------------------- 227 228 .PHONY: run 229 run: generate lint ## Run against the configured Kubernetes cluster in ~/.kube/config 230 go run ./main.go 231 232 .PHONY: install 233 install: generate ## Install CRDs into a cluster 234 kubectl apply -f config/crd/bases 235 236 .PHONY: deploy 237 deploy: generate ## Deploy controller in the configured Kubernetes cluster in ~/.kube/config 238 kubectl apply -f config/crd/bases 239 kubectl kustomize config/default | kubectl apply -f -