diff --git a/Makefile b/Makefile index c2f623ae64e8..17b1a1aa3599 100644 --- a/Makefile +++ b/Makefile @@ -153,6 +153,10 @@ KUBEADM_BOOTSTRAP_CONTROLLER_IMG ?= $(REGISTRY)/$(KUBEADM_BOOTSTRAP_IMAGE_NAME) KUBEADM_CONTROL_PLANE_IMAGE_NAME ?= kubeadm-control-plane-controller KUBEADM_CONTROL_PLANE_CONTROLLER_IMG ?= $(REGISTRY)/$(KUBEADM_CONTROL_PLANE_IMAGE_NAME) +# capd +CAPD_IMAGE_NAME ?= capd-manager +CAPD_CONTROLLER_IMG ?= $(REGISTRY)/$(CAPD_IMAGE_NAME) + # clusterctl CLUSTERCTL_MANIFEST_DIR := cmd/clusterctl/config CLUSTERCTL_IMAGE_NAME ?= clusterctl @@ -188,12 +192,11 @@ help: # Display this help ##@ generate: -ALL_GENERATE_MODULES = core kubeadm-bootstrap kubeadm-control-plane +ALL_GENERATE_MODULES = core kubeadm-bootstrap kubeadm-control-plane capd .PHONY: generate generate: ## Run all generate-manifests-*, generate-go-deepcopy-*, generate-go-conversions-* and generate-go-openapi targets $(MAKE) generate-modules generate-manifests generate-go-deepcopy generate-go-conversions generate-go-openapi - $(MAKE) -C $(CAPD_DIR) generate .PHONY: generate-manifests generate-manifests: $(addprefix generate-manifests-,$(ALL_GENERATE_MODULES)) ## Run all generate-manifests-* targets @@ -246,6 +249,19 @@ generate-manifests-kubeadm-control-plane: $(CONTROLLER_GEN) ## Generate manifest output:webhook:dir=./controlplane/kubeadm/config/webhook \ webhook +.PHONY: generate-manifests-capd +generate-manifests-capd: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc. for capd provider + cd $(CAPD_DIR); $(CONTROLLER_GEN) \ + paths=./api/... \ + paths=./$(EXP_DIR)/api/... \ + paths=./$(EXP_DIR)/internal/controllers/... \ + paths=./internal/controllers/... \ + crd:crdVersions=v1 \ + rbac:roleName=manager-role \ + output:crd:dir=./config/crd/bases \ + output:webhook:dir=./config/webhook \ + webhook + .PHONY: generate-go-deepcopy generate-go-deepcopy: ## Run all generate-go-deepcopy-* targets $(MAKE) $(addprefix generate-go-deepcopy-,$(ALL_GENERATE_MODULES)) @@ -276,6 +292,13 @@ generate-go-deepcopy-kubeadm-control-plane: $(CONTROLLER_GEN) ## Generate deepco object:headerFile=./hack/boilerplate/boilerplate.generatego.txt \ paths=./controlplane/kubeadm/api/... +.PHONY: generate-go-deepcopy-capd +generate-go-deepcopy-capd: $(CONTROLLER_GEN) ## Generate deepcopy go code for capd + cd $(CAPD_DIR); $(CONTROLLER_GEN) \ + object:headerFile=../../../hack/boilerplate/boilerplate.generatego.txt \ + paths=./api/... \ + paths=./$(EXP_DIR)/api/... + .PHONY: generate-go-conversions generate-go-conversions: ## Run all generate-go-conversions-* targets $(MAKE) $(addprefix generate-go-conversions-,$(ALL_GENERATE_MODULES)) @@ -353,6 +376,19 @@ generate-go-conversions-kubeadm-control-plane: $(CONVERSION_GEN) ## Generate con --output-file-base=zz_generated.conversion $(CONVERSION_GEN_OUTPUT_BASE) \ --go-header-file=./hack/boilerplate/boilerplate.generatego.txt +.PHONY: generate-go-conversions-capd +generate-go-conversions-capd: $(CONVERSION_GEN) ## Generate conversions go code for capd + cd $(CAPD_DIR); $(CONVERSION_GEN) \ + --input-dirs=./api/v1alpha3 \ + --input-dirs=./api/v1alpha4 \ + --input-dirs=./$(EXP_DIR)/api/v1alpha3 \ + --input-dirs=./$(EXP_DIR)/api/v1alpha4 \ + --build-tag=ignore_autogenerated_capd \ + --extra-peer-dirs=sigs.k8s.io/cluster-api/api/v1alpha3 \ + --extra-peer-dirs=sigs.k8s.io/cluster-api/api/v1alpha4 \ + --output-file-base=zz_generated.conversion $(CONVERSION_GEN_OUTPUT_BASE) \ + --go-header-file=../../../hack/boilerplate/boilerplate.generatego.txt + .PHONY: generate-go-openapi generate-go-openapi: $(OPENAPI_GEN) $(CONTROLLER_GEN) ## Generate openapi go code for runtime SDK @for pkg in "api/v1beta1" "$(EXP_DIR)/runtime/hooks/api/v1alpha1"; do \ @@ -401,7 +437,7 @@ APIDIFF_OLD_COMMIT ?= $(shell git rev-parse origin/main) apidiff: $(GO_APIDIFF) ## Check for API differences $(GO_APIDIFF) $(APIDIFF_OLD_COMMIT) --print-compatible -ALL_VERIFY_CHECKS = doctoc boilerplate shellcheck tiltfile modules gen conversions docker-provider +ALL_VERIFY_CHECKS = doctoc boilerplate shellcheck tiltfile modules gen conversions .PHONY: verify verify: $(addprefix verify-,$(ALL_VERIFY_CHECKS)) ## Run all verify-* targets @@ -444,11 +480,6 @@ verify-shellcheck: ## Verify shell files verify-tiltfile: ## Verify Tiltfile format ./hack/verify-starlark.sh -.PHONY: verify-docker-provider -verify-docker-provider: - @echo "Verifying CAPD" - cd $(CAPD_DIR); $(MAKE) verify - ## -------------------------------------- ## Binaries ## -------------------------------------- @@ -459,7 +490,7 @@ verify-docker-provider: clusterctl: ## Build the clusterctl binary go build -trimpath -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/clusterctl sigs.k8s.io/cluster-api/cmd/clusterctl -ALL_MANAGERS = core kubeadm-bootstrap kubeadm-control-plane +ALL_MANAGERS = core kubeadm-bootstrap kubeadm-control-plane capd .PHONY: managers managers: $(addprefix manager-,$(ALL_MANAGERS)) ## Run all manager-* targets @@ -476,6 +507,10 @@ manager-kubeadm-bootstrap: ## Build the kubeadm bootstrap manager binary into th manager-kubeadm-control-plane: ## Build the kubeadm control plane manager binary into the ./bin folder go build -trimpath -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/kubeadm-control-plane-manager sigs.k8s.io/cluster-api/controlplane/kubeadm +.PHONY: manager-capd +manager-capd: ## Build the kubeadm control plane manager binary into the ./bin folder + cd $(CAPD_DIR); go build -trimpath -ldflags "$(LDFLAGS)" -o ../../../$(BIN_DIR)/capd-manager sigs.k8s.io/cluster-api/test/infrastructure/docker + .PHONY: docker-pull-prerequisites docker-pull-prerequisites: docker pull docker.io/docker/dockerfile:1.1-experimental @@ -516,6 +551,9 @@ docker-build-kubeadm-control-plane: ## Build the docker image for kubeadm contro docker-build-clusterctl: ## Build the docker image for clusterctl with output binary name as 'clusterctl' DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE) --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg package=./cmd/clusterctl --build-arg ldflags="$(LDFLAGS)" -f ./cmd/clusterctl/Dockerfile . -t $(CLUSTERCTL_IMG)-$(ARCH):$(TAG) +.PHONY: docker-capd-build-all +docker-capd-build-all: $(addprefix docker-capd-build-,$(ALL_ARCH)) ## Build capd docker images for all architectures + .PHONY: e2e-framework e2e-framework: ## Builds the CAPI e2e framework cd $(E2E_FRAMEWORK_DIR); go build ./... @@ -528,6 +566,15 @@ build-book: ## Build the book serve-book: ## Build and serve the book (with live-reload) $(MAKE) -C docs/book serve +docker-capd-build-%: + $(MAKE) ARCH=$* docker-capd-build + +.PHONY: docker-capd-build +docker-capd-build: ## Build the docker image for capd + cd $(CAPD_DIR); DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE) --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg ldflags="$(LDFLAGS)" ../../.. -t $(CAPD_CONTROLLER_IMG)-$(ARCH):$(TAG) --file Dockerfile + $(MAKE) set-manifest-image MANIFEST_IMG=$(CAPD_CONTROLLER_IMG)-$(ARCH) MANIFEST_TAG=$(TAG) TARGET_RESOURCE="$(CAPD_DIR)/config/default/manager_image_patch.yaml" + $(MAKE) set-manifest-pull-policy TARGET_RESOURCE="$(CAPD_DIR)/config/default/manager_pull_policy.yaml" + ## -------------------------------------- ## Testing ## -------------------------------------- @@ -566,14 +613,28 @@ test-cover: ## Run unit and integration tests and generate a coverage report test-e2e: ## Run e2e tests $(MAKE) -C $(TEST_DIR)/e2e run +.PHONY: test-capd +test-capd: $(SETUP_ENVTEST) ## Run unit and integration tests for capd + cd $(CAPD_DIR); KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test ./... $(TEST_ARGS) + +.PHONY: test-capd-verbose +test-capd-verbose: ## Run unit and integration tests with verbose flag + $(MAKE) test-capd TEST_ARGS="$(TEST_ARGS) -v" + +.PHONY: test-capd-junit +test-capd-junit: $(SETUP_ENVTEST) $(GOTESTSUM) ## Run unit and integration tests and generate a junit report for capd + cd $(CAPD_DIR); set +o errexit; (KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test -json ./... $(TEST_ARGS); echo $$? > $(ARTIFACTS)/junit.infra_docker.exitcode) | tee $(ARTIFACTS)/junit.infra_docker.stdout + $(GOTESTSUM) --junitfile $(ARTIFACTS)/junit.infra_docker.xml --raw-command cat $(ARTIFACTS)/junit.infra_docker.stdout + exit $$(cat $(ARTIFACTS)/junit.infra_docker.exitcode) + .PHONY: kind-cluster kind-cluster: ## Create a new kind cluster designed for development with Tilt hack/kind-install-for-capd.sh .PHONY: docker-build-e2e docker-build-e2e: ## Rebuild all Cluster API provider images to be used in the e2e tests - make docker-build REGISTRY=gcr.io/k8s-staging-cluster-api PULL_POLICY=IfNotPresent - $(MAKE) -C $(CAPD_DIR) docker-build REGISTRY=gcr.io/k8s-staging-cluster-api PULL_POLICY=IfNotPresent + $(MAKE) docker-build REGISTRY=gcr.io/k8s-staging-cluster-api PULL_POLICY=IfNotPresent + $(MAKE) docker-capd-build REGISTRY=gcr.io/k8s-staging-cluster-api PULL_POLICY=IfNotPresent ## -------------------------------------- ## Release @@ -626,9 +687,13 @@ manifest-modification: # Set the manifest images to the staging/production bucke $(MAKE) set-manifest-image \ MANIFEST_IMG=$(REGISTRY)/$(KUBEADM_CONTROL_PLANE_IMAGE_NAME) MANIFEST_TAG=$(RELEASE_TAG) \ TARGET_RESOURCE="./controlplane/kubeadm/config/default/manager_image_patch.yaml" + $(MAKE) set-manifest-image \ + MANIFEST_IMG=$(REGISTRY)/$(CAPD_IMAGE_NAME) MANIFEST_TAG=$(RELEASE_TAG) \ + TARGET_RESOURCE="$(CAPD_DIR)/config/default/manager_image_patch.yaml" $(MAKE) set-manifest-pull-policy PULL_POLICY=IfNotPresent TARGET_RESOURCE="./config/default/manager_pull_policy.yaml" $(MAKE) set-manifest-pull-policy PULL_POLICY=IfNotPresent TARGET_RESOURCE="./bootstrap/kubeadm/config/default/manager_pull_policy.yaml" $(MAKE) set-manifest-pull-policy PULL_POLICY=IfNotPresent TARGET_RESOURCE="./controlplane/kubeadm/config/default/manager_pull_policy.yaml" + $(MAKE) set-manifest-pull-policy PULL_POLICY=IfNotPresent TARGET_RESOURCE="$(CAPD_DIR)/config/default/manager_pull_policy.yaml" .PHONY: release-manifests release-manifests: $(RELEASE_DIR) $(KUSTOMIZE) $(RUNTIME_OPENAPI_GEN) ## Build the manifests to publish with a release @@ -652,11 +717,8 @@ release-manifests: $(RELEASE_DIR) $(KUSTOMIZE) $(RUNTIME_OPENAPI_GEN) ## Build t $(RUNTIME_OPENAPI_GEN) --version $(RELEASE_TAG) --output-file $(RELEASE_DIR)/runtime-sdk-openapi.yaml .PHONY: release-manifests-dev -release-manifests-dev: ## Build the development manifests and copies them in the release folder - # Release CAPD components and add them to the release dir - $(MAKE) -C $(CAPD_DIR) release - cp $(CAPD_DIR)/out/infrastructure-components.yaml $(RELEASE_DIR)/infrastructure-components-development.yaml - # Adds CAPD templates +release-manifests-dev: $(RELEASE_DIR) $(KUSTOMIZE) ## Build the development manifests and copies them in the release folder + cd $(CAPD_DIR); $(KUSTOMIZE) build config/default > ../../../$(RELEASE_DIR)/infrastructure-components-development.yaml cp $(CAPD_DIR)/templates/* $(RELEASE_DIR)/ release-binaries: ## Build the binaries to publish with a release @@ -701,6 +763,26 @@ release-alias-tag: ## Add the release alias tag to the last build tag gcloud container images add-tag $(KUBEADM_CONTROL_PLANE_CONTROLLER_IMG):$(TAG) $(KUBEADM_CONTROL_PLANE_CONTROLLER_IMG):$(RELEASE_ALIAS_TAG) gcloud container images add-tag $(CLUSTERCTL_IMG):$(TAG) $(CLUSTERCTL_IMG):$(RELEASE_ALIAS_TAG) +.PHONY: release-capd-staging +release-capd-staging: ## Build and push container images to the staging bucket + REGISTRY=$(STAGING_REGISTRY) $(MAKE) docker-capd-build-all docker-capd-push-all release-capd-alias-tag + +.PHONY: release-capd-staging-nightly +release-capd-staging-nightly: ## Tag and push container images to the staging bucket. Example image tag: cluster-api-controller:nightly_main_20210121 + $(eval NEW_RELEASE_ALIAS_TAG := nightly_$(RELEASE_ALIAS_TAG)_$(shell date +'%Y%m%d')) + echo $(NEW_RELEASE_ALIAS_TAG) + $(MAKE) release-capd-alias-tag TAG=$(RELEASE_ALIAS_TAG) RELEASE_ALIAS_TAG=$(NEW_RELEASE_ALIAS_TAG) + # Set the manifest image to the staging bucket. + $(MAKE) manifest-modification REGISTRY=$(STAGING_REGISTRY) RELEASE_TAG=$(NEW_RELEASE_ALIAS_TAG) + ## Build the manifests + $(MAKE) release-manifests-dev + # Example manifest location: artifacts.k8s-staging-cluster-api.appspot.com/components/nightly_main_20210121/infrastructure-components.yaml + gsutil cp $(RELEASE_DIR)/* gs://$(STAGING_BUCKET)/components/$(NEW_RELEASE_ALIAS_TAG) + +.PHONY: release-capd-alias-tag +release-capd-alias-tag: ## Add the release alias tag to the last build tag + gcloud container images add-tag $(CAPD_CONTROLLER_IMG):$(TAG) $(CAPD_CONTROLLER_IMG):$(RELEASE_ALIAS_TAG) + .PHONY: release-notes release-notes: $(RELEASE_NOTES_DIR) $(RELEASE_NOTES) if [ -n "${PRE_RELEASE}" ]; then \ @@ -734,6 +816,17 @@ docker-push-all: $(addprefix docker-push-,$(ALL_ARCH)) ## Push all the architec docker-push-%: $(MAKE) ARCH=$* docker-push +.PHONY: docker-capd-push +docker-capd-push: ## Push the capd docker image + docker push $(CAPD_CONTROLLER_IMG)-$(ARCH):$(TAG) + +.PHONY: docker-capd-push-all +docker-capd-push-all: $(addprefix docker-capd-push-,$(ALL_ARCH)) ## Push all the architecture docker images + $(MAKE) docker-capd-push-manifest + +docker-capd-push-%: + $(MAKE) ARCH=$* docker-capd-push + .PHONY: docker-push-manifest-core docker-push-manifest-core: ## Push the multiarch manifest for the core docker images ## Minimum docker version 18.06.0 is required for creating and pushing manifest images. @@ -761,6 +854,15 @@ docker-push-manifest-kubeadm-control-plane: ## Push the multiarch manifest for t $(MAKE) set-manifest-image MANIFEST_IMG=$(KUBEADM_CONTROL_PLANE_CONTROLLER_IMG) MANIFEST_TAG=$(TAG) TARGET_RESOURCE="./controlplane/kubeadm/config/default/manager_image_patch.yaml" $(MAKE) set-manifest-pull-policy TARGET_RESOURCE="./controlplane/kubeadm/config/default/manager_pull_policy.yaml" +.PHONY: docker-push-manifest-capd +docker-capd-push-manifest: ## Push the multiarch manifest for the the capd docker images + ## Minimum docker version 18.06.0 is required for creating and pushing manifest images. + docker manifest create --amend $(CAPD_CONTROLLER_IMG):$(TAG) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(CAPD_CONTROLLER_IMG)\-&:$(TAG)~g") + @for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} ${CAPD_CONTROLLER_IMG}:${TAG} ${CAPD_CONTROLLER_IMG}-$${arch}:${TAG}; done + docker manifest push --purge $(CAPD_CONTROLLER_IMG):$(TAG) + $(MAKE) set-manifest-image MANIFEST_IMG=$(CAPD_CONTROLLER_IMG) MANIFEST_TAG=$(TAG) TARGET_RESOURCE="$(CAPD_DIR)/config/default/manager_image_patch.yaml" + $(MAKE) set-manifest-pull-policy TARGET_RESOURCE="$(CAPD_DIR)/config/default/manager_pull_policy.yaml" + .PHONY: docker-push-clusterctl docker-push-clusterctl: ## Push the clusterctl images ## Minimum docker version 18.06.0 is required for creating and pushing manifest images. diff --git a/cloudbuild-nightly.yaml b/cloudbuild-nightly.yaml index d7badb1487a8..cf4122c64d49 100644 --- a/cloudbuild-nightly.yaml +++ b/cloudbuild-nightly.yaml @@ -14,15 +14,14 @@ steps: args: - release-staging-nightly - name: 'gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:v20220609-2e4c91eb7e' - dir: 'test/infrastructure/docker' - entrypoint: make +======= env: - DOCKER_CLI_EXPERIMENTAL=enabled - TAG=$_GIT_TAG - PULL_BASE_REF=$_PULL_BASE_REF - DOCKER_BUILDKIT=1 args: - - release-staging-nightly + - release-capd-staging-nightly substitutions: # _GIT_TAG will be filled with a git-based tag for the image, of the form vYYYYMMDD-hash, and # can be used as a substitution diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 5c9d6b715419..e57bc6c085a4 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -14,15 +14,14 @@ steps: args: - release-staging - name: 'gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:v20220609-2e4c91eb7e' - dir: 'test/infrastructure/docker' - entrypoint: make +======= env: - DOCKER_CLI_EXPERIMENTAL=enabled - TAG=$_GIT_TAG - PULL_BASE_REF=$_PULL_BASE_REF - DOCKER_BUILDKIT=1 args: - - release-staging + - release-capd-staging substitutions: # _GIT_TAG will be filled with a git-based tag for the image, of the form vYYYYMMDD-hash, and # can be used as a substitution diff --git a/docs/book/src/clusterctl/developers.md b/docs/book/src/clusterctl/developers.md index 2ea1d4ab4513..de840de9b928 100644 --- a/docs/book/src/clusterctl/developers.md +++ b/docs/book/src/clusterctl/developers.md @@ -42,7 +42,7 @@ make docker-build REGISTRY=gcr.io/k8s-staging-cluster-api PULL_POLICY=IfNotPrese In order to build docker provider artifacts ``` -make -C test/infrastructure/docker docker-build REGISTRY=gcr.io/k8s-staging-cluster-api PULL_POLICY=IfNotPresent +make docker-capd-build REGISTRY=gcr.io/k8s-staging-cluster-api PULL_POLICY=IfNotPresent ``` ### Create a clusterctl-settings.json file diff --git a/docs/book/src/developer/guide.md b/docs/book/src/developer/guide.md index 0e8d52309b01..fb212e565e27 100644 --- a/docs/book/src/developer/guide.md +++ b/docs/book/src/developer/guide.md @@ -113,7 +113,7 @@ You'll need to build two docker images, one for Cluster API itself and one for t ``` make docker-build -make -C test/infrastructure/docker docker-build +make docker-capd-build ``` ### Push both images @@ -125,19 +125,17 @@ The push refers to repository [gcr.io/cluster-api-242700/cluster-api-controller- 90a39583ad5f: Layer already exists 932da5156413: Layer already exists dev: digest: sha256:263262cfbabd3d1add68172a5a1d141f6481a2bc443672ce80778dc122ee6234 size: 739 -$ make -C test/infrastructure/docker docker-push -make: Entering directory '/home/liz/src/sigs.k8s.io/cluster-api/test/infrastructure/docker' -docker push gcr.io/cluster-api-242700/manager:dev -The push refers to repository [gcr.io/cluster-api-242700/manager] +$ make docker-capd-push +docker push gcr.io/cluster-api-242700/capd-manager-amd64:dev +The push refers to repository [gcr.io/cluster-api-242700/capd-manager-amd64] 5b1e744b2bae: Pushed 932da5156413: Layer already exists dev: digest: sha256:35670a049372ae063dad910c267a4450758a139c4deb248c04c3198865589ab2 size: 739 -make: Leaving directory '/home/liz/src/sigs.k8s.io/cluster-api/test/infrastructure/docker' ``` Make a note of the URLs and the digests. You'll need them for the next step. In this case, they're... -`gcr.io/cluster-api-242700/manager@sha256:35670a049372ae063dad910c267a4450758a139c4deb248c04c3198865589ab2` +`gcr.io/cluster-api-242700/capd-manager-amd64@sha256:35670a049372ae063dad910c267a4450758a139c4deb248c04c3198865589ab2` and @@ -162,7 +160,7 @@ spec: template: spec: containers: - - image: gcr.io/cluster-api-242700/manager@sha256:35670a049372ae063dad910c267a4450758a139c4deb248c04c3198865589ab2` + - image: gcr.io/cluster-api-242700/capd-manager-amd64@sha256:35670a049372ae063dad910c267a4450758a139c4deb248c04c3198865589ab2` name: manager ``` diff --git a/docs/book/src/reference/jobs.md b/docs/book/src/reference/jobs.md index 7a9ccc8b1969..63a838ffe293 100644 --- a/docs/book/src/reference/jobs.md +++ b/docs/book/src/reference/jobs.md @@ -36,7 +36,7 @@ GitHub Presubmit Workflows: ### Postsubmits Prow Postsubmits: -* [post-cluster-api-push-images] Google Cloud Build: `make release-staging`, `make -C test/infrastructure/docker release-staging` +* [post-cluster-api-push-images] Google Cloud Build: `make release-staging`, `make release-capd-staging` ### Periodics @@ -62,7 +62,7 @@ Prow Periodics: * GINKGO_FOCUS: `[K8s-Upgrade]` * [periodic-cluster-api-e2e-workload-upgrade-1-23-latest-main] `./scripts/ci-e2e.sh` FROM: `stable-1.23` TO: `ci/latest-1.24` * GINKGO_FOCUS: `[K8s-Upgrade]` -* [cluster-api-push-images-nightly] Google Cloud Build: `make release-staging-nightly`, `make -C test/infrastructure/docker release-staging-nightly` +* [cluster-api-push-images-nightly] Google Cloud Build: `make release-staging-nightly`, `make release-capd-staging-nightly` ## Builds and Tests running on releases diff --git a/scripts/ci-build.sh b/scripts/ci-build.sh index f0c46017b0dc..86c08dc99ac6 100755 --- a/scripts/ci-build.sh +++ b/scripts/ci-build.sh @@ -20,9 +20,5 @@ set -o pipefail REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -# Core Cluster API +# Core Cluster API and Docker provider cd "${REPO_ROOT}" && make managers clusterctl e2e-framework build-book - -echo "*** Building Cluster API Provider Docker ***" -# Docker provider -cd "${REPO_ROOT}/test/infrastructure/docker" && make manager diff --git a/scripts/ci-e2e-lib.sh b/scripts/ci-e2e-lib.sh index 1a9df93d0740..0612b06661f4 100644 --- a/scripts/ci-e2e-lib.sh +++ b/scripts/ci-e2e-lib.sh @@ -35,7 +35,7 @@ capi:buildDockerImages () { ## Build CAPD provider images, if missing if [[ "$(docker images -q "$REGISTRY/capd-manager-$ARCH:$TAG" 2> /dev/null)" == "" ]]; then echo "+ Building CAPD images" - make -C test/infrastructure/docker docker-build + make docker-capd-build else echo "+ CAPD images already present in the system, skipping make" fi diff --git a/scripts/ci-test.sh b/scripts/ci-test.sh index 68163f0672a8..de861bcf4d15 100755 --- a/scripts/ci-test.sh +++ b/scripts/ci-test.sh @@ -29,5 +29,4 @@ make test-junit echo -e "\n*** Testing Cluster API Provider Docker ***\n" # Docker provider -cd test/infrastructure/docker -make test-junit +make test-capd-junit diff --git a/test/infrastructure/docker/Makefile b/test/infrastructure/docker/Makefile deleted file mode 100644 index 605a62b9e7fe..000000000000 --- a/test/infrastructure/docker/Makefile +++ /dev/null @@ -1,299 +0,0 @@ -# Copyright 2018 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/ - -ROOT = ../../.. - -.DEFAULT_GOAL:=help - -GO_VERSION ?= 1.18.3 -GO_CONTAINER_IMAGE ?= docker.io/library/golang:$(GO_VERSION) - -# 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. -ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) -TOOLS_DIR := $(ROOT)/hack/tools -TOOLS_BIN_DIR := $(TOOLS_DIR)/bin -BIN_DIR := bin -EXP_DIR := exp - -# Set --output-base for conversion-gen if we are not within GOPATH -ifneq ($(abspath $(ROOT_DIR)),$(shell go env GOPATH)/src/sigs.k8s.io/cluster-api/test/infrastructure/docker) - CONVERSION_GEN_OUTPUT_BASE := --output-base=$(ROOT_DIR) -endif - -# Binaries. -CONTROLLER_GEN_BIN := controller-gen -CONTROLLER_GEN_VER := $(shell grep "^CONTROLLER_GEN_VER" $(ROOT)/Makefile | awk '{print $$NF}') -CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/$(CONTROLLER_GEN_BIN)-$(CONTROLLER_GEN_VER)) -CONVERSION_GEN_BIN := conversion-gen -CONVERSION_GEN_VER := $(shell grep "^CONVERSION_GEN_VER" $(ROOT)/Makefile | awk '{print $$NF}') -# We are intentionally using the binary without version suffix, to avoid the version -# in generated files. -CONVERSION_GEN := $(abspath $(TOOLS_BIN_DIR)/$(CONVERSION_GEN_BIN)) -GOTESTSUM_BIN := gotestsum -GOTESTSUM_VER := $(shell grep "^GOTESTSUM_VER" $(ROOT)/Makefile | awk '{print $$NF}') -GOTESTSUM := $(abspath $(TOOLS_BIN_DIR)/$(GOTESTSUM_BIN)-$(GOTESTSUM_VER)) -KUSTOMIZE_BIN := kustomize -KUSTOMIZE_VER := $(shell grep "^KUSTOMIZE_VER" $(ROOT)/Makefile | awk '{print $$NF}') -KUSTOMIZE := $(abspath $(TOOLS_BIN_DIR)/$(KUSTOMIZE_BIN)-$(KUSTOMIZE_VER)) - -$(KUSTOMIZE): # Build kustomize from tools folder. - $(MAKE) -C $(ROOT) kustomize - -# Define Docker related variables. Releases should modify and double check these vars. -REGISTRY ?= gcr.io/$(shell gcloud config get-value project) -IMAGE_NAME ?= capd-manager -CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME) -ARCH ?= $(shell go env GOARCH) -ALL_ARCH = amd64 arm arm64 ppc64le s390x - -STAGING_REGISTRY ?= gcr.io/k8s-staging-cluster-api -STAGING_BUCKET ?= artifacts.k8s-staging-cluster-api.appspot.com - -# TAG is set to GIT_TAG in GCB, a git-based tag of the form vYYYYMMDD-hash, e.g., v20210120-v0.3.10-308-gc61521971. -TAG ?= dev - -# Allow overriding the imagePullPolicy -PULL_POLICY ?= Always - -all: test manager clusterctl - -help: ## Display this help - @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) - -## -------------------------------------- -## Testing -## -------------------------------------- - -ARTIFACTS ?= $(ROOT)/_artifacts - -.PHONY: test -test: ## Run tests. - go test ./... $(TEST_ARGS) - -.PHONY: test-verbose -test-verbose: ## Run tests with verbose settings. - TEST_ARGS="$(TEST_ARGS) -v" $(MAKE) test - -.PHONY: test-junit -test-junit: $(GOTESTSUM) ## Run tests with verbose setting and generate a junit report. - (go test -json ./... $(TEST_ARGS); echo $$? > $(ARTIFACTS)/junit.infra_docker.exitcode) | tee $(ARTIFACTS)/junit.infra_docker.stdout - $(GOTESTSUM) --junitfile $(ARTIFACTS)/junit.infra_docker.xml --raw-command cat $(ARTIFACTS)/junit.infra_docker.stdout - exit $$(cat $(ARTIFACTS)/junit.infra_docker.exitcode) - -## -------------------------------------- -## Binaries -## -------------------------------------- - -.PHONY: manager -manager: ## Build manager binary - go build -trimpath -o $(BIN_DIR)/manager sigs.k8s.io/cluster-api/test/infrastructure/docker - -$(CONTROLLER_GEN): - $(MAKE) -C $(ROOT) controller-gen - -$(CONVERSION_GEN): - $(MAKE) -C $(ROOT) conversion-gen - -$(GOTESTSUM): - $(MAKE) -C $(ROOT) gotestsum - -## -------------------------------------- -## Generate / Manifests -## -------------------------------------- - -.PHONY: generate -generate: $(CONTROLLER_GEN) ## Generate code - $(MAKE) generate-manifests - $(MAKE) generate-go - -.PHONY: generate-go -generate-go: $(CONTROLLER_GEN) $(CONVERSION_GEN) ## Runs Go related generate targets - $(CONTROLLER_GEN) \ - object:headerFile=$(ROOT)/hack/boilerplate/boilerplate.generatego.txt \ - paths=./api/... \ - paths=./$(EXP_DIR)/api/... - (IFS=','; for i in "./api/v1alpha3,./$(EXP_DIR)/api/v1alpha3"; do find $$i -type f -name 'zz_generated.conversion*' -exec rm -f {} \;; done) - (IFS=','; for i in "./api/v1alpha4,./$(EXP_DIR)/api/v1alpha4"; do find $$i -type f -name 'zz_generated.conversion*' -exec rm -f {} \;; done) - $(CONVERSION_GEN) \ - --input-dirs=./api/v1alpha3 \ - --input-dirs=./api/v1alpha4 \ - --input-dirs=./$(EXP_DIR)/api/v1alpha3 \ - --input-dirs=./$(EXP_DIR)/api/v1alpha4 \ - --build-tag=ignore_autogenerated_capd \ - --extra-peer-dirs=sigs.k8s.io/cluster-api/api/v1alpha3 \ - --extra-peer-dirs=sigs.k8s.io/cluster-api/api/v1alpha4 \ - --output-file-base=zz_generated.conversion $(CONVERSION_GEN_OUTPUT_BASE) \ - --go-header-file=$(ROOT)/hack/boilerplate/boilerplate.generatego.txt - -.PHONY: generate-manifests -generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc. - $(CONTROLLER_GEN) \ - paths=./api/... \ - paths=./$(EXP_DIR)/api/... \ - paths=./$(EXP_DIR)/internal/controllers/... \ - paths=./internal/controllers/... \ - crd:crdVersions=v1 \ - rbac:roleName=manager-role \ - output:crd:dir=./config/crd/bases \ - output:webhook:dir=./config/webhook \ - webhook - -## -------------------------------------- -## Docker -## -------------------------------------- - -.PHONY: docker-pull-prerequisites -docker-pull-prerequisites: - docker pull docker.io/docker/dockerfile:1.1-experimental - docker pull $(GO_CONTAINER_IMAGE) - docker pull gcr.io/distroless/static:latest - -.PHONY: docker-build -docker-build: docker-pull-prerequisites ## Build the docker image for controller-manager - DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE) --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) ../../.. -t $(CONTROLLER_IMG)-$(ARCH):$(TAG) --file Dockerfile - MANIFEST_IMG=$(CONTROLLER_IMG)-$(ARCH) MANIFEST_TAG=$(TAG) $(MAKE) set-manifest-image - $(MAKE) set-manifest-pull-policy - -.PHONY: docker-push -docker-push: ## Push the docker image - docker push $(CONTROLLER_IMG)-$(ARCH):$(TAG) - -## -------------------------------------- -## Docker — All ARCH -## -------------------------------------- - -.PHONY: docker-build-all ## Build all the architecture docker images -docker-build-all: $(addprefix docker-build-,$(ALL_ARCH)) - -docker-build-%: - $(MAKE) ARCH=$* docker-build - -.PHONY: docker-push-all ## Push all the architecture docker images -docker-push-all: $(addprefix docker-push-,$(ALL_ARCH)) - $(MAKE) docker-push-manifest - -docker-push-%: - $(MAKE) ARCH=$* docker-push - -.PHONY: docker-push-manifest -docker-push-manifest: ## Push the fat manifest docker image. - ## Minimum docker version 18.06.0 is required for creating and pushing manifest images. - docker manifest create --amend $(CONTROLLER_IMG):$(TAG) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(CONTROLLER_IMG)\-&:$(TAG)~g") - @for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} ${CONTROLLER_IMG}:${TAG} ${CONTROLLER_IMG}-$${arch}:${TAG}; done - docker manifest push --purge $(CONTROLLER_IMG):$(TAG) - MANIFEST_IMG=$(CONTROLLER_IMG) MANIFEST_TAG=$(TAG) $(MAKE) set-manifest-image - $(MAKE) set-manifest-pull-policy - -.PHONY: set-manifest-image -set-manifest-image: - $(info Updating kustomize image patch file for manager resource) - sed -i'' -e 's@image: .*@image: '"${MANIFEST_IMG}:$(MANIFEST_TAG)"'@' ./config/default/manager_image_patch.yaml - -.PHONY: set-manifest-pull-policy -set-manifest-pull-policy: - $(info Updating kustomize pull policy file for manager resource) - sed -i'' -e 's@imagePullPolicy: .*@imagePullPolicy: '"$(PULL_POLICY)"'@' ./config/default/manager_pull_policy.yaml - -## -------------------------------------- -## Release -## -------------------------------------- - -RELEASE_TAG ?= $(shell git describe --abbrev=0 2>/dev/null) -RELEASE_ALIAS_TAG ?= $(PULL_BASE_REF) -RELEASE_DIR := out - -$(RELEASE_DIR): - mkdir -p $(RELEASE_DIR)/ - -.PHONY: release -release: clean-release ## Builds and push container images using the latest git tag for the commit. - @if [ -z "${RELEASE_TAG}" ]; then echo "RELEASE_TAG is not set"; exit 1; fi - @if ! [ -z "$$(git status --porcelain)" ]; then echo "Your local git repository contains uncommitted changes, use git clean before proceeding."; exit 1; fi - git checkout "${RELEASE_TAG}" - # Set the manifest image to the staging bucket. - REGISTRY=$(STAGING_REGISTRY) $(MAKE) manifest-modification - $(MAKE) release-manifests - -.PHONY: manifest-modification -manifest-modification: # Set the manifest images to the staging/production bucket. - $(MAKE) set-manifest-image MANIFEST_IMG=$(REGISTRY)/$(IMAGE_NAME) MANIFEST_TAG=$(RELEASE_TAG) - PULL_POLICY=IfNotPresent $(MAKE) set-manifest-pull-policy - -.PHONY: release-manifests -release-manifests: $(RELEASE_DIR) $(KUSTOMIZE)## Builds the manifests to publish with a release - $(KUSTOMIZE) build config/default > $(RELEASE_DIR)/infrastructure-components.yaml - -.PHONY: release-staging -release-staging: ## Builds and push container images to the staging bucket. - REGISTRY=$(STAGING_REGISTRY) $(MAKE) docker-build-all docker-push-all release-alias-tag - -.PHONY: release-staging-nightly -release-staging-nightly: ## Tags and push container images to the staging bucket. Example image tag: cluster-api-controller:nightly_main_20210121 - $(eval NEW_RELEASE_ALIAS_TAG := nightly_$(RELEASE_ALIAS_TAG)_$(shell date +'%Y%m%d')) - $(MAKE) release-alias-tag TAG=$(RELEASE_ALIAS_TAG) RELEASE_ALIAS_TAG=$(NEW_RELEASE_ALIAS_TAG) - # Set the manifest image to the production bucket. - $(MAKE) manifest-modification REGISTRY=$(STAGING_REGISTRY) RELEASE_TAG=$(NEW_RELEASE_ALIAS_TAG) - ## Build the manifests - $(MAKE) release-manifests - # Example manifest location: artifacts.k8s-staging-cluster-api.appspot.com/components/nightly_main_20210121/infrastructure-components.yaml - gsutil cp $(RELEASE_DIR)/* gs://$(STAGING_BUCKET)/components/$(NEW_RELEASE_ALIAS_TAG) - -.PHONY: release-alias-tag -release-alias-tag: # Adds the tag to the last build tag. - gcloud container images add-tag $(CONTROLLER_IMG):$(TAG) $(CONTROLLER_IMG):$(RELEASE_ALIAS_TAG) - -## -------------------------------------- -## Cleanup / Verification -## -------------------------------------- - -.PHONY: clean -clean: ## Remove all generated files - $(MAKE) clean-bin - -.PHONY: clean-bin -clean-bin: ## Remove all generated binaries - rm -rf bin - rm -rf hack/tools/bin - -.PHONY: clean-release -clean-release: ## Remove the release folder - rm -rf $(RELEASE_DIR) - -.PHONY: verify -verify: - ./hack/verify-all.sh - $(MAKE) verify-gen - -.PHONY: verify-gen -verify-gen: generate - @if !(git diff --quiet HEAD); then \ - git diff; \ - echo "generated files are out of date, run make generate"; exit 1; \ - fi diff --git a/test/infrastructure/docker/README.md b/test/infrastructure/docker/README.md index 48bd2e7f80f8..55ded11651b3 100644 --- a/test/infrastructure/docker/README.md +++ b/test/infrastructure/docker/README.md @@ -17,7 +17,7 @@ For a complete overview, please refer to the documentation available [here](http ## Testing In order to test your local changes, go to the top level directory of this project, `cluster-api/` and run -`make -C test/infrastructure/docker test` to run the unit tests. +`make test-capd` to run the unit tests. **Note:** `make test-e2e` runs the CAPI E2E tests that are based on CAPD (CAPD does not have a separated e2e suite). diff --git a/test/infrastructure/docker/hack/verify-all.sh b/test/infrastructure/docker/hack/verify-all.sh deleted file mode 100755 index 07c6d71814a4..000000000000 --- a/test/infrastructure/docker/hack/verify-all.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2019 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. - -set -o nounset -set -o pipefail - -# shellcheck source=./hack/utils.sh -source "$(git rev-parse --show-toplevel)/hack/utils.sh" - -# set REPO_PATH -readonly REPO_PATH=$(get_capd_root_path) -cd "${REPO_PATH}" || exit - -failure() { - if [[ "${1}" != 0 ]]; then - res=1 - failed+=("${2}") - outputs+=("${3}") - fi -} - -# exit code, if a script fails we'll set this to 1 -res=0 -failed=() -outputs=() - -# run all verify scripts, optionally skipping any of them -if [[ "${VERIFY_BUILD:-true}" == "true" ]]; then - echo "[*] Verifying build..." - out=$(hack/verify-build.sh 2>&1) - failure $? "verify-build.sh" "${out}" - cd "${REPO_PATH}" || exit -fi - -# exit based on verify scripts -if [[ "${res}" = 0 ]]; then - echo "" - echo "All verify checks passed, congrats!" -else - echo "" - echo "Some of the verify scripts failed:" - for i in "${!failed[@]}"; do - echo "- ${failed[$i]}:" - echo "${outputs[$i]}" - echo - done -fi -exit "${res}" diff --git a/test/infrastructure/docker/hack/verify-build.sh b/test/infrastructure/docker/hack/verify-build.sh deleted file mode 100755 index a61915e032fd..000000000000 --- a/test/infrastructure/docker/hack/verify-build.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2019 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. - -set -o errexit -set -o nounset -set -o pipefail - -# shellcheck source=./hack/utils.sh -source "$(git rev-parse --show-toplevel)/hack/utils.sh" - -# check if the code builds -cd_capd_root_path -export GO111MODULE=on -go build ./...