hack/lib/util.sh: support uutils' date command

`make` was printing the following warning on Ubuntu 25.10,
which switched away from GNU coreutils to uutils:

```
!!! [1107 12:46:24] Failed to find GNU date as date or gdate. If you are on Mac: brew install coreutils.
<GOPATH>/src/k8s.io/kubernetes/hack/lib/version.sh: line 166: DATE: unbound variable
```

Fix issue 135210

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
(cherry picked from commit 0c0bc0d533f669fa4acc4fe5b33c75864262cf64)
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
Akihiro Suda
2025-11-07 12:58:02 +09:00
parent 5ed8e8aa89
commit 60e446a7b3
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