From dfd8e4e4670918e5879215710b43a42cde4f6482 Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Wed, 29 Jan 2020 12:46:08 -0500 Subject: [PATCH] Enable selinux tags in make targets In 24d105995dbd0cb8a67213f5edc8132fdad136cb, a fix was made in bazel based builds to ensure that we add `selinux` tag when we build all binaries especially the `kubelet`. We need to do the same for in our hack scripts so things like `make release` will work properly as well. Some scripts use `GOFLAGS=-tags=providerless` for example, So we should support the tags to be specified in GOFLAGS as well. We parse out the tags from there and ensure selinux is added to the list of tags we used for building the binaries. Note that we add our own `-tags` with the full set of tags and since we specify our parameter at the end, ours full list takes precendence --- hack/lib/golang.sh | 9 ++++++++- test/typecheck/main.go | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh index ce7de733019..b646bbe2edf 100755 --- a/hack/lib/golang.sh +++ b/hack/lib/golang.sh @@ -700,6 +700,7 @@ kube::golang::build_binaries_for_platform() { -gcflags "${gogcflags:-}" -asmflags "${goasmflags:-}" -ldflags "${goldflags:-}" + -tags "${gotags:-}" ) CGO_ENABLED=0 kube::golang::build_some_binaries "${statics[@]}" fi @@ -710,6 +711,7 @@ kube::golang::build_binaries_for_platform() { -gcflags "${gogcflags:-}" -asmflags "${goasmflags:-}" -ldflags "${goldflags:-}" + -tags "${gotags:-}" ) kube::golang::build_some_binaries "${nonstatics[@]}" fi @@ -725,6 +727,7 @@ kube::golang::build_binaries_for_platform() { -gcflags "${gogcflags:-}" \ -asmflags "${goasmflags:-}" \ -ldflags "${goldflags:-}" \ + -tags "${gotags:-}" \ -o "${outfile}" \ "${testpkg}" done @@ -776,7 +779,7 @@ kube::golang::build_binaries() { local host_platform host_platform=$(kube::golang::host_platform) - local goflags goldflags goasmflags gogcflags + local goflags goldflags goasmflags gogcflags gotags # If GOLDFLAGS is unset, then set it to the a default of "-s -w". # Disable SC2153 for this, as it will throw a warning that the local # variable goldflags will exist, and it suggest changing it to this. @@ -785,6 +788,10 @@ kube::golang::build_binaries() { goasmflags="-trimpath=${KUBE_ROOT}" gogcflags="${GOGCFLAGS:-} -trimpath=${KUBE_ROOT}" + # extract tags if any specified in GOFLAGS + # shellcheck disable=SC2001 + gotags="selinux,$(echo "${GOFLAGS:-}" | sed -e 's|.*-tags=\([^-]*\).*|\1|')" + local -a targets=() local arg diff --git a/test/typecheck/main.go b/test/typecheck/main.go index b6bd558b4da..9e073be31f1 100644 --- a/test/typecheck/main.go +++ b/test/typecheck/main.go @@ -105,6 +105,9 @@ func newAnalyzer(platform string) *analyzer { ctx.BuildTags = append(ctx.BuildTags, tagsSplit...) } + // add selinux tag explicitly + ctx.BuildTags = append(ctx.BuildTags, "selinux") + a := &analyzer{ platform: platform, fset: token.NewFileSet(),