Skip to content

Commit 405609b

Browse files
committed
Fix shellcheck warnings/errors in /build/lib/release.sh
With these changes, /build/lib/release.sh can be removed from hack/.shellcheck_failures and included in the scripts that are checked by hack/verify-shellcheck.sh. Signed-off-by: Joakim Roubert <[email protected]>
1 parent d52ecd5 commit 405609b

File tree

2 files changed

+65
-42
lines changed

2 files changed

+65
-42
lines changed

build/lib/release.sh

Lines changed: 65 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,23 @@ function kube::release::parse_and_validate_ci_version() {
5656
kube::log::error "Invalid ci version: '${version}', must match regex ${version_regex}"
5757
return 1
5858
}
59+
60+
# The VERSION variables are used when this file is sourced, hence
61+
# the shellcheck SC2034 'appears unused' warning is to be ignored.
62+
63+
# shellcheck disable=SC2034
5964
VERSION_MAJOR="${BASH_REMATCH[1]}"
65+
# shellcheck disable=SC2034
6066
VERSION_MINOR="${BASH_REMATCH[2]}"
67+
# shellcheck disable=SC2034
6168
VERSION_PATCH="${BASH_REMATCH[3]}"
69+
# shellcheck disable=SC2034
6270
VERSION_PRERELEASE="${BASH_REMATCH[4]}"
71+
# shellcheck disable=SC2034
6372
VERSION_PRERELEASE_REV="${BASH_REMATCH[5]}"
73+
# shellcheck disable=SC2034
6474
VERSION_BUILD_INFO="${BASH_REMATCH[6]}"
75+
# shellcheck disable=SC2034
6576
VERSION_COMMITS="${BASH_REMATCH[7]}"
6677
}
6778

@@ -100,28 +111,25 @@ function kube::release::package_src_tarball() {
100111
if [[ "${KUBE_GIT_TREE_STATE-}" == "clean" ]]; then
101112
git archive -o "${src_tarball}" HEAD
102113
else
103-
local source_files=(
104-
$(cd "${KUBE_ROOT}" && find . -mindepth 1 -maxdepth 1 \
114+
"${TAR}" czf "${src_tarball}" --transform 's|^\.|kubernetes|' -C "${KUBE_ROOT}" "$(cd "${KUBE_ROOT}" && find . -mindepth 1 -maxdepth 1 \
105115
-not \( \
106116
\( -path ./_\* -o \
107117
-path ./.git\* -o \
108118
-path ./.config\* -o \
109119
-path ./.gsutil\* \
110120
\) -prune \
111-
\))
112-
)
113-
"${TAR}" czf "${src_tarball}" --transform 's|^\.|kubernetes|' -C "${KUBE_ROOT}" "${source_files[@]}"
121+
\))"
114122
fi
115123
}
116124

