Allow init.sh and protoc.sh to be sourced idempotently

This commit is contained in:
Jordan Liggitt 2023-01-23 09:12:41 -05:00
parent 3548e7febe
commit d49d988467
No known key found for this signature in database
2 changed files with 16 additions and 0 deletions

View File

@ -18,6 +18,9 @@ set -o errexit
set -o nounset set -o nounset
set -o pipefail set -o pipefail
# Short-circuit if init.sh has already been sourced
[[ $(type -t kube::init::loaded) == function ]] && return 0
# Unset CDPATH so that path interpolation can work correctly # Unset CDPATH so that path interpolation can work correctly
# https://github.com/kubernetes/kubernetes/issues/52255 # https://github.com/kubernetes/kubernetes/issues/52255
unset CDPATH unset CDPATH
@ -211,3 +214,8 @@ kube::realpath() {
fi fi
kube::readlinkdashf "${1}" kube::readlinkdashf "${1}"
} }
# Marker function to indicate init.sh has been fully sourced
kube::init::loaded() {
return 0
}

View File

@ -18,6 +18,9 @@ set -o errexit
set -o nounset set -o nounset
set -o pipefail set -o pipefail
# Short-circuit if protoc.sh has already been sourced
[[ $(type -t kube::protoc::loaded) == function ]] && return 0
# The root of the build/dist directory # The root of the build/dist directory
KUBE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)" KUBE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
source "${KUBE_ROOT}/hack/lib/init.sh" source "${KUBE_ROOT}/hack/lib/init.sh"
@ -134,3 +137,8 @@ function kube::protoc::install() {
kube::log::info "export PATH=\"$(pwd)/protoc:\${PATH}\"" kube::log::info "export PATH=\"$(pwd)/protoc:\${PATH}\""
) )
} }
# Marker function to indicate protoc.sh has been fully sourced
kube::protoc::loaded() {
return 0
}