k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/build/root/Makefile (about) 1 # Copyright 2016 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 DBG_MAKEFILE ?= 16 ifeq ($(DBG_MAKEFILE),1) 17 $(warning ***** starting Makefile for goal(s) "$(MAKECMDGOALS)") 18 $(warning ***** $(shell date)) 19 else 20 # If we're not debugging the Makefile, don't echo recipes. 21 MAKEFLAGS += -s 22 endif 23 24 25 # Old-skool build tools. 26 # 27 # Commonly used targets (see each target for more information): 28 # all: Build code. 29 # test: Run tests. 30 # clean: Clean up. 31 32 # It's necessary to set this because some environments don't link sh -> bash. 33 SHELL := /usr/bin/env bash -o errexit -o pipefail -o nounset 34 BASH_ENV := ./hack/lib/logging.sh 35 36 # Define variables so `make --warn-undefined-variables` works. 37 PRINT_HELP ?= 38 WHAT ?= 39 TESTS ?= 40 41 # We don't need make's built-in rules. 42 MAKEFLAGS += --no-builtin-rules 43 # Be pedantic about undefined variables. 44 MAKEFLAGS += --warn-undefined-variables 45 .SUFFIXES: 46 47 # Constants used throughout. 48 .EXPORT_ALL_VARIABLES: 49 OUT_DIR ?= _output 50 BIN_DIR := $(OUT_DIR)/bin 51 52 ifdef KUBE_GOFLAGS 53 $(info KUBE_GOFLAGS is now deprecated. Please use GOFLAGS instead.) 54 ifndef GOFLAGS 55 GOFLAGS := $(KUBE_GOFLAGS) 56 unexport KUBE_GOFLAGS 57 else 58 $(error Both KUBE_GOFLAGS and GOFLAGS are set. Please use just GOFLAGS) 59 endif 60 endif 61 62 # This controls the verbosity of the build. Higher numbers mean more output. 63 KUBE_VERBOSE ?= 1 64 65 define ALL_HELP_INFO 66 # Build code. 67 # 68 # Args: 69 # WHAT: Directory or Go package names to build. If any of these directories 70 # has a 'main' package, the build will produce executable files under 71 # $(OUT_DIR)/bin. If not specified, "everything" will be built. 72 # "vendor/<module>/<path>" is accepted as alias for "<module>/<path>". 73 # "ginkgo" is an alias for the ginkgo CLI. 74 # GOFLAGS: Extra flags to pass to 'go' when building. 75 # GOLDFLAGS: Extra linking flags passed to 'go' when building. 76 # GOGCFLAGS: Additional go compile flags passed to 'go' when building. 77 # DBG: If set to "1", build with optimizations disabled for easier 78 # debugging. Any other value is ignored. 79 # 80 # Example: 81 # make 82 # make all 83 # make all WHAT=cmd/kubelet GOFLAGS=-v 84 # make all DBG=1 85 # Note: Specify DBG=1 for building unstripped binaries, which allows you to 86 # use code debugging tools like delve. When DBG is unspecified, it defaults 87 # to "-s -w" which strips debug information. 88 endef 89 .PHONY: all 90 ifeq ($(PRINT_HELP),y) 91 all: 92 echo "$$ALL_HELP_INFO" 93 else 94 all: 95 hack/make-rules/build.sh $(WHAT) 96 endif 97 98 define GINKGO_HELP_INFO 99 # Build ginkgo 100 # 101 # Example: 102 # make ginkgo 103 endef 104 .PHONY: ginkgo 105 ifeq ($(PRINT_HELP),y) 106 ginkgo: 107 echo "$$GINKGO_HELP_INFO" 108 else 109 ginkgo: 110 hack/make-rules/build.sh github.com/onsi/ginkgo/v2/ginkgo 111 endif 112 113 define VERIFY_HELP_INFO 114 # Runs all the presubmission verifications. 115 # 116 # Args: 117 # BRANCH: Branch to be passed to verify-vendor.sh script. 118 # WHAT: List of checks to run 119 # 120 # Example: 121 # make verify 122 # make verify BRANCH=branch_x 123 # make verify WHAT="gofmt typecheck" 124 endef 125 .PHONY: verify 126 ifeq ($(PRINT_HELP),y) 127 verify: 128 echo "$$VERIFY_HELP_INFO" 129 else ifeq ($(origin KUBE_VERIFY_GIT_BRANCH), undefined) 130 verify: 131 KUBE_VERIFY_GIT_BRANCH=$(BRANCH) hack/make-rules/verify.sh 132 else 133 verify: 134 hack/make-rules/verify.sh 135 endif 136 137 define QUICK_VERIFY_HELP_INFO 138 # Runs only the presubmission verifications that aren't slow. 139 # 140 # Example: 141 # make quick-verify 142 endef 143 .PHONY: quick-verify 144 ifeq ($(PRINT_HELP),y) 145 quick-verify: 146 echo "$$QUICK_VERIFY_HELP_INFO" 147 else 148 quick-verify: 149 QUICK=true SILENT=false hack/make-rules/verify.sh 150 endif 151 152 define UPDATE_HELP_INFO 153 # Runs all the update scripts. 154 # 155 # Example: 156 # make update 157 endef 158 .PHONY: update 159 ifeq ($(PRINT_HELP),y) 160 update: 161 echo "$$UPDATE_HELP_INFO" 162 else 163 update: 164 hack/make-rules/update.sh 165 endif 166 167 define CHECK_TEST_HELP_INFO 168 # Build and run tests. 169 # 170 # Args: 171 # WHAT: Directory names to test. All *_test.go files under these 172 # directories will be run. If not specified, "everything" will be tested. 173 # TESTS: Same as WHAT. 174 # KUBE_COVER: Whether to run tests with code coverage. Set to 'y' to enable coverage collection. 175 # GOFLAGS: Extra flags to pass to 'go' when building. 176 # GOLDFLAGS: Extra linking flags to pass to 'go' when building. 177 # GOGCFLAGS: Additional go compile flags passed to 'go' when building. 178 # 179 # Example: 180 # make check 181 # make test 182 # make check WHAT=./pkg/kubelet GOFLAGS=-v 183 endef 184 .PHONY: check test 185 ifeq ($(PRINT_HELP),y) 186 check test: 187 echo "$$CHECK_TEST_HELP_INFO" 188 else 189 check test: 190 hack/make-rules/test.sh $(WHAT) $(TESTS) 191 endif 192 193 define TEST_IT_HELP_INFO 194 # Build and run integration tests. 195 # 196 # Args: 197 # WHAT: Directory names to test. All *_test.go files under these 198 # directories will be run. If not specified, "everything" will be tested. 199 # KUBE_TEST_ARGS: Arguments to pass to the resulting go test invocation. 200 # 201 # Example: 202 # make test-integration 203 # make test-integration WHAT=./test/integration/kubelet GOFLAGS="-v -coverpkg=./pkg/kubelet/..." KUBE_COVER="y" 204 # make test-integration WHAT=./test/integration/pods GOFLAGS="-v" KUBE_TEST_ARGS='-run ^TestPodUpdateActiveDeadlineSeconds$$' 205 endef 206 .PHONY: test-integration 207 ifeq ($(PRINT_HELP),y) 208 test-integration: 209 echo "$$TEST_IT_HELP_INFO" 210 else 211 test-integration: 212 # KUBE_TEST_ARGS is explicitly passed here in order to ensure that we are preserving any dollar signs in the value. 213 KUBE_TEST_ARGS='$(value KUBE_TEST_ARGS)' hack/make-rules/test-integration.sh $(WHAT) 214 endif 215 216 define TEST_E2E_NODE_HELP_INFO 217 # Build and run node end-to-end tests. 218 # 219 # Args: 220 # FOCUS: Regexp that matches the tests to be run. Defaults to "". 221 # SKIP: Regexp that matches the tests that needs to be skipped. 222 # Defaults to "\[Flaky\]|\[Slow\]|\[Serial\]". 223 # TEST_ARGS: A space-separated list of arguments to pass to node e2e test. 224 # Defaults to "". 225 # RUN_UNTIL_FAILURE: If true, pass --until-it-fails=true to ginkgo so tests are run 226 # repeatedly until they fail. Defaults to false. 227 # REMOTE: If true, run the tests on a remote host. Defaults to false. 228 # REMOTE_MODE: For REMOTE=true only. Mode for remote execution (eg. gce, ssh). 229 # If set to "gce", an instance can be provisioned or reused from GCE. If set 230 # to "ssh", provided `HOSTS` must be IPs or resolvable. Defaults to "gce". 231 # ARTIFACTS: Local directory to scp test artifacts into from the remote hosts 232 # for REMOTE=true. Local directory to write juntil xml results into for REMOTE=false. 233 # Defaults to "/tmp/_artifacts/$$(date +%y%m%dT%H%M%S)". 234 # TIMEOUT: For REMOTE=true only. How long (in golang duration format) to wait 235 # for ginkgo tests to complete. Defaults to 45m. 236 # PARALLELISM: The number of ginkgo nodes to run. Defaults to 8. 237 # CONTAINER_RUNTIME_ENDPOINT: remote container endpoint to connect to. 238 # Defaults to "/run/containerd/containerd.sock". 239 # IMAGE_SERVICE_ENDPOINT: remote image endpoint to connect to, to prepull images. 240 # Defaults to CONTAINER_RUNTIME_ENDPOINT. 241 # IMAGE_CONFIG_FILE: path to a file containing image configuration. 242 # IMAGE_CONFIG_DIR: path to image config files. 243 # SYSTEM_SPEC_NAME: The name of the system spec to be used for validating the 244 # image in the node conformance test. The specs are located at 245 # test/e2e_node/system/specs/. For example, "SYSTEM_SPEC_NAME=gke" will use 246 # the spec at test/e2e_node/system/specs/gke.yaml. If unspecified, the 247 # default built-in spec (system.DefaultSpec) will be used. 248 # IMAGES: For REMOTE=true only. Comma delimited list of images for creating 249 # remote hosts to run tests against. Defaults to a recent image. 250 # HOSTS: For REMOTE=true only. Comma delimited list of running gce hosts to 251 # run tests against. Defaults to "". 252 # DELETE_INSTANCES: For REMOTE=true only. Delete any instances created as 253 # part of this test run. Defaults to false. 254 # PREEMPTIBLE_INSTANCES: For REMOTE=true only. Mark created gce instances 255 # as preemptible. Defaults to false. 256 # CLEANUP: For REMOTE=true only. If false, do not stop processes or delete 257 # test files on remote hosts. Defaults to true. 258 # IMAGE_PROJECT: For REMOTE=true only. Project containing images provided to 259 # $$IMAGES. Defaults to "cos-cloud". 260 # INSTANCE_PREFIX: For REMOTE=true only. Instances created from images will 261 # have the name "$${INSTANCE_PREFIX}-$${IMAGE_NAME}". Defaults to "test". 262 # INSTANCE_METADATA: For REMOTE=true and running on GCE only. 263 # GUBERNATOR: For REMOTE=true only. Produce link to Gubernator to view logs. 264 # Defaults to false. 265 # TEST_SUITE: For REMOTE=true only. Test suite to use. Defaults to "default". 266 # SSH_USER: For REMOTE=true only SSH username to use. 267 # SSH_KEY: For REMOTE=true only. Path to SSH key to use. 268 # SSH_OPTIONS: For REMOTE=true only. SSH options to use. 269 # INSTANCE_TYPE: For REMOTE=true only. Machine type to use. 270 # NODE_ENV: For REMOTE=true only. Additional metadata keys to add the instance. 271 # RUNTIME_CONFIG: The runtime configuration for the API server on the node e2e tests. 272 # E2E_TEST_DEBUG_TOOL: one of dlv/delve/gdb. Runs the test/e2e_node test binary 273 # interactively under the chosen debugger. Only works for REMOTE=false and 274 # in combination with DBG=1. 275 # 276 # Example: 277 # make test-e2e-node FOCUS=Kubelet SKIP=container 278 # make test-e2e-node REMOTE=true DELETE_INSTANCES=true 279 # make test-e2e-node TEST_ARGS='--kubelet-flags="--cgroups-per-qos=true"' 280 # Build and run tests. 281 endef 282 .PHONY: test-e2e-node 283 ifeq ($(PRINT_HELP),y) 284 test-e2e-node: 285 echo "$$TEST_E2E_NODE_HELP_INFO" 286 else 287 test-e2e-node: ginkgo 288 hack/make-rules/test-e2e-node.sh 289 endif 290 291 define TEST_CMD_HELP_INFO 292 # Build and run cmdline tests. 293 # 294 # Args: 295 # WHAT: List of tests to run, check test/cmd/legacy-script.sh for names. 296 # For example, WHAT=deployment will run run_deployment_tests function. 297 # Example: 298 # make test-cmd 299 # make test-cmd WHAT="deployment impersonation" 300 endef 301 .PHONY: test-cmd 302 ifeq ($(PRINT_HELP),y) 303 test-cmd: 304 echo "$$TEST_CMD_HELP_INFO" 305 else 306 test-cmd: 307 hack/make-rules/test-cmd.sh 308 endif 309 310 define CLEAN_HELP_INFO 311 # Remove all build artifacts. 312 # 313 # Example: 314 # make clean 315 endef 316 .PHONY: clean 317 ifeq ($(PRINT_HELP),y) 318 clean: 319 echo "$$CLEAN_HELP_INFO" 320 else 321 clean: 322 build/make-clean.sh 323 hack/make-rules/clean.sh 324 endif 325 326 define VET_HELP_INFO 327 # Run 'go vet'. 328 # 329 # Args: 330 # WHAT: Directory names to vet. All *.go files under these 331 # directories will be vetted. If not specified, "everything" will be 332 # vetted. 333 # 334 # Example: 335 # make vet 336 # make vet WHAT=./pkg/kubelet 337 endef 338 .PHONY: vet 339 ifeq ($(PRINT_HELP),y) 340 vet: 341 echo "$$VET_HELP_INFO" 342 else 343 vet: 344 hack/make-rules/vet.sh $(WHAT) 345 endif 346 347 define LINT_HELP_INFO 348 # Run golangci-lint 349 # 350 # Example: 351 # make lint 352 endef 353 .PHONY: lint 354 ifeq ($(PRINT_HELP),y) 355 lint: 356 echo "$$LINT_HELP_INFO" 357 else 358 lint: 359 hack/verify-golangci-lint.sh 360 endif 361 362 define RELEASE_HELP_INFO 363 # Build a release 364 # Use the 'release-in-a-container' target to build the release when already in 365 # a container vs. creating a new container to build in using the 'release' 366 # target. Useful for running in GCB. 367 # 368 # Example: 369 # make release 370 # make release-in-a-container 371 endef 372 .PHONY: release release-in-a-container 373 ifeq ($(PRINT_HELP),y) 374 release release-in-a-container: 375 echo "$$RELEASE_HELP_INFO" 376 else 377 release release-in-a-container: KUBE_BUILD_CONFORMANCE = y 378 release: 379 build/release.sh 380 release-in-a-container: 381 build/release-in-a-container.sh 382 endif 383 384 define RELEASE_IMAGES_HELP_INFO 385 # Build release images 386 # 387 # Args: 388 # KUBE_BUILD_CONFORMANCE: Whether to build conformance testing image as well. Set to 'n' to skip. 389 # DBG: If set to "1", build with optimizations disabled for easier debugging. Any other value is ignored. 390 # 391 # Example: 392 # make release-images 393 # make release-images DBG=1 394 # Note: Specify DBG=1 for building unstripped binaries, which allows you to use code debugging 395 # tools like delve. When DBG is unspecified, it defaults to "-s -w" which strips debug 396 # information. 397 endef 398 .PHONY: release-images 399 ifeq ($(PRINT_HELP),y) 400 release-images: KUBE_BUILD_CONFORMANCE = y 401 release-images: 402 echo "$$RELEASE_IMAGES_HELP_INFO" 403 else 404 release-images: 405 build/release-images.sh 406 endif 407 408 define RELEASE_SKIP_TESTS_HELP_INFO 409 # Build a release, but skip tests 410 # 411 # Args: 412 # KUBE_RELEASE_RUN_TESTS: Whether to run tests. Set to 'y' to run tests anyways. 413 # KUBE_FASTBUILD: Whether to cross-compile for other architectures. Set to 'false' to do so. 414 # KUBE_DOCKER_REGISTRY: Registry of released images, default to registry.k8s.io 415 # KUBE_BASE_IMAGE_REGISTRY: Registry of base images for controlplane binaries, default to registry.k8s.io/build-image 416 # 417 # Example: 418 # make release-skip-tests 419 # make quick-release 420 endef 421 .PHONY: release-skip-tests quick-release 422 ifeq ($(PRINT_HELP),y) 423 release-skip-tests quick-release: 424 echo "$$RELEASE_SKIP_TESTS_HELP_INFO" 425 else 426 release-skip-tests quick-release: KUBE_RELEASE_RUN_TESTS = n 427 release-skip-tests quick-release: KUBE_FASTBUILD = true 428 release-skip-tests quick-release: 429 build/release.sh 430 endif 431 432 define QUICK_RELEASE_IMAGES_HELP_INFO 433 # Build release images, but only for linux/amd64 434 # 435 # Args: 436 # KUBE_FASTBUILD: Whether to cross-compile for other architectures. Set to 'false' to do so. 437 # KUBE_BUILD_CONFORMANCE: Whether to build conformance testing image as well. Set to 'y' to do so. 438 # DBG: If set to "1", build with optimizations disabled for easier debugging. Any other value is ignored. 439 # 440 # Example: 441 # make quick-release-images 442 # make quick-release-images DBG=1 443 # Note: Specify DBG=1 for building unstripped binaries, which allows you to use code debugging 444 # tools like delve. When DBG is unspecified, it defaults to "-s -w" which strips debug 445 # information. 446 endef 447 .PHONY: quick-release-images 448 ifeq ($(PRINT_HELP),y) 449 quick-release-images: 450 echo "$$QUICK_RELEASE_IMAGES_HELP_INFO" 451 else 452 quick-release-images: KUBE_FASTBUILD = true 453 quick-release-images: 454 build/release-images.sh 455 endif 456 457 define PACKAGE_HELP_INFO 458 # Package tarballs 459 # Use the 'package-tarballs' target to run the final packaging steps of 460 # a release. 461 # 462 # Example: 463 # make package-tarballs 464 endef 465 .PHONY: package package-tarballs 466 ifeq ($(PRINT_HELP),y) 467 package package-tarballs: 468 echo "$$PACKAGE_HELP_INFO" 469 else 470 package-tarballs: KUBE_BUILD_CONFORMANCE = y 471 package package-tarballs: 472 build/package-tarballs.sh 473 endif 474 475 define CROSS_HELP_INFO 476 # Cross-compile for all platforms 477 # Use the 'cross-in-a-container' target to cross build when already in 478 # a container vs. creating a new container to build from (build-image) 479 # Useful for running in GCB. 480 # 481 # Example: 482 # make cross 483 # make cross-in-a-container 484 endef 485 .PHONY: cross cross-in-a-container 486 ifeq ($(PRINT_HELP),y) 487 cross cross-in-a-container: 488 echo "$$CROSS_HELP_INFO" 489 else 490 cross cross-in-a-container: KUBE_BUILD_CONFORMANCE = y 491 cross: 492 hack/make-rules/cross.sh 493 cross-in-a-container: KUBE_OUTPUT_SUBPATH = $(OUT_DIR)/dockerized 494 cross-in-a-container: 495 ifeq (,$(wildcard /.dockerenv)) 496 echo -e "\nThe 'cross-in-a-container' target can only be used from within a docker container.\n" 497 else 498 hack/make-rules/cross.sh 499 endif 500 endif 501 502 define CMD_HELP_INFO 503 # Add rules for all directories in cmd/ 504 # 505 # Example: 506 # make kubectl kube-proxy 507 endef 508 #TODO: make EXCLUDE_TARGET auto-generated when there are other files in cmd/ 509 EXCLUDE_TARGET=OWNERS 510 CMD_TARGET = $(filter-out %$(EXCLUDE_TARGET),$(notdir $(abspath $(wildcard cmd/*/)))) 511 .PHONY: $(CMD_TARGET) 512 ifeq ($(PRINT_HELP),y) 513 $(CMD_TARGET): 514 echo "$$CMD_HELP_INFO" 515 else 516 $(CMD_TARGET): 517 hack/make-rules/build.sh cmd/$@ 518 endif 519 520 define HELP_INFO 521 # Print make targets and help info 522 # 523 # Example: 524 # make help 525 endef 526 .PHONY: help 527 ifeq ($(PRINT_HELP),y) 528 help: 529 echo "$$HELP_INFO" 530 else 531 help: 532 hack/make-rules/make-help.sh 533 endif