sigs.k8s.io/controller-tools@v0.15.1-0.20240515195456-85686cb69316/Makefile (about) 1 #!/usr/bin/env bash 2 3 # Copyright 2024 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # If you update this file, please follow 18 # https://suva.sh/posts/well-documented-makefiles 19 20 ## -------------------------------------- 21 ## General 22 ## -------------------------------------- 23 24 SHELL:=/usr/bin/env bash 25 .DEFAULT_GOAL:=help 26 27 # Use GOPROXY environment variable if set 28 GOPROXY := $(shell go env GOPROXY) 29 ifeq ($(GOPROXY),) 30 GOPROXY := https://proxy.golang.org 31 endif 32 export GOPROXY 33 34 # Active module mode, as we use go modules to manage dependencies 35 export GO111MODULE=on 36 37 # Tools. 38 ENVTEST_DIR := hack/envtest 39 ENVTEST_MATRIX_DIR := $(ENVTEST_DIR)/_matrix 40 TOOLS_DIR := hack/tools 41 TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/bin) 42 GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/golangci-lint) 43 GO_INSTALL := ./hack/go-install.sh 44 45 ## -------------------------------------- 46 ## Binaries 47 ## -------------------------------------- 48 49 GOLANGCI_LINT_BIN := golangci-lint 50 GOLANGCI_LINT_VER := $(shell cat .github/workflows/golangci-lint.yml | grep [[:space:]]version: | sed 's/.*version: //') 51 GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER)) 52 GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint 53 54 $(GOLANGCI_LINT): # Build golangci-lint from tools folder. 55 GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(GOLANGCI_LINT_PKG) $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER) 56 57 ## -------------------------------------- 58 ## Linting 59 ## -------------------------------------- 60 61 .PHONY: lint 62 lint: $(GOLANGCI_LINT) ## Lint codebase 63 $(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS) 64 cd tools/setup-envtest; $(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS) 65 66 .PHONY: lint-fix 67 lint-fix: $(GOLANGCI_LINT) ## Lint the codebase and run auto-fixers if supported by the linter. 68 GOLANGCI_LINT_EXTRA_ARGS=--fix $(MAKE) lint 69 70 ## -------------------------------------- 71 ## Testing 72 ## -------------------------------------- 73 74 .PHONY: test 75 test: ## Run the test.sh script which will check all. 76 TRACE=1 ./test.sh 77 78 test-all: 79 $(MAKE) test 80 81 .PHONY: modules 82 modules: ## Runs go mod to ensure modules are up to date. 83 go mod tidy 84 85 ## -------------------------------------- 86 ## Cleanup / Verification 87 ## -------------------------------------- 88 89 .PHONY: clean 90 clean: ## Cleanup. 91 $(GOLANGCI_LINT) cache clean 92 $(MAKE) clean-bin 93 94 .PHONY: clean-bin 95 clean-bin: ## Remove all generated binaries. 96 rm -rf hack/tools/bin 97 98 .PHONE: clean-release 99 clean-release: ## Remove all generated release binaries. 100 rm -rf $(RELEASE_DIR) 101 102 ## -------------------------------------- 103 ## Envtest Build 104 ## -------------------------------------- 105 106 RELEASE_DIR := out 107 108 .PHONY: $(RELEASE_DIR) 109 $(RELEASE_DIR): 110 mkdir -p $(RELEASE_DIR)/ 111 112 .PHONY: release-envtest 113 release-envtest: clean-release ## Build the envtest binaries by operating system. 114 OS=linux ARCH=amd64 $(MAKE) release-envtest-docker-build 115 OS=linux ARCH=arm64 $(MAKE) release-envtest-docker-build 116 OS=linux ARCH=ppc64le $(MAKE) release-envtest-docker-build 117 OS=linux ARCH=s390x $(MAKE) release-envtest-docker-build 118 OS=darwin ARCH=amd64 $(MAKE) release-envtest-docker-build 119 OS=darwin ARCH=arm64 $(MAKE) release-envtest-docker-build 120 OS=windows ARCH=amd64 $(MAKE) release-envtest-docker-build 121 ./hack/envtest/update-releases.sh 122 123 .PHONY: release-envtest-docker-build 124 release-envtest-docker-build: $(RELEASE_DIR) ## Build the envtest binaries. 125 @: $(if $(KUBERNETES_VERSION),,$(error KUBERNETES_VERSION is not set)) 126 @: $(if $(OS),,$(error OS is not set)) 127 @: $(if $(ARCH),,$(error ARCH is not set)) 128 docker buildx build \ 129 --file ./hack/envtest/$(OS)/Dockerfile \ 130 --build-arg KUBERNETES_VERSION=$(KUBERNETES_VERSION) \ 131 --build-arg GO_VERSION=$(shell yq eval '.go' $(ENVTEST_MATRIX_DIR)/$(KUBERNETES_VERSION).yaml) \ 132 --build-arg ETCD_VERSION=$(shell yq eval '.etcd' $(ENVTEST_MATRIX_DIR)/$(KUBERNETES_VERSION).yaml) \ 133 --build-arg OS=$(OS) \ 134 --build-arg ARCH=$(ARCH) \ 135 --tag sigs.k8s.io/controller-tools/envtest:$(KUBERNETES_VERSION)-$(OS)-$(ARCH) \ 136 --output type=local,dest=$(RELEASE_DIR) \ 137 .