From ebd8ccc6bba982e556794a56ccd380d513037fc5 Mon Sep 17 00:00:00 2001 From: Stephen Augustus Date: Wed, 2 Sep 2020 19:47:58 -0400 Subject: [PATCH 1/9] [go1.15] build: Update to k/repo-infra@v0.1.1 (supports go1.15.2) Signed-off-by: Stephen Augustus --- build/dependencies.yaml | 2 +- build/root/WORKSPACE | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/dependencies.yaml b/build/dependencies.yaml index 8735a29e2e7..9a4a8763cae 100644 --- a/build/dependencies.yaml +++ b/build/dependencies.yaml @@ -17,7 +17,7 @@ dependencies: # Bazel - name: "repo-infra" - version: 0.0.12 + version: 0.1.1 refPaths: - path: build/root/WORKSPACE match: strip_prefix = "repo-infra-\d+.\d+.\d+" diff --git a/build/root/WORKSPACE b/build/root/WORKSPACE index 4cc85d2a3eb..6f4832aa3a7 100644 --- a/build/root/WORKSPACE +++ b/build/root/WORKSPACE @@ -5,10 +5,10 @@ load("//build:workspace_mirror.bzl", "mirror") http_archive( name = "io_k8s_repo_infra", - strip_prefix = "repo-infra-0.0.12", - sha256 = "e309a655a5b04fd76b6e950b3371aa8636bb929f2860a7ec22fa9b4b0b7c8236", + strip_prefix = "repo-infra-0.1.1", + sha256 = "6c916da43b701e2947f147f3791b3355d8a342dd6cb81887b7d6db184879e387", urls = [ - "https://github.com/kubernetes/repo-infra/archive/v0.0.12.tar.gz", + "https://github.com/kubernetes/repo-infra/archive/v0.1.1.tar.gz", ], ) From 01a0c45f4aed5dad94240145ed29f116cfcb33fe Mon Sep 17 00:00:00 2001 From: Stephen Augustus Date: Wed, 2 Sep 2020 19:50:34 -0400 Subject: [PATCH 2/9] [go1.15] hack/tools: Update to k/repo-infra@v0.1.1 (supports go1.15.2) Signed-off-by: Stephen Augustus --- hack/tools/go.mod | 2 +- hack/tools/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hack/tools/go.mod b/hack/tools/go.mod index 1aec012d221..c73aa3174da 100644 --- a/hack/tools/go.mod +++ b/hack/tools/go.mod @@ -11,5 +11,5 @@ require ( gotest.tools v2.2.0+incompatible gotest.tools/gotestsum v0.3.5 honnef.co/go/tools v0.0.1-2020.1.4 - k8s.io/repo-infra v0.0.12 + k8s.io/repo-infra v0.1.1 ) diff --git a/hack/tools/go.sum b/hack/tools/go.sum index 9911d6e8ac4..57d0c07dcf3 100644 --- a/hack/tools/go.sum +++ b/hack/tools/go.sum @@ -708,8 +708,8 @@ honnef.co/go/tools v0.0.1-2020.1.4 h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= k8s.io/klog/v2 v2.3.0 h1:WmkrnW7fdrm0/DMClc+HIxtftvxVIPAhlVwMQo5yLco= k8s.io/klog/v2 v2.3.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= -k8s.io/repo-infra v0.0.12 h1:i5NvQE7KU7Ky/YkJZPLZJKBDTNgf4ncNXz17XC8uZIE= -k8s.io/repo-infra v0.0.12/go.mod h1:WfvjbUCy0f1fsyHq6sF825VYMfAh9pQdkYCa35OZRJc= +k8s.io/repo-infra v0.1.1 h1:gGVxusj+TfqEQmLQGg3bzhpQlHrB0RSVM94HyU7Jg9I= +k8s.io/repo-infra v0.1.1/go.mod h1:WfvjbUCy0f1fsyHq6sF825VYMfAh9pQdkYCa35OZRJc= mvdan.cc/gofumpt v0.0.0-20200709182408-4fd085cb6d5f/go.mod h1:9VQ397fNXEnF84t90W4r4TRCQK+pg9f8ugVfyj+S26w= mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed h1:WX1yoOaKQfddO/mLzdV4wptyWgoH/6hwLs7QHTixo0I= mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc= From a4a98f440cea4fea7751f7eee377350a72669426 Mon Sep 17 00:00:00 2001 From: Stephen Augustus Date: Wed, 2 Sep 2020 17:59:40 -0400 Subject: [PATCH 3/9] [go1.15] Update to go1.15.2 Signed-off-by: Stephen Augustus --- build/build-image/cross/VERSION | 2 +- build/dependencies.yaml | 4 ++-- build/root/WORKSPACE | 2 +- test/images/Makefile | 2 +- test/images/sample-apiserver/Dockerfile | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build/build-image/cross/VERSION b/build/build-image/cross/VERSION index c2f3f74f20d..eb2573a06ea 100644 --- a/build/build-image/cross/VERSION +++ b/build/build-image/cross/VERSION @@ -1 +1 @@ -v1.15.0-1 +v1.15.2-1 diff --git a/build/dependencies.yaml b/build/dependencies.yaml index 9a4a8763cae..1ba43a61bf7 100644 --- a/build/dependencies.yaml +++ b/build/dependencies.yaml @@ -99,7 +99,7 @@ dependencies: # Golang - name: "golang: upstream version" - version: 1.15 + version: 1.15.2 refPaths: - path: build/build-image/cross/VERSION - path: build/root/WORKSPACE @@ -108,7 +108,7 @@ dependencies: match: GOLANG_VERSION=\d+.\d+(alpha|beta|rc)?\.?\d+ - name: "k8s.gcr.io/kube-cross: dependents" - version: v1.15.0-1 + version: v1.15.2-1 refPaths: - path: build/build-image/cross/VERSION - path: test/images/sample-apiserver/Dockerfile diff --git a/build/root/WORKSPACE b/build/root/WORKSPACE index 6f4832aa3a7..a21731eaf3d 100644 --- a/build/root/WORKSPACE +++ b/build/root/WORKSPACE @@ -23,7 +23,7 @@ load("@io_k8s_repo_infra//:repos.bzl", repo_infra_configure = "configure", repo_ # 'override_go_version': used to specify an alternate go version provided # by kubernetes/repo-infra repo_infra_configure( - go_version = "1.15", + go_version = "1.15.2", minimum_bazel_version = "2.2.0", ) diff --git a/test/images/Makefile b/test/images/Makefile index 6dd1ef8260e..7b9981cb19e 100644 --- a/test/images/Makefile +++ b/test/images/Makefile @@ -16,7 +16,7 @@ REGISTRY ?= gcr.io/kubernetes-e2e-test-images GOARM ?= 7 DOCKER_CERT_BASE_PATH ?= QEMUVERSION=v2.9.1 -GOLANG_VERSION=1.15.0 +GOLANG_VERSION=1.15.2 export ifndef WHAT diff --git a/test/images/sample-apiserver/Dockerfile b/test/images/sample-apiserver/Dockerfile index a1c3fa69ca6..dbec210d46d 100644 --- a/test/images/sample-apiserver/Dockerfile +++ b/test/images/sample-apiserver/Dockerfile @@ -13,7 +13,7 @@ # limitations under the License. ARG BASEIMAGE -FROM k8s.gcr.io/build-image/kube-cross:v1.15.0-1 as build_k8s_1_17_sample_apiserver +FROM k8s.gcr.io/build-image/kube-cross:v1.15.2-1 as build_k8s_1_17_sample_apiserver ENV GOPATH /go RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin From eb61cf27fe1a6832f8c79065c3b05220cd605efb Mon Sep 17 00:00:00 2001 From: Stephen Augustus Date: Wed, 2 Sep 2020 22:18:35 -0400 Subject: [PATCH 4/9] [go1.15] build: Use go-runner:buster-v2.0.1 (built using go1.15.1) Signed-off-by: Stephen Augustus --- build/common.sh | 2 +- build/dependencies.yaml | 2 +- build/workspace.bzl | 18 +++++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build/common.sh b/build/common.sh index 39b297e93cd..db4125b8f92 100755 --- a/build/common.sh +++ b/build/common.sh @@ -94,7 +94,7 @@ readonly KUBE_CONTAINER_RSYNC_PORT=8730 # $1 - server architecture kube::build::get_docker_wrapped_binaries() { local debian_iptables_version=v12.1.2 - local go_runner_version=buster-v2.0.0 + local go_runner_version=buster-v2.0.1 ### If you change any of these lists, please also update DOCKERIZED_BINARIES ### in build/BUILD. And kube::golang::server_image_targets local targets=( diff --git a/build/dependencies.yaml b/build/dependencies.yaml index 1ba43a61bf7..3c6cc2a2e0e 100644 --- a/build/dependencies.yaml +++ b/build/dependencies.yaml @@ -142,7 +142,7 @@ dependencies: match: configs\[DebianIptables\] = Config{buildImageRegistry, "debian-iptables", "v\d+\.\d+.\d+"} - name: "k8s.gcr.io/go-runner: dependents" - version: buster-v2.0.0 + version: buster-v2.0.1 refPaths: - path: build/common.sh match: go_runner_version= diff --git a/build/workspace.bzl b/build/workspace.bzl index 642c49d92a7..82bbe15505d 100644 --- a/build/workspace.bzl +++ b/build/workspace.bzl @@ -102,15 +102,15 @@ _DEBIAN_IPTABLES_DIGEST = { # Use skopeo to find these values: https://github.com/containers/skopeo # # Example -# Manifest: skopeo inspect docker://gcr.io/k8s-staging-build-image/go-runner:buster-v2.0.0 -# Arches: skopeo inspect --raw docker://gcr.io/k8s-staging-build-image/go-runner:buster-v2.0.0 +# Manifest: skopeo inspect docker://gcr.io/k8s-staging-build-image/go-runner:buster-v2.0.1 +# Arches: skopeo inspect --raw docker://gcr.io/k8s-staging-build-image/go-runner:buster-v2.0.1 _GO_RUNNER_DIGEST = { - "manifest": "sha256:ff6e2f3683e7d284674ed18341fc898060204e8c43c9b477e13c6f7faf3e66d4", - "amd64": "sha256:140404aed601b95a2a0a1aeac0608a0fdbd5fc339a8ea6b2ee4a63c7e1f56415", - "arm": "sha256:5d4e8c77bc472610e7e46bbd2b83e167e243434b8287ba2ffe6b09aba9f08ecc", - "arm64": "sha256:62429a05973522064480deb44134e3ca355ee89c7781f3fc3ee9072f17de0085", - "ppc64le": "sha256:05c8575486ccea90c35e8d8ba28c84aee57a03d58329b1354cf7193c372d2de2", - "s390x": "sha256:e886ab4557e60293081f2e47a5b52e84bd3d60290a0f46fb99fac6eec35479ec", + "manifest": "sha256:687c17db2f5cd4aea13faa7ae56bee639a5b11f380c431a9800205624f53541c", + "amd64": "sha256:b02bdb3444b1e7fb14cb5b60174f0e8f0a087ff4c294352e6c31c17da99a4ee2", + "arm": "sha256:0d7563c814c0cd88bc5937b6e606d266409b5b7cee2deb6c04c6dcb6d7daaa5d", + "arm64": "sha256:78f42645ddfd2ab9dfc4053834aa0042c82c8c550f9f61a2a76fd9f1791e5308", + "ppc64le": "sha256:93e3ca63df801a5c1ad15bdbb9c50fa38e5db3479a92d8f4516c00dfd736f227", + "s390x": "sha256:d7ed7bd8d58a6570504f14a50d502c2df97f944378f9f5306519f3379cb92fe2", } def _digest(d, arch): @@ -127,7 +127,7 @@ def image_dependencies(): digest = _digest(_GO_RUNNER_DIGEST, arch), registry = "k8s.gcr.io/build-image", repository = "go-runner", - tag = "buster-v2.0.0", # ignored, but kept here for documentation + tag = "buster-v2.0.1", # ignored, but kept here for documentation ) container_pull( From 2ff22026d5c86ed92d65b15c412fc414c3b631a8 Mon Sep 17 00:00:00 2001 From: Stephen Augustus Date: Wed, 2 Sep 2020 22:23:20 -0400 Subject: [PATCH 5/9] [go1.15] staging/publishing: Set default go version to go1.15.2 Signed-off-by: Stephen Augustus --- build/dependencies.yaml | 2 ++ staging/publishing/rules.yaml | 50 +++++++++++++++++------------------ 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/build/dependencies.yaml b/build/dependencies.yaml index 3c6cc2a2e0e..fd63d4b1a09 100644 --- a/build/dependencies.yaml +++ b/build/dependencies.yaml @@ -106,6 +106,8 @@ dependencies: match: (override_)?go_version = "\d+.\d+(alpha|beta|rc)?\.?\d+" - path: test/images/Makefile match: GOLANG_VERSION=\d+.\d+(alpha|beta|rc)?\.?\d+ + - path: staging/publishing/rules.yaml + match: 'default-go-version\: \d+.\d+(alpha|beta|rc)?\.?(\d+)?' - name: "k8s.gcr.io/kube-cross: dependents" version: v1.15.2-1 diff --git a/staging/publishing/rules.yaml b/staging/publishing/rules.yaml index d07711ae7e0..248a2ea2107 100644 --- a/staging/publishing/rules.yaml +++ b/staging/publishing/rules.yaml @@ -4,7 +4,7 @@ recursive-delete-patterns: - BUILD.bazel - "*/BUILD.bazel" - Gopkg.toml -default-go-version: 1.15 +default-go-version: 1.15.2 rules: - destination: code-generator branches: @@ -31,7 +31,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/code-generator name: release-1.19 - go: 1.15 + go: 1.15.2 - destination: apimachinery library: true @@ -59,7 +59,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/apimachinery name: release-1.19 - go: 1.15 + go: 1.15.2 - destination: api library: true @@ -99,7 +99,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/api name: release-1.19 - go: 1.15 + go: 1.15.2 dependencies: - repository: apimachinery branch: release-1.19 @@ -150,7 +150,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/client-go name: release-1.19 - go: 1.15 + go: 1.15.2 dependencies: - repository: apimachinery branch: release-1.19 @@ -215,7 +215,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/component-base name: release-1.19 - go: 1.15 + go: 1.15.2 dependencies: - repository: apimachinery branch: release-1.19 @@ -286,7 +286,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/apiserver name: release-1.19 - go: 1.15 + go: 1.15.2 dependencies: - repository: apimachinery branch: release-1.19 @@ -374,7 +374,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/kube-aggregator name: release-1.19 - go: 1.15 + go: 1.15.2 dependencies: - repository: apimachinery branch: release-1.19 @@ -474,7 +474,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/sample-apiserver name: release-1.19 - go: 1.15 + go: 1.15.2 dependencies: - repository: apimachinery branch: release-1.19 @@ -563,7 +563,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/sample-controller name: release-1.19 - go: 1.15 + go: 1.15.2 dependencies: - repository: apimachinery branch: release-1.19 @@ -664,7 +664,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/apiextensions-apiserver name: release-1.19 - go: 1.15 + go: 1.15.2 dependencies: - repository: apimachinery branch: release-1.19 @@ -743,7 +743,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/metrics name: release-1.19 - go: 1.15 + go: 1.15.2 dependencies: - repository: apimachinery branch: release-1.19 @@ -808,7 +808,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/cli-runtime name: release-1.19 - go: 1.15 + go: 1.15.2 dependencies: - repository: api branch: release-1.19 @@ -879,7 +879,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/sample-cli-plugin name: release-1.19 - go: 1.15 + go: 1.15.2 dependencies: - repository: api branch: release-1.19 @@ -952,7 +952,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/kube-proxy name: release-1.19 - go: 1.15 + go: 1.15.2 dependencies: - repository: apimachinery branch: release-1.19 @@ -1013,7 +1013,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/kubelet name: release-1.19 - go: 1.15 + go: 1.15.2 dependencies: - repository: apimachinery branch: release-1.19 @@ -1086,7 +1086,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/kube-scheduler name: release-1.19 - go: 1.15 + go: 1.15.2 dependencies: - repository: apimachinery branch: release-1.19 @@ -1159,7 +1159,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/kube-controller-manager name: release-1.19 - go: 1.15 + go: 1.15.2 dependencies: - repository: apimachinery branch: release-1.19 @@ -1216,7 +1216,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/cluster-bootstrap name: release-1.19 - go: 1.15 + go: 1.15.2 dependencies: - repository: apimachinery branch: release-1.19 @@ -1279,7 +1279,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/cloud-provider name: release-1.19 - go: 1.15 + go: 1.15.2 dependencies: - repository: api branch: release-1.19 @@ -1354,7 +1354,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/csi-translation-lib name: release-1.19 - go: 1.15 + go: 1.15.2 dependencies: - repository: api branch: release-1.19 @@ -1453,7 +1453,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/legacy-cloud-providers name: release-1.19 - go: 1.15 + go: 1.15.2 dependencies: - repository: api branch: release-1.19 @@ -1528,7 +1528,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/cri-api name: release-1.19 - go: 1.15 + go: 1.15.2 - destination: kubectl library: true @@ -1616,7 +1616,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/kubectl name: release-1.19 - go: 1.15 + go: 1.15.2 dependencies: - repository: api branch: release-1.19 @@ -1644,7 +1644,7 @@ rules: branch: release-1.19 dir: staging/src/k8s.io/controller-manager name: release-1.19 - go: 1.15 + go: 1.15.2 - destination: mount-utils library: true From bb1855bf117259ad9053f63ceea6dd83f410df71 Mon Sep 17 00:00:00 2001 From: Stephen Augustus Date: Mon, 7 Sep 2020 06:23:42 -0400 Subject: [PATCH 6/9] bazel: Replace --features with Starlark build settings flag All --features and --define flags Deprecated in: 0.23.0 To be removed in: 0.25.0 ref: https://github.com/bazelbuild/rules_go/wiki/Deprecation-schedule Signed-off-by: Stephen Augustus --- build/root/.bazelrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/root/.bazelrc b/build/root/.bazelrc index dc62796681b..9c9d6b79a52 100644 --- a/build/root/.bazelrc +++ b/build/root/.bazelrc @@ -23,8 +23,8 @@ build --define gotags=selinux build --sandbox_fake_username # Enable go race detection. -build:unit --features=race -test:unit --features=race +build:unit --@io_bazel_rules_go//go/config:race +test:unit --@io_bazel_rules_go//go/config:race test:unit --build_tests_only test:unit --test_tag_filters=-e2e,-integration From 5a72bb001f5cd93e0f38beafaa1201028beb9595 Mon Sep 17 00:00:00 2001 From: Mike Danese Date: Thu, 10 Sep 2020 21:21:12 -0700 Subject: [PATCH 7/9] hack/lib/util.sh: some bash cleanups * switched one spot to use kube::logging * make kube::util::find-binary return an error when it doesn't find anything so that hack scripts fail fast instead of with '' binary not found errors. * this required deleting some genfeddoc stuff. the binary no longer exists in k/k repo since we removed federation/, and I don't see it in https://github.com/kubernetes-sigs/kubefed/ either. I'm assuming that it's gone for good now. --- hack/lib/util.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/hack/lib/util.sh b/hack/lib/util.sh index 5c90902d710..dc70ea1f157 100755 --- a/hack/lib/util.sh +++ b/hack/lib/util.sh @@ -223,6 +223,12 @@ kube::util::find-binary-for-platform() { # List most recently-updated location. local -r bin=$( (ls -t "${locations[@]}" 2>/dev/null || true) | head -1 ) + + if [[ -z "${bin}" ]]; then + kube::log::error "Failed to find binary ${lookfor} for platform ${platform}" + return 1 + fi + echo -n "${bin}" } @@ -242,11 +248,6 @@ kube::util::gen-docs() { genkubedocs=$(kube::util::find-binary "genkubedocs") genman=$(kube::util::find-binary "genman") genyaml=$(kube::util::find-binary "genyaml") - genfeddocs=$(kube::util::find-binary "genfeddocs") - - # TODO: If ${genfeddocs} is not used from anywhere (it isn't used at - # least from k/k tree), remove it completely. - kube::util::sourced_variable "${genfeddocs}" mkdir -p "${dest}/docs/user-guide/kubectl/" "${gendocs}" "${dest}/docs/user-guide/kubectl/" @@ -764,7 +765,7 @@ function kube::util::check-file-in-alphabetical-order { # Checks whether jq is installed. function kube::util::require-jq { if ! command -v jq &>/dev/null; then - echo "jq not found. Please install." 1>&2 + kube::log::error "jq not found. Please install." return 1 fi } From d182ecc1f9b198cd2050b3f3aabb9df1a957ee32 Mon Sep 17 00:00:00 2001 From: Mike Danese Date: Wed, 9 Sep 2020 12:05:07 -0700 Subject: [PATCH 8/9] output go_binary rule directly from go_binary_conditional_pure And same for go_test_conditional_pure. Instead of aliasing. Aliases are annoying in a number of ways. This is specifically bugging me now because they make the action graph harder to analyze programmatically. By using aliases here, we would need to handle potentially aliased go_binary targets and dereference to the effective target. The comment references an issue with `pure = select(...)` which appears to be resolved considering this now builds. --- build/BUILD | 4 +- build/go.bzl | 90 +++++++------------------------- cluster/images/conformance/BUILD | 2 +- test/conformance/BUILD | 4 +- 4 files changed, 23 insertions(+), 77 deletions(-) diff --git a/build/BUILD b/build/BUILD index 20793e1f7b9..465e395594b 100644 --- a/build/BUILD +++ b/build/BUILD @@ -155,7 +155,7 @@ filegroup( srcs = select(for_platforms( for_server = [ "//cmd/kubemark", - "//test/e2e_node:e2e_node.test_binary", + "//test/e2e_node:e2e_node.test", ], for_test = [ "//cmd/gendocs", @@ -164,7 +164,7 @@ filegroup( "//cmd/genswaggertypedocs", "//cmd/genyaml", "//cmd/linkcheck", - "//test/e2e:e2e.test_binary", + "//test/e2e:e2e.test", "//vendor/github.com/onsi/ginkgo/ginkgo", "//cluster/images/conformance/go-runner", ], diff --git a/build/go.bzl b/build/go.bzl index 58ce9c101b0..b7b6bbc798b 100644 --- a/build/go.bzl +++ b/build/go.bzl @@ -14,90 +14,36 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_test") -# Defines several go_binary rules to work around a Bazel issue which makes -# the pure attribute on go_binary not configurable. -# The name provided will have cgo enabled if targeting Linux, and will -# be a pure go binary otherwise. Additionally, if targeting Windows, the -# output filename will have a .exe suffix. -def go_binary_conditional_pure(name, tags = None, **kwargs): - tags = tags or [] - tags.append("manual") +# Defines a go_binary rule that enables cgo on platform builds targeting Linux, +# and otherwise builds a pure go binary. +def go_binary_conditional_pure(name, tags = [], **kwargs): go_binary( - name = "_%s-cgo" % name, - out = name, - pure = "off", - tags = tags, - **kwargs - ) - - # Define a rule for both Unix and Windows exe suffixes. - [go_binary( - name = "_%s-pure" % out, - out = out, - pure = "on", - tags = tags, - **kwargs - ) for out in [name, name + ".exe"]] - - # The real magic, where we work around the pure attribute not being - # configurable: select the appropriate go_binary rule above based on the - # configured platform. - native.alias( name = name, - actual = select({ - "@io_bazel_rules_go//go/platform:linux": ":_%s-cgo" % name, - "@io_bazel_rules_go//go/platform:windows": ":_%s.exe-pure" % name, - "//conditions:default": ":_%s-pure" % name, + pure = select({ + "@io_bazel_rules_go//go/platform:linux": "off", + "//conditions:default": "on", }), + tags = ["manual"] + tags, + **kwargs ) -# Defines several go_test rules to work around a Bazel issue which makes -# the pure attribute on go_test not configurable. -# This also defines genrules to produce test binaries named ${out} and -# ${out}.exe, and an alias named ${out}_binary which automatically selects -# the correct filename suffix (i.e. with a .exe on Windows). -def go_test_conditional_pure(name, out, tags = None, **kwargs): - tags = tags or [] +# Defines a go_test rule that enables cgo on platform builds targeting Linux, +# and otherwise builds a pure go binary. +def go_test_conditional_pure(name, out, tags = [], **kwargs): tags.append("manual") go_test( - name = "_%s-cgo" % name, - pure = "off", - testonly = False, - tags = tags, - **kwargs - ) - - go_test( - name = "_%s-pure" % name, - pure = "on", + name = out, + pure = select({ + "@io_bazel_rules_go//go/platform:linux": "off", + "//conditions:default": "on", + }), testonly = False, tags = tags, **kwargs ) native.alias( - name = name, - actual = select({ - "@io_bazel_rules_go//go/platform:linux": ":_%s-cgo" % name, - "//conditions:default": ":_%s-pure" % name, - }), - ) - - [native.genrule( - name = "gen_%s" % o, - srcs = [name], - outs = [o], - cmd = "cp $< $@;", - output_to_bindir = True, - executable = True, - tags = tags, - ) for o in [out, out + ".exe"]] - - native.alias( - name = "%s_binary" % out, - actual = select({ - "@io_bazel_rules_go//go/platform:windows": ":gen_%s.exe" % out, - "//conditions:default": ":gen_%s" % out, - }), + name = "name", + actual = out, ) diff --git a/cluster/images/conformance/BUILD b/cluster/images/conformance/BUILD index b25c140f4e4..9bac3144122 100644 --- a/cluster/images/conformance/BUILD +++ b/cluster/images/conformance/BUILD @@ -15,7 +15,7 @@ container_layer( files = [ "//cluster/images/conformance/go-runner", "//cmd/kubectl", - "//test/e2e:e2e.test_binary", + "//test/e2e:e2e.test", "//vendor/github.com/onsi/ginkgo/ginkgo", ], ) diff --git a/test/conformance/BUILD b/test/conformance/BUILD index b8ec7993333..bb9003038c0 100644 --- a/test/conformance/BUILD +++ b/test/conformance/BUILD @@ -45,11 +45,11 @@ genrule( srcs = [ "//test/e2e:all-srcs", "//test/e2e_node:all-srcs", - "//test/e2e:e2e.test_binary", + "//test/e2e:e2e.test", "//vendor/github.com/onsi/ginkgo/ginkgo", ], outs = ["specsummaries.json"], - cmd = "$(location //vendor/github.com/onsi/ginkgo/ginkgo) --dryRun=true --focus=[Conformance] $(location //test/e2e:e2e.test_binary) -- --spec-dump $$(pwd)/$@ > /dev/null", + cmd = "$(location //vendor/github.com/onsi/ginkgo/ginkgo) --dryRun=true --focus=[Conformance] $(location //test/e2e:e2e.test) -- --spec-dump $$(pwd)/$@ > /dev/null", message = "Getting all conformance spec summaries.", ) From bdadb2a1879672d993b3469d81b19dc35747d9f5 Mon Sep 17 00:00:00 2001 From: Mike Danese Date: Wed, 9 Sep 2020 17:44:05 -0700 Subject: [PATCH 9/9] make kube::util::find-binary not dependent on bazel-out/ structure Implement an aspect that outputs go_build_mode metadata for go binaries, and use that during binary selection. --- build/go.bzl | 64 ++++++++++++++++++++++++++++++++++++++++++++- build/root/.bazelrc | 4 +++ hack/lib/util.sh | 23 +++++++--------- 3 files changed, 77 insertions(+), 14 deletions(-) diff --git a/build/go.bzl b/build/go.bzl index b7b6bbc798b..d0fe3490bd1 100644 --- a/build/go.bzl +++ b/build/go.bzl @@ -12,7 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_test") +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_context", "go_test") +load("@io_bazel_rules_go//go/platform:list.bzl", "GOOS_GOARCH") # Defines a go_binary rule that enables cgo on platform builds targeting Linux, # and otherwise builds a pure go binary. @@ -47,3 +48,64 @@ def go_test_conditional_pure(name, out, tags = [], **kwargs): name = "name", actual = out, ) + +_GO_BUILD_MODE_TMPL = "{goos}/{goarch}/pure={pure},static={static},msan={msan},race={race}\n" + +def _go_build_mode_aspect_impl(target, ctx): + if (not hasattr(ctx.rule.attr, "_is_executable") or + not ctx.rule.attr._is_executable or + ctx.rule.attr.testonly): + # We only care about exporting platform info for executable targets + # that aren't testonly (e.g. kubectl and e2e.test). + return [] + + mode = go_context(ctx).mode + + out = ctx.actions.declare_file( + target.files_to_run.executable.basename + ".go_build_mode", + sibling = target.files_to_run.executable, + ) + ctx.actions.write(out, _GO_BUILD_MODE_TMPL.format( + goos = mode.goos, + goarch = mode.goarch, + pure = str(mode.pure).lower(), + static = str(mode.static).lower(), + msan = str(mode.msan).lower(), + race = str(mode.race).lower(), + )) + + return [OutputGroupInfo(default = depset([out]))] + +# This aspect ouputs a *.go_build_mode metadata for go binaries. This metadata +# is used for executable selection e.g. in CI. +go_build_mode_aspect = aspect( + implementation = _go_build_mode_aspect_impl, + attrs = { + "goos": attr.string( + default = "auto", + values = ["auto"] + {goos: None for goos, _ in GOOS_GOARCH}.keys(), + ), + "goarch": attr.string( + default = "auto", + values = ["auto"] + {goarch: None for _, goarch in GOOS_GOARCH}.keys(), + ), + "pure": attr.string( + default = "auto", + values = ["auto", "on", "off"], + ), + "static": attr.string( + default = "auto", + values = ["auto", "on", "off"], + ), + "msan": attr.string( + default = "auto", + values = ["auto", "on", "off"], + ), + "race": attr.string( + default = "auto", + values = ["auto", "on", "off"], + ), + "_go_context_data": attr.label(default = "@io_bazel_rules_go//:go_context_data"), + }, + toolchains = ["@io_bazel_rules_go//go:toolchain"], +) diff --git a/build/root/.bazelrc b/build/root/.bazelrc index 9c9d6b79a52..d0bcddcd543 100644 --- a/build/root/.bazelrc +++ b/build/root/.bazelrc @@ -22,6 +22,10 @@ build --define gotags=selinux # This flag requires Bazel 0.5.0+ build --sandbox_fake_username +# Output go_build_mode metadata for binaries. This metadata is used for +# executable selection e.g. in CI. +build --aspects //build:go.bzl%go_build_mode_aspect + # Enable go race detection. build:unit --@io_bazel_rules_go//go/config:race test:unit --@io_bazel_rules_go//go/config:race diff --git a/hack/lib/util.sh b/hack/lib/util.sh index dc70ea1f157..ff699da004f 100755 --- a/hack/lib/util.sh +++ b/hack/lib/util.sh @@ -207,19 +207,16 @@ kube::util::find-binary-for-platform() { "${KUBE_ROOT}/_output/dockerized/go/bin/${lookfor}" ); fi - # Also search for binary in bazel build tree. - # The bazel go rules place some binaries in subtrees like - # "bazel-bin/source/path/linux_amd64_pure_stripped/binaryname", so make sure - # the platform name is matched in the path. - while IFS=$'\n' read -r location; do - locations+=("$location"); - done < <(find "${KUBE_ROOT}/bazel-bin/" -type f -executable \ - \( -path "*/${platform/\//_}*/${lookfor}" -o -path "*/${lookfor}" \) 2>/dev/null || true) - # search for executables for non-GNU versions of find (eg. BSD) - while IFS=$'\n' read -r location; do - locations+=("$location"); - done < <(find "${KUBE_ROOT}/bazel-bin/" -type f -perm -111 \ - \( -path "*/${platform/\//_}*/${lookfor}" -o -path "*/${lookfor}" \) 2>/dev/null || true) + + # Also search for binary in bazel build tree if bazel-out/ exists. + if [[ -d "${KUBE_ROOT}/bazel-out" ]]; then + while IFS=$'\n' read -r bin_build_mode; do + if grep -q "${platform}" "${bin_build_mode}"; then + # drop the extension to get the real binary path. + locations+=("${bin_build_mode%.*}") + fi + done < <(find "${KUBE_ROOT}/bazel-out/" -name "${lookfor}.go_build_mode") + fi # List most recently-updated location. local -r bin=$( (ls -t "${locations[@]}" 2>/dev/null || true) | head -1 )