Ensure we are using GNU date for builds

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This commit is contained in:
Davanum Srinivas 2022-10-20 10:12:23 -04:00
parent 7423cc931f
commit ec71e53adb
No known key found for this signature in database
GPG Key ID: 80D83A796103BF59
2 changed files with 24 additions and 1 deletions

View File

@ -759,6 +759,27 @@ function kube::util::ensure-gnu-sed {
kube::util::sourced_variable "${SED}"
}
# kube::util::ensure-gnu-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 {
# 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="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
return 1
fi
kube::util::sourced_variable "${DATE}"
}
# kube::util::check-file-in-alphabetical-order <file>
# Check that the file is in alphabetical order
#

View File

@ -163,7 +163,9 @@ kube::version::ldflags() {
)
}
add_ldflag "buildDate" "$(date ${SOURCE_DATE_EPOCH:+"--date=@${SOURCE_DATE_EPOCH}"} -u +'%Y-%m-%dT%H:%M:%SZ')"
kube::util::ensure-gnu-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
add_ldflag "gitCommit" "${KUBE_GIT_COMMIT}"
add_ldflag "gitTreeState" "${KUBE_GIT_TREE_STATE}"