From 8e8f07ad4add0ee0e9dde07b5b2c251798e26925 Mon Sep 17 00:00:00 2001 From: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> Date: Tue, 29 Mar 2022 10:05:17 +0200 Subject: [PATCH] Using setup-envtest to install kubebuilder dependency --- Makefile | 33 ++++++++--- hack/tools/go.mod | 5 ++ hack/tools/go.sum | 7 +++ hack/tools/tools.go | 1 + scripts/ci-test.sh | 6 +- scripts/fetch_ext_bins.sh | 113 -------------------------------------- scripts/go_install.sh | 45 +++++++++++++++ 7 files changed, 84 insertions(+), 126 deletions(-) delete mode 100755 scripts/fetch_ext_bins.sh create mode 100755 scripts/go_install.sh diff --git a/Makefile b/Makefile index e6eb4b7cd8..aca59b0371 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,7 @@ ARTIFACTS ?= $(REPO_ROOT)/_artifacts TOOLS_DIR := hack/tools TOOLS_DIR_DEPS := $(TOOLS_DIR)/go.sum $(TOOLS_DIR)/go.mod $(TOOLS_DIR)/Makefile TOOLS_BIN_DIR := $(TOOLS_DIR)/bin +GO_INSTALL := ./scripts/go_install.sh API_DIRS := cmd/clusterawsadm/api api exp/api controlplane/eks/api bootstrap/eks/api iam/api API_SRCS := $(foreach dir, $(API_DIRS), $(call rwildcard,../../$(dir),*.go)) @@ -129,6 +130,19 @@ E2E_SKIP_EKS_UPGRADE ?= "false" # Set EKS_SOURCE_TEMPLATE to override the source template EKS_SOURCE_TEMPLATE ?= eks/cluster-template-eks-control-plane-only.yaml +# set up `setup-envtest` to install kubebuilder dependency +export KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.23.3 +SETUP_ENVTEST_VER := v0.0.0-20211110210527-619e6b92dab9 +SETUP_ENVTEST_BIN := setup-envtest +SETUP_ENVTEST := $(abspath $(TOOLS_BIN_DIR)/$(SETUP_ENVTEST_BIN)-$(SETUP_ENVTEST_VER)) +SETUP_ENVTEST_PKG := sigs.k8s.io/controller-runtime/tools/setup-envtest + +ifeq ($(shell go env GOOS),darwin) # Use the darwin/amd64 binary until an arm64 version is available + KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use --use-env -p path --arch amd64 $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION)) +else + KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use --use-env -p path $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION)) +endif + # Enable Cluster API Framework tests for the purposes of running the PR blocking test ifeq ($(findstring \[PR-Blocking\],$(E2E_FOCUS)),\[PR-Blocking\]) override undefine GINKGO_SKIP @@ -305,7 +319,7 @@ verify-shellcheck: ## Verify shell files .PHONY: verify-book-links verify-book-links: ## Verify book links - $(MAKE) -C docs/book verify + $(MAKE) -C docs/book verify .PHONY: verify-gen verify-gen: generate ## Verify generated files @@ -366,13 +380,16 @@ generate-test-flavors: $(KUSTOMIZE) ## Generate test template flavors e2e-image: docker-pull-prerequisites $(TOOLS_BIN_DIR)/start.sh $(TOOLS_BIN_DIR)/restart.sh ## Build an e2e test image docker build -f Dockerfile --tag="gcr.io/k8s-staging-cluster-api/capa-manager:e2e" . +$(SETUP_ENVTEST): # Build setup-envtest from tools folder. + GOBIN=$(abspath $(TOOLS_BIN_DIR)) $(GO_INSTALL) $(SETUP_ENVTEST_PKG) $(SETUP_ENVTEST_BIN) $(SETUP_ENVTEST_VER) + .PHONY: test -test: ## Run tests - source ./scripts/fetch_ext_bins.sh; fetch_tools; setup_envs; go test ./... +test: $(SETUP_ENVTEST) ## Run tests + KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test ./... .PHONY: test-verbose -test-verbose: ## Run tests with verbose settings. - source ./scripts/fetch_ext_bins.sh; fetch_tools; setup_envs; go test -v ./... +test-verbose: $(SETUP_ENVTEST) ## Run tests with verbose settings. + KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test -v ./... .PHONY: test-e2e ## Run e2e tests using clusterctl test-e2e: $(GINKGO) $(KIND) $(SSM_PLUGIN) $(KUSTOMIZE) generate-test-flavors e2e-image ## Run e2e tests @@ -391,8 +408,8 @@ test-conformance: generate-test-flavors $(GINKGO) $(KIND) $(SSM_PLUGIN) $(KUSTOM time $(GINKGO) -tags=e2e -focus="conformance" $(CONFORMANCE_GINKGO_ARGS) ./test/e2e/suites/conformance/... -- -config-path="$(E2E_CONF_PATH)" $(CONFORMANCE_E2E_ARGS) .PHONY: test-cover -test-cover: ## Run tests with code coverage and code generate reports - source ./scripts/fetch_ext_bins.sh; fetch_tools; setup_envs; go test -coverprofile=coverage.out ./... $(TEST_ARGS) +test-cover: $(SETUP_ENVTEST) ## Run tests with code coverage and code generate reports + KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test -coverprofile=coverage.out ./... $(TEST_ARGS) go tool cover -func=coverage.out -o coverage.txt go tool cover -html=coverage.out -o coverage.html @@ -533,7 +550,7 @@ release-manifests: ## Release manifest files .PHONY: release-changelog release-changelog: $(GH) ## Generates release notes using Github release notes. ./hack/releasechangelog.sh -v $(VERSION) -pv $(PREVIOUS_VERSION) -gh $(GH) -ghorg $(GH_ORG_NAME) -ghrepo $(GH_REPO_NAME) -cimg $(CORE_CONTROLLER_IMG) > $(RELEASE_DIR)/CHANGELOG.md - + .PHONY: release-binaries release-binaries: ## Builds the binaries to publish with a release RELEASE_BINARY=./cmd/clusterawsadm GOOS=linux GOARCH=amd64 $(MAKE) release-binary diff --git a/hack/tools/go.mod b/hack/tools/go.mod index 44e564e5e4..fea73d0b11 100644 --- a/hack/tools/go.mod +++ b/hack/tools/go.mod @@ -16,6 +16,7 @@ require ( k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c k8s.io/klog/v2 v2.60.1 sigs.k8s.io/cluster-api/hack/tools v0.0.0-20211111175208-4cc2fce2111a + sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20211110210527-619e6b92dab9 sigs.k8s.io/controller-tools v0.7.1-0.20211110210727-ab52f76cc7d1 sigs.k8s.io/kind v0.12.0 sigs.k8s.io/kustomize/kustomize/v4 v4.5.3 @@ -70,6 +71,7 @@ require ( github.com/go-git/go-billy/v5 v5.3.1 // indirect github.com/go-git/go-git/v5 v5.4.2 // indirect github.com/go-logr/logr v1.2.0 // indirect + github.com/go-logr/zapr v1.2.0 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonreference v0.19.5 // indirect github.com/go-openapi/swag v0.19.14 // indirect @@ -200,6 +202,9 @@ require ( github.com/yeya24/promlinter v0.1.1-0.20210918184747-d757024714a1 // indirect gitlab.com/bosi/decorder v0.2.1 // indirect go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect + go.uber.org/atomic v1.7.0 // indirect + go.uber.org/multierr v1.6.0 // indirect + go.uber.org/zap v1.19.1 // indirect golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect golang.org/x/exp v0.0.0-20211029160041-3396431c207b // indirect golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect diff --git a/hack/tools/go.sum b/hack/tools/go.sum index e690b210ec..7f4a3fea96 100644 --- a/hack/tools/go.sum +++ b/hack/tools/go.sum @@ -150,6 +150,7 @@ github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN github.com/aws/aws-sdk-go v1.36.30/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM= +github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= @@ -332,6 +333,7 @@ github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTg github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= github.com/go-logr/logr v1.2.0 h1:QK40JKJyMdUDz+h+xvCsru/bJhvG0UxvePV0ufL/AcE= github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/zapr v1.2.0 h1:n4JnPI1T3Qq1SFEi/F8rwLrZERp2bso19PJZDB9dayk= github.com/go-logr/zapr v1.2.0/go.mod h1:Qa4Bsj2Vb+FAVeAKsLD8RLQ+YRJB8YDmOAKxaBQf7Ro= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= @@ -1180,13 +1182,16 @@ go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= +go.uber.org/goleak v1.1.11-0.20210813005559-691160354723 h1:sHOAIxRGBp443oHZIPB+HsUGaksVCXVQENPxwTfQdH4= go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/multierr v1.4.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= +go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= @@ -1194,6 +1199,7 @@ go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ= go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= +go.uber.org/zap v1.19.1 h1:ue41HOKd1vGURxrmeKIgELGb3jPW9DMUDGtsinblHwI= go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI= golang.org/x/crypto v0.0.0-20180501155221-613d6eafa307/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -1869,6 +1875,7 @@ rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.23/go.mod h1:LEScyzhFmoF5pso/YSeBstl57mOzx9xlU9n85RGrDQg= sigs.k8s.io/cluster-api/hack/tools v0.0.0-20211111175208-4cc2fce2111a h1:VrYPmq0nN1VQuhid22yD9Z5Hn+M6p/N0f0dCkuM5C2s= sigs.k8s.io/cluster-api/hack/tools v0.0.0-20211111175208-4cc2fce2111a/go.mod h1:Bib3nYZoRjwPdZ1+X1MVRWcQL18dJ4q2U+Ok603lcAE= +sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20211110210527-619e6b92dab9 h1:ylYUI5uaq/guUFerFRVG81FHSA5/3+fERCE1RQbQUZ4= sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20211110210527-619e6b92dab9/go.mod h1:+sJcI1F0QI0Cv+8fp5rH5B2fK1LxzrAQqYnaPx9nY8I= sigs.k8s.io/controller-tools v0.7.1-0.20211110210727-ab52f76cc7d1 h1:fsnXNyvliKAKkcOZ5l9gGinGqjGM8eKKT+4TW/LoI7A= sigs.k8s.io/controller-tools v0.7.1-0.20211110210727-ab52f76cc7d1/go.mod h1:h59umkqeBKj3TNpLmLoqDCwXDcbN+mkhQzlNjoUDJ3I= diff --git a/hack/tools/tools.go b/hack/tools/tools.go index 2efdd0db29..4f6687cd28 100644 --- a/hack/tools/tools.go +++ b/hack/tools/tools.go @@ -36,6 +36,7 @@ import ( _ "sigs.k8s.io/cluster-api/hack/tools/conversion-verifier" _ "sigs.k8s.io/cluster-api/hack/tools/mdbook/embed" _ "sigs.k8s.io/cluster-api/hack/tools/mdbook/releaselink" + _ "sigs.k8s.io/controller-runtime/tools/setup-envtest" _ "sigs.k8s.io/controller-tools/cmd/controller-gen" _ "sigs.k8s.io/kind" _ "sigs.k8s.io/kustomize/kustomize/v4" diff --git a/scripts/ci-test.sh b/scripts/ci-test.sh index d8ecbde710..bcc70bdb7c 100755 --- a/scripts/ci-test.sh +++ b/scripts/ci-test.sh @@ -22,8 +22,4 @@ REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. # shellcheck source=../hack/ensure-go.sh source "${REPO_ROOT}/hack/ensure-go.sh" -cd "${REPO_ROOT}" && - source ./scripts/fetch_ext_bins.sh && - fetch_tools && - setup_envs && - make lint test-verbose +cd "${REPO_ROOT}" && make lint test-verbose diff --git a/scripts/fetch_ext_bins.sh b/scripts/fetch_ext_bins.sh deleted file mode 100755 index 476ee40426..0000000000 --- a/scripts/fetch_ext_bins.sh +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/env bash -# 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. - -set -o errexit -set -o nounset -set -o pipefail - -# Enable tracing in this script off by setting the TRACE variable in your -# environment to any value: -# -# $ TRACE=1 test.sh -TRACE=${TRACE:-""} -if [[ -n "${TRACE}" ]]; then - set -x -fi - -k8s_version=1.19.2 -goarch=amd64 -goos="unknown" - -if [[ "${OSTYPE}" == "linux"* ]]; then - goos="linux" -elif [[ "${OSTYPE}" == "darwin"* ]]; then - goos="darwin" -fi - -if [[ "$goos" == "unknown" ]]; then - echo "OS '$OSTYPE' not supported. Aborting." >&2 - exit 1 -fi - -# Turn colors in this script off by setting the NO_COLOR variable in your -# environment to any value: -# -# $ NO_COLOR=1 test.sh -NO_COLOR=${NO_COLOR:-""} -if [[ -z "${NO_COLOR}" ]]; then - header=$'\e[1;33m' - reset=$'\e[0m' -else - header='' - reset='' -fi - -function header_text { - echo "$header$*$reset" -} - -tmp_root=/tmp - -kb_root_dir=${tmp_root}/kubebuilder - -# Skip fetching and untaring the tools by setting the SKIP_FETCH_TOOLS variable -# in your environment to any value: -# -# $ SKIP_FETCH_TOOLS=1 ./fetch_ext_bins.sh -# -# If you skip fetching tools, this script will use the tools already on your -# machine, but rebuild the kubebuilder and kubebuilder-bin binaries. -SKIP_FETCH_TOOLS=${SKIP_FETCH_TOOLS:-""} - -function prepare_staging_dir { - header_text "preparing staging dir" - - if [[ -z "${SKIP_FETCH_TOOLS}" ]]; then - rm -rf "${kb_root_dir}" - else - rm -f "${kb_root_dir}/kubebuilder/bin/kubebuilder" - rm -f "${kb_root_dir}/kubebuilder/bin/kubebuilder-gen" - rm -f "${kb_root_dir}/kubebuilder/bin/vendor.tar.gz" - fi -} - -# fetch k8s API gen tools and make it available under kb_root_dir/bin. -function fetch_tools { - if [[ -n "$SKIP_FETCH_TOOLS" ]]; then - return 0 - fi - - header_text "fetching tools" - kb_tools_archive_name="kubebuilder-tools-${k8s_version}-${goos}-${goarch}.tar.gz" - kb_tools_download_url="https://storage.googleapis.com/kubebuilder-tools/${kb_tools_archive_name}" - - kb_tools_archive_path="${tmp_root}/${kb_tools_archive_name}" - if [[ ! -f ${kb_tools_archive_path} ]]; then - echo ${kb_tools_download_url} - curl -fsL ${kb_tools_download_url} -o "${kb_tools_archive_path}" - - fi - tar -zvxf "${kb_tools_archive_path}" -C "${tmp_root}/" -} - -function setup_envs { - header_text "setting up env vars" - - # Setup env vars - export PATH=/tmp/kubebuilder/bin:$PATH - export TEST_ASSET_KUBECTL=/tmp/kubebuilder/bin/kubectl - export TEST_ASSET_KUBE_APISERVER=/tmp/kubebuilder/bin/kube-apiserver - export TEST_ASSET_ETCD=/tmp/kubebuilder/bin/etcd -} diff --git a/scripts/go_install.sh b/scripts/go_install.sh new file mode 100755 index 0000000000..415e06d801 --- /dev/null +++ b/scripts/go_install.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# 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. + +set -o errexit +set -o nounset +set -o pipefail + +if [ -z "${1}" ]; then + echo "must provide module as first parameter" + exit 1 +fi + +if [ -z "${2}" ]; then + echo "must provide binary name as second parameter" + exit 1 +fi + +if [ -z "${3}" ]; then + echo "must provide version as third parameter" + exit 1 +fi + +if [ -z "${GOBIN}" ]; then + echo "GOBIN is not set. Must set GOBIN to install the bin in a specified directory." + exit 1 +fi + +rm "${GOBIN}/${2}"* || true + +# install the golang module specified as the first argument +go install -tags tools "${1}@${3}" +mv "${GOBIN}/${2}" "${GOBIN}/${2}-${3}" +ln -sf "${GOBIN}/${2}-${3}" "${GOBIN}/${2}"