From 60e446a7b33360a697e44e83487a22b57537aeb5 Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Fri, 7 Nov 2025 12:58:02 +0900 Subject: [PATCH] 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. /src/k8s.io/kubernetes/hack/lib/version.sh: line 166: DATE: unbound variable ``` Fix issue 135210 Signed-off-by: Akihiro Suda (cherry picked from commit 0c0bc0d533f669fa4acc4fe5b33c75864262cf64) Signed-off-by: Akihiro Suda --- hack/lib/util.sh | 10 +++++----- hack/lib/version.sh | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/hack/lib/util.sh b/hack/lib/util.sh index cae8a499204..ed067cc7a30 100755 --- a/hack/lib/util.sh +++ b/hack/lib/util.sh @@ -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}" diff --git a/hack/lib/version.sh b/hack/lib/version.sh index ffd8bc3789a..65595e63fe9 100644 --- a/hack/lib/version.sh +++ b/hack/lib/version.sh @@ -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