117125
# Package up all of the cross compiled clients. Over time this should grow into
118126
# a full SDK
119127
function kube::release::package_client_tarballs() {
120128
# Find all of the built client binaries
121-
local platform platforms
122-
platforms=($(cd "${LOCAL_OUTPUT_BINPATH}" ; echo */*))
123-
for platform in "${platforms[@]}"; do
124-
local platform_tag=${platform/\//-} # Replace a "/" for a "-"
129+
for platform in "${LOCAL_OUTPUT_BINPATH}"/*/*; do
130+
local platform_tag
131+
platform_tag=${platform##${LOCAL_OUTPUT_BINPATH}/} # Strip LOCAL_OUTPUT_BINPATH
132+
platform_tag=${platform_tag/\//-} # Replace a "/" for a "-"
125133
kube::log::status "Starting tarball: client $platform_tag"
126134

127135
(
@@ -155,8 +163,10 @@ function kube::release::package_client_tarballs() {
155163
function kube::release::package_node_tarballs() {
156164
local platform
157165
for platform in "${KUBE_NODE_PLATFORMS[@]}"; do
158-
local platform_tag=${platform/\//-} # Replace a "/" for a "-"
159-
local arch=$(basename "${platform}")
166+
local platform_tag
167+
local arch
168+
platform_tag=${platform/\//-} # Replace a "/" for a "-"
169+
arch=$(basename "${platform}")
160170
kube::log::status "Building tarball: node $platform_tag"
161171

162172
local release_stage="${RELEASE_STAGE}/node/${platform_tag}/kubernetes"
@@ -204,11 +214,14 @@ function kube::release::build_server_images() {
204214
rm -rf "${RELEASE_IMAGES}"
205215
local platform
206216
for platform in "${KUBE_SERVER_PLATFORMS[@]}"; do
207-
local platform_tag=${platform/\//-} # Replace a "/" for a "-"
208-
local arch=$(basename "${platform}")
217+
local platform_tag
218+
local arch
219+
platform_tag=${platform/\//-} # Replace a "/" for a "-"
220+
arch=$(basename "${platform}")
209221
kube::log::status "Building images: $platform_tag"
210222

211-
local release_stage="${RELEASE_STAGE}/server/${platform_tag}/kubernetes"
223+
local release_stage
224+
release_stage="${RELEASE_STAGE}/server/${platform_tag}/kubernetes"
212225
rm -rf "${release_stage}"
213226
mkdir -p "${release_stage}/server/bin"
214227

@@ -227,12 +240,15 @@ function kube::release::package_server_tarballs() {
227240
kube::release::build_server_images
228241
local platform
229242
for platform in "${KUBE_SERVER_PLATFORMS[@]}"; do
230-
local platform_tag=${platform/\//-} # Replace a "/" for a "-"
231-
local arch=$(basename "${platform}")
243+
local platform_tag
244+
local arch
245+
platform_tag=${platform/\//-} # Replace a "/" for a "-"
246+
arch=$(basename "${platform}")
232247
kube::log::status "Building tarball: server $platform_tag"
233248

234249
# NOTE: this directory was setup in kube::release::build_server_images
235-
local release_stage="${RELEASE_STAGE}/server/${platform_tag}/kubernetes"
250+
local release_stage
251+
release_stage="${RELEASE_STAGE}/server/${platform_tag}/kubernetes"
236252
mkdir -p "${release_stage}/addons"
237253

238254
# This fancy expression will expand to prepend a path
@@ -242,7 +258,8 @@ function kube::release::package_server_tarballs() {
242258
"${release_stage}/server/bin/"
243259

244260
# Include the client binaries here too as they are useful debugging tools.
245-
local client_bins=("${KUBE_CLIENT_BINARIES[@]}")
261+
local client_bins
262+
client_bins=("${KUBE_CLIENT_BINARIES[@]}")
246263
if [[ "${platform%/*}" == "windows" ]]; then
247264
client_bins=("${KUBE_CLIENT_BINARIES_WIN[@]}")
248265
fi
@@ -258,7 +275,8 @@ function kube::release::package_server_tarballs() {
258275

259276
kube::release::clean_cruft
260277

261-
local package_name="${RELEASE_TARS}/kubernetes-server-${platform_tag}.tar.gz"
278+
local package_name
279+
package_name="${RELEASE_TARS}/kubernetes-server-${platform_tag}.tar.gz"
262280
kube::release::create_tarball "${package_name}" "${release_stage}/.."
263281
done
264282
}
@@ -288,7 +306,8 @@ function kube::release::build_hyperkube_image() {
288306
ARCH="${arch}" REGISTRY="${registry}" VERSION="${version}" \
289307
make -C cluster/images/hyperkube/ build >/dev/null
290308

291-
local hyperkube_tag="${registry}/hyperkube-${arch}:${version}"
309+
local hyperkube_tag
310+
hyperkube_tag="${registry}/hyperkube-${arch}:${version}"
292311
if [[ -n "${save_dir}" ]]; then
293312
"${DOCKER[@]}" save "${hyperkube_tag}" > "${save_dir}/hyperkube-${arch}.tar"
294313
fi
@@ -305,7 +324,8 @@ function kube::release::build_conformance_image() {
305324
ARCH="${arch}" REGISTRY="${registry}" VERSION="${version}" \
306325
make -C cluster/images/conformance/ build >/dev/null
307326

308-
local conformance_tag="${registry}/conformance-${arch}:${version}"
327+
local conformance_tag
328+
conformance_tag="${registry}/conformance-${arch}:${version}"
309329
if [[ -n "${save_dir}" ]]; then
310330
"${DOCKER[@]}" save "${conformance_tag}" > "${save_dir}/conformance-${arch}.tar"
311331
fi
@@ -320,11 +340,15 @@ function kube::release::build_conformance_image() {
320340
function kube::release::create_docker_images_for_server() {
321341
# Create a sub-shell so that we don't pollute the outer environment
322342
(
323-
local binary_dir="$1"
324-
local arch="$2"
325-
local binary_name
326-
local binaries=($(kube::build::get_docker_wrapped_binaries "${arch}"))
327-
local images_dir="${RELEASE_IMAGES}/${arch}"
343+
local binary_dir
344+
local arch
345+
local binaries
346+
local images_dir
347+
binary_dir="$1"
348+
arch="$2"
349+
binary_name
350+
binaries=$(kube::build::get_docker_wrapped_binaries "${arch}")
351+
images_dir="${RELEASE_IMAGES}/${arch}"
328352
mkdir -p "${images_dir}"
329353

330354
# k8s.gcr.io is the constant tag in the docker archives, this is also the default for config scripts in GKE.
@@ -341,31 +365,31 @@ function kube::release::create_docker_images_for_server() {
341365
# provide `--pull` argument to `docker build` if `KUBE_BUILD_PULL_LATEST_IMAGES`
342366
# is set to y or Y; otherwise try to build the image without forcefully
343367
# pulling the latest base image.
344-
local DOCKER_BUILD_OPTS=()
368+
local docker_build_opts
369+
docker_build_opts=
345370
if [[ "${KUBE_BUILD_PULL_LATEST_IMAGES}" =~ [yY] ]]; then
346-
DOCKER_BUILD_OPTS+=("--pull")
371+
docker_build_opts='--pull'
347372
fi
348-
local -r docker_build_opts="${DOCKER_BUILD_OPTS[@]}"
349373

350374
for wrappable in "${binaries[@]}"; do
351375

352376
local oldifs=$IFS
353377
IFS=","
354-
set $wrappable
378+
set "$wrappable"
355379
IFS=$oldifs
356380

357381
local binary_name="$1"
358382
local base_image="$2"
359-
local docker_build_path="${binary_dir}/${binary_name}.dockerbuild"
360-
local docker_file_path="${docker_build_path}/Dockerfile"
361383
local binary_file_path="${binary_dir}/${binary_name}"
384+
local docker_build_path="${binary_file_path}.dockerbuild"
385+
local docker_file_path="${docker_build_path}/Dockerfile"
362386
local docker_image_tag="${docker_registry}/${binary_name}-${arch}:${docker_tag}"
363387

364388
kube::log::status "Starting docker build for image: ${binary_name}-${arch}"
365389
(
366390
rm -rf "${docker_build_path}"
367391
mkdir -p "${docker_build_path}"
368-
ln "${binary_dir}/${binary_name}" "${docker_build_path}/${binary_name}"
392+
ln "${binary_file_path}" "${docker_build_path}/${binary_name}"
369393
ln "${KUBE_ROOT}/build/nsswitch.conf" "${docker_build_path}/nsswitch.conf"
370394
chmod 0644 "${docker_build_path}/nsswitch.conf"
371395
cat <<EOF > "${docker_file_path}"
@@ -377,7 +401,7 @@ EOF
377401
echo "COPY nsswitch.conf /etc/" >> "${docker_file_path}"
378402
fi
379403

380-
"${DOCKER[@]}" build ${docker_build_opts} -q -t "${docker_image_tag}" "${docker_build_path}" >/dev/null
404+
"${DOCKER[@]}" build "${docker_build_opts}" -q -t "${docker_image_tag}" "${docker_build_path}" >/dev/null
381405
# If we are building an official/alpha/beta release we want to keep
382406
# docker images and tag them appropriately.
383407
local -r release_docker_image_tag="${KUBE_DOCKER_REGISTRY-$docker_registry}/${binary_name}-${arch}:${KUBE_DOCKER_IMAGE_TAG-$docker_tag}"
@@ -386,10 +410,10 @@ EOF
386410
"${DOCKER[@]}" rmi "${release_docker_image_tag}" 2>/dev/null || true
387411
"${DOCKER[@]}" tag "${docker_image_tag}" "${release_docker_image_tag}" 2>/dev/null
388412
fi
389-
"${DOCKER[@]}" save -o "${binary_dir}/${binary_name}.tar" "${docker_image_tag}" ${release_docker_image_tag}
390-
echo "${docker_tag}" > "${binary_dir}/${binary_name}.docker_tag"
413+
"${DOCKER[@]}" save -o "${binary_file_path}.tar" "${docker_image_tag}" "${release_docker_image_tag}"
414+
echo "${docker_tag}" > "${binary_file_path}.docker_tag"
391415
rm -rf "${docker_build_path}"
392-
ln "${binary_dir}/${binary_name}.tar" "${images_dir}/"
416+
ln "${binary_file_path}.tar" "${images_dir}/"
393417

394418
kube::log::status "Deleting docker image ${docker_image_tag}"
395419
"${DOCKER[@]}" rmi "${docker_image_tag}" &>/dev/null || true
@@ -434,8 +458,8 @@ function kube::release::package_kube_manifests_tarball() {
434458
cp "${src_dir}/glbc.manifest" "${dst_dir}"
435459
cp "${src_dir}/etcd-empty-dir-cleanup.yaml" "${dst_dir}/"
436460
local internal_manifest
437-
for internal_manifest in $(ls "${src_dir}" | grep "^internal-*"); do
438-
cp "${src_dir}/${internal_manifest}" "${dst_dir}"
461+
for internal_manifest in "${src_dir}/internal-"*; do
462+
cp "${internal_manifest}" "${dst_dir}"
439463
done
440464
cp "${KUBE_ROOT}/cluster/gce/gci/configure-helper.sh" "${dst_dir}/gci-configure-helper.sh"
441465
cp "${KUBE_ROOT}/cluster/gce/gci/configure-kubeapiserver.sh" "${dst_dir}/configure-kubeapiserver.sh"
@@ -445,12 +469,12 @@ function kube::release::package_kube_manifests_tarball() {
445469
cp "${KUBE_ROOT}/cluster/gce/gci/health-monitor.sh" "${dst_dir}/health-monitor.sh"
446470
local objects
447471
objects=$(cd "${KUBE_ROOT}/cluster/addons" && find . \( -name \*.yaml -or -name \*.yaml.in -or -name \*.json \) | grep -v demo)
448-
tar c -C "${KUBE_ROOT}/cluster/addons" ${objects} | tar x -C "${dst_dir}"
472+
tar c -C "${KUBE_ROOT}/cluster/addons" "${objects}" | tar x -C "${dst_dir}"
449473
# Merge GCE-specific addons with general purpose addons.
450474
local gce_objects
451475
gce_objects=$(cd "${KUBE_ROOT}/cluster/gce/addons" && find . \( -name \*.yaml -or -name \*.yaml.in -or -name \*.json \) \( -not -name \*demo\* \))
452476
if [[ -n "${gce_objects}" ]]; then
453-
tar c -C "${KUBE_ROOT}/cluster/gce/addons" ${gce_objects} | tar x -C "${dst_dir}"
477+
tar c -C "${KUBE_ROOT}/cluster/gce/addons" "${gce_objects}" | tar x -C "${dst_dir}"
454478
fi
455479

456480
kube::release::clean_cruft

hack/.shellcheck_failures

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
./build/lib/release.sh
21
./cluster/gce/config-default.sh
32
./cluster/gce/config-test.sh
43
./cluster/gce/gci/configure-helper.sh

0 commit comments

Comments
 (0)