Skip to content

Commit

Permalink
automatically setup etcd when running verify/update openapi-spec.sh
Browse files Browse the repository at this point in the history
1. automatically add etcd to current PATH when calling kube::etcd::install

2. call kube::etcd::install from update-openapi-spec

3. don't call kube::golang::setup_env twice
  • Loading branch information
BenTheElder committed Oct 25, 2023
1 parent 03ba7ef commit 3c530ee
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 35 deletions.
70 changes: 37 additions & 33 deletions hack/lib/etcd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,38 +144,42 @@ kube::etcd::cleanup() {
}

kube::etcd::install() {
(
local os
local arch

os=$(kube::util::host_os)
arch=$(kube::util::host_arch)

cd "${KUBE_ROOT}/third_party" || return 1
if [[ $(readlink etcd) == etcd-v${ETCD_VERSION}-${os}-* ]]; then
kube::log::info "etcd v${ETCD_VERSION} already installed. To use:"
kube::log::info "export PATH=\"$(pwd)/etcd:\${PATH}\""
return #already installed
fi

if [[ ${os} == "darwin" ]]; then
download_file="etcd-v${ETCD_VERSION}-${os}-${arch}.zip"
url="https://github.com/etcd-io/etcd/releases/download/v${ETCD_VERSION}/${download_file}"
kube::util::download_file "${url}" "${download_file}"
unzip -o "${download_file}"
ln -fns "etcd-v${ETCD_VERSION}-${os}-${arch}" etcd
rm "${download_file}"
elif [[ ${os} == "linux" ]]; then
url="https://github.com/coreos/etcd/releases/download/v${ETCD_VERSION}/etcd-v${ETCD_VERSION}-${os}-${arch}.tar.gz"
download_file="etcd-v${ETCD_VERSION}-${os}-${arch}.tar.gz"
kube::util::download_file "${url}" "${download_file}"
tar xzf "${download_file}"
ln -fns "etcd-v${ETCD_VERSION}-${os}-${arch}" etcd
rm "${download_file}"
else
kube::log::info "${os} is NOT supported."
fi
kube::log::info "etcd v${ETCD_VERSION} installed. To use:"
local os
local arch

os=$(kube::util::host_os)
arch=$(kube::util::host_arch)

cd "${KUBE_ROOT}/third_party" || return 1
if [[ $(readlink etcd) == etcd-v${ETCD_VERSION}-${os}-* ]]; then
kube::log::info "etcd v${ETCD_VERSION} already installed. To use:"
kube::log::info "export PATH=\"$(pwd)/etcd:\${PATH}\""
)
# export into current process
PATH="$(pwd)/etcd:${PATH}"
export PATH
return #already installed
fi

if [[ ${os} == "darwin" ]]; then
download_file="etcd-v${ETCD_VERSION}-${os}-${arch}.zip"
url="https://github.com/etcd-io/etcd/releases/download/v${ETCD_VERSION}/${download_file}"
kube::util::download_file "${url}" "${download_file}"
unzip -o "${download_file}"
ln -fns "etcd-v${ETCD_VERSION}-${os}-${arch}" etcd
rm "${download_file}"
elif [[ ${os} == "linux" ]]; then
url="https://github.com/coreos/etcd/releases/download/v${ETCD_VERSION}/etcd-v${ETCD_VERSION}-${os}-${arch}.tar.gz"
download_file="etcd-v${ETCD_VERSION}-${os}-${arch}.tar.gz"
kube::util::download_file "${url}" "${download_file}"
tar xzf "${download_file}"
ln -fns "etcd-v${ETCD_VERSION}-${os}-${arch}" etcd
rm "${download_file}"
else
kube::log::info "${os} is NOT supported."
fi
kube::log::info "etcd v${ETCD_VERSION} installed. To use:"
kube::log::info "export PATH=\"$(pwd)/etcd:\${PATH}\""
# export into current process
PATH="$(pwd)/etcd:${PATH}"
export PATH
}
3 changes: 1 addition & 2 deletions hack/update-openapi-spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ source "${KUBE_ROOT}/hack/lib/init.sh"

kube::util::require-jq
kube::golang::setup_env
kube::etcd::install

make -C "${KUBE_ROOT}" WHAT=cmd/kube-apiserver

Expand All @@ -46,8 +47,6 @@ function cleanup()

trap cleanup EXIT SIGINT

kube::golang::setup_env

TMP_DIR=${TMP_DIR:-$(kube::realpath "$(mktemp -d -t "$(basename "$0").XXXXXX")")}
ETCD_HOST=${ETCD_HOST:-127.0.0.1}
ETCD_PORT=${ETCD_PORT:-2379}
Expand Down

0 comments on commit 3c530ee

Please sign in to comment.