Merge pull request #135811 from AkihiroSuda/fix-135210-1.34

[release-1.34] hack/lib/util.sh: support uutils' `date` command
This commit is contained in:
Kubernetes Prow Robot
2026-01-07 10:27:44 +05:30
committed by GitHub
2 changed files with 6 additions and 6 deletions

View File

@@ -720,22 +720,22 @@ function kube::util::ensure-gnu-sed {
kube::util::sourced_variable "${SED}"
}
# kube::util::ensure-gnu-date
# kube::util::ensure-gnu-compatible-date
# Determines which date binary is gnu-date on linux/darwin
#
# Sets:
# DATE: The name of the gnu-date binary
#
function kube::util::ensure-gnu-date {
function kube::util::ensure-gnu-compatible-date {
# NOTE: the echo below is a workaround to ensure date is executed before the grep.
# see: https://github.com/kubernetes/kubernetes/issues/87251
date_help="$(LANG=C date --help 2>&1 || true)"
if echo "${date_help}" | grep -q "GNU\|BusyBox"; then
date_version="$(LANG=C date --version 2>&1 || true)"
if echo "${date_version}" | grep -q "GNU\|BusyBox\|uutils"; then
DATE="date"
elif command -v gdate &>/dev/null; then
DATE="gdate"
else
kube::log::error "Failed to find GNU date as date or gdate. If you are on Mac: brew install coreutils." >&2
kube::log::error "Failed to find GNU-compatible date as date or gdate. If you are on Mac: brew install coreutils." >&2
return 1
fi
kube::util::sourced_variable "${DATE}"

View File

@@ -161,7 +161,7 @@ kube::version::ldflags() {
)
}
kube::util::ensure-gnu-date
kube::util::ensure-gnu-compatible-date
add_ldflag "buildDate" "$(${DATE} ${SOURCE_DATE_EPOCH:+"--date=@${SOURCE_DATE_EPOCH}"} -u +'%Y-%m-%dT%H:%M:%SZ')"
if [[ -n ${KUBE_GIT_COMMIT-} ]]; then