Skip to content

Commit 835268e

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request kubernetes#64219 from ixdy/hack-lib-golang-cgo-overrides
Automatic merge from submit-queue (batch tested with PRs 64338, 64219, 64486, 64495, 64347). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Add KUBE_CGO_OVERRIDES env var to force enabling CGO **What this PR does / why we need it**: as detailed in kubernetes/release#469 (and elsewhere), there is a desire to have `kubectl` built with CGO enabled on mac OS. There currently isn't a great way to do this in our official cross builds, but we should allow mac users to build their own kubectl with CGO enabled if they desire, e.g. through homebrew. This change enables that; you can now do `KUBE_CGO_OVERRIDES=kubectl make WHAT=cmd/kubectl` and get a cgo-enabled `kubectl`. The default build outputs remain unchanged. **Release note**: ```release-note kubectl built for darwin from darwin now enables cgo to use the system-native C libraries for DNS resolution. Cross-compiled kubectl (e.g. from an official kubernetes release) still uses the go-native netgo DNS implementation. ``` /assign @BenTheElder @cblecker cc @bks7 @bitglue
2 parents 887f8ec + e4ded2b commit 835268e

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

hack/lib/golang.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,27 @@ readonly KUBE_STATIC_LIBRARIES=(
213213
kubectl
214214
)
215215

216+
# KUBE_CGO_OVERRIDES is a space-separated list of binaries which should be built
217+
# with CGO enabled, assuming CGO is supported on the target platform.
218+
# This overrides any entry in KUBE_STATIC_LIBRARIES.
219+
IFS=" " read -ra KUBE_CGO_OVERRIDES <<< "${KUBE_CGO_OVERRIDES:-}"
220+
readonly KUBE_CGO_OVERRIDES
221+
# KUBE_STATIC_OVERRIDES is a space-separated list of binaries which should be
222+
# built with CGO disabled. This is in addition to the list in
223+
# KUBE_STATIC_LIBRARIES.
224+
IFS=" " read -ra KUBE_STATIC_OVERRIDES <<< "${KUBE_STATIC_OVERRIDES:-}"
225+
readonly KUBE_STATIC_OVERRIDES
226+
216227
kube::golang::is_statically_linked_library() {
217228
local e
229+
# Explicitly enable cgo when building kubectl for darwin from darwin.
230+
[[ "$(go env GOHOSTOS)" == "darwin" && "$(go env GOOS)" == "darwin" &&
231+
"$1" == *"/kubectl" ]] && return 1
232+
if [[ -n "${KUBE_CGO_OVERRIDES:+x}" ]]; then
233+
for e in "${KUBE_CGO_OVERRIDES[@]}"; do [[ "$1" == *"/$e" ]] && return 1; done;
234+
fi
218235
for e in "${KUBE_STATIC_LIBRARIES[@]}"; do [[ "$1" == *"/$e" ]] && return 0; done;
219-
# Allow individual overrides--e.g., so that you can get a static build of
220-
# kubectl for inclusion in a container.
221-
if [ -n "${KUBE_STATIC_OVERRIDES:+x}" ]; then
236+
if [[ -n "${KUBE_STATIC_OVERRIDES:+x}" ]]; then
222237
for e in "${KUBE_STATIC_OVERRIDES[@]}"; do [[ "$1" == *"/$e" ]] && return 0; done;
223238
fi
224239
return 1;

0 commit comments

Comments
 (0)