mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #59797 from ipuustin/shell-bugfix3
Automatic merge from submit-queue (batch tested with PRs 59532, 59685, 59797). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Continue fixing bash scripts **What this PR does / why we need it**: This PR continues the work of fixing bugs in shell scripts (see https://github.com/kubernetes/kubernetes/pull/59572 for the previous PR). The fixed scripts are `hack/grab-profiles.sh` and `hack/update-codegen.sh`. Most of the issues are found by using `shellcheck`. The goal is to make the scripts work and behave as they did previously, but fix obvious bugs and make them more robust and resilient for irregular input such as file names with special characters or whitespace in them. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
commit
fb5caac2da
@ -51,7 +51,7 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
|
||||
source "${KUBE_ROOT}/hack/lib/init.sh"
|
||||
|
||||
server_addr=""
|
||||
kubelet_addreses=""
|
||||
kubelet_addresses=""
|
||||
kubelet_binary=""
|
||||
master_binary=""
|
||||
scheduler_binary=""
|
||||
@ -97,7 +97,7 @@ while true; do
|
||||
--master-binary)
|
||||
shift
|
||||
if [ -z "$1" ]; then
|
||||
>&2 echo "empty argumet to --master-binary flag"
|
||||
>&2 echo "empty argument to --master-binary flag"
|
||||
exit 1
|
||||
fi
|
||||
master_binary=$1
|
||||
@ -111,16 +111,16 @@ while true; do
|
||||
shift
|
||||
profile_components="kubelet ${profile_components}"
|
||||
if [ -z "$1" ]; then
|
||||
>&2 echo "empty argumet to --kubelet flag"
|
||||
>&2 echo "empty argument to --kubelet flag"
|
||||
exit 1
|
||||
fi
|
||||
kubelet_addreses="$1 $kubelet_addreses"
|
||||
kubelet_addresses="$1 $kubelet_addresses"
|
||||
shift
|
||||
;;
|
||||
--kubelet-binary)
|
||||
shift
|
||||
if [ -z "$1" ]; then
|
||||
>&2 echo "empty argumet to --kubelet-binary flag"
|
||||
>&2 echo "empty argument to --kubelet-binary flag"
|
||||
exit 1
|
||||
fi
|
||||
kubelet_binary=$1
|
||||
@ -133,7 +133,7 @@ while true; do
|
||||
--scheduler-binary)
|
||||
shift
|
||||
if [ -z "$1" ]; then
|
||||
>&2 echo "empty argumet to --scheduler-binary flag"
|
||||
>&2 echo "empty argument to --scheduler-binary flag"
|
||||
exit 1
|
||||
fi
|
||||
scheduler_binary=$1
|
||||
@ -142,7 +142,7 @@ while true; do
|
||||
--scheduler-port)
|
||||
shift
|
||||
if [ -z "$1" ]; then
|
||||
>&2 echo "empty argumet to --scheduler-port flag"
|
||||
>&2 echo "empty argument to --scheduler-port flag"
|
||||
exit 1
|
||||
fi
|
||||
scheduler_port=$1
|
||||
@ -155,7 +155,7 @@ while true; do
|
||||
--controller-manager-binary)
|
||||
shift
|
||||
if [ -z "$1" ]; then
|
||||
>&2 echo "empty argumet to --controller-manager-binary flag"
|
||||
>&2 echo "empty argument to --controller-manager-binary flag"
|
||||
exit 1
|
||||
fi
|
||||
controller_manager_binary=$1
|
||||
@ -164,10 +164,10 @@ while true; do
|
||||
--controller-manager-port)
|
||||
shift
|
||||
if [ -z "$1" ]; then
|
||||
>&2 echo "empty argumet to --controller-manager-port flag"
|
||||
>&2 echo "empty argument to --controller-manager-port flag"
|
||||
exit 1
|
||||
fi
|
||||
controller-managerr_port=$1
|
||||
controller_manager_port=$1
|
||||
shift
|
||||
;;
|
||||
-o|--output)
|
||||
@ -240,18 +240,18 @@ if [[ -z "${requested_profiles}" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
gcloud compute ssh "${server_addr}" --ssh-flag=-nN --ssh-flag=-L${tunnel_port}:localhost:8080 &
|
||||
gcloud compute ssh "${server_addr}" --ssh-flag=-nN --ssh-flag=-L"${tunnel_port}":localhost:8080 &
|
||||
|
||||
echo "Waiting for tunnel to be created..."
|
||||
kube::util::wait_for_url http://localhost:${tunnel_port}/healthz
|
||||
kube::util::wait_for_url http://localhost:"${tunnel_port}"/healthz
|
||||
|
||||
SSH_PID=$(pgrep -f "/usr/bin/ssh.*${tunnel_port}:localhost:8080")
|
||||
kube::util::trap_add 'kill $SSH_PID' EXIT
|
||||
kube::util::trap_add 'kill $SSH_PID' SIGTERM
|
||||
kube::util::trap_add "kill $SSH_PID" EXIT
|
||||
kube::util::trap_add "kill $SSH_PID" SIGTERM
|
||||
|
||||
requested_profiles=$(echo ${requested_profiles} | xargs -n1 | LC_ALL=C sort -u | xargs)
|
||||
profile_components=$(echo ${profile_components} | xargs -n1 | LC_ALL=C sort -u | xargs)
|
||||
kubelet_addreses=$(echo ${kubelet_addreses} | xargs -n1 | LC_ALL=C sort -u | xargs)
|
||||
requested_profiles=$(echo "${requested_profiles}" | xargs -n1 | LC_ALL=C sort -u | xargs)
|
||||
profile_components=$(echo "${profile_components}" | xargs -n1 | LC_ALL=C sort -u | xargs)
|
||||
kubelet_addresses=$(echo "${kubelet_addresses}" | xargs -n1 | LC_ALL=C sort -u | xargs)
|
||||
echo "requested profiles: ${requested_profiles}"
|
||||
echo "flags for heap profile: ${mem_pprof_flags}"
|
||||
|
||||
@ -291,7 +291,7 @@ for component in ${profile_components}; do
|
||||
esac
|
||||
|
||||
if [[ "${component}" == "kubelet" ]]; then
|
||||
for node in $(echo ${kubelet_addreses} | sed 's/[,;]/\n/g'); do
|
||||
for node in ${kubelet_addresses//[,;]/' '}; do
|
||||
grab_profiles_from_component "${requested_profiles}" "${mem_pprof_flags}" "${binary}" "${tunnel_port}" "${path}/${node}" "${output_dir}/${component}" "${timestamp}"
|
||||
done
|
||||
else
|
||||
|
@ -38,7 +38,7 @@ informergen=$(kube::util::find-binary "informer-gen")
|
||||
# that generates the set-gen program.
|
||||
#
|
||||
|
||||
GROUP_VERSIONS=(${KUBE_AVAILABLE_GROUP_VERSIONS})
|
||||
IFS=" " read -ra GROUP_VERSIONS <<< "$KUBE_AVAILABLE_GROUP_VERSIONS"
|
||||
GV_DIRS=()
|
||||
INTERNAL_DIRS=()
|
||||
for gv in "${GROUP_VERSIONS[@]}"; do
|
||||
@ -50,20 +50,28 @@ for gv in "${GROUP_VERSIONS[@]}"; do
|
||||
|
||||
|
||||
# skip groups that aren't being served, clients for these don't matter
|
||||
if [[ " ${KUBE_NONSERVER_GROUP_VERSIONS} " == *" ${gv} "* ]]; then
|
||||
continue
|
||||
fi
|
||||
if [[ " ${KUBE_NONSERVER_GROUP_VERSIONS} " == *" ${gv} "* ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
GV_DIRS+=("${pkg_dir}")
|
||||
|
||||
# collect internal groups
|
||||
int_group="${pkg_dir%/*}/"
|
||||
if [[ "${pkg_dir}" = core/* ]]; then
|
||||
int_group="api/"
|
||||
int_group="api/"
|
||||
fi
|
||||
|
||||
found=0
|
||||
for dir in "${INTERNAL_DIRS[@]}"; do
|
||||
if [[ "$dir" = "$int_group" ]]; then
|
||||
found=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [[ $found = 0 ]]; then
|
||||
INTERNAL_DIRS+=("$int_group")
|
||||
fi
|
||||
if ! [[ " ${INTERNAL_DIRS[@]:-} " =~ " ${int_group} " ]]; then
|
||||
INTERNAL_DIRS+=("${int_group}")
|
||||
fi
|
||||
done
|
||||
# delimit by commas for the command
|
||||
GV_DIRS_CSV=$(IFS=',';echo "${GV_DIRS[*]// /,}";IFS=$)
|
||||
@ -74,32 +82,26 @@ INTERNAL_DIRS_CSV=$(IFS=',';echo "${INTERNAL_DIRS[*]// /,}";IFS=$)
|
||||
${clientgen} --input-base="k8s.io/kubernetes/pkg/apis" --input="${INTERNAL_DIRS_CSV}" "$@"
|
||||
${clientgen} --output-base "${KUBE_ROOT}/vendor" --output-package="k8s.io/client-go" --clientset-name="kubernetes" --input-base="k8s.io/kubernetes/vendor/k8s.io/api" --input="${GV_DIRS_CSV}" --go-header-file ${KUBE_ROOT}/hack/boilerplate/boilerplate.go.txt "$@"
|
||||
|
||||
listergen_internal_apis=(
|
||||
$(
|
||||
cd ${KUBE_ROOT}
|
||||
find pkg/apis -maxdepth 2 -name types.go | xargs -n1 dirname | sort
|
||||
mapfile -t listergen_internal_apis < <(
|
||||
cd "${KUBE_ROOT}"
|
||||
sort <(find pkg/apis -maxdepth 2 -name types.go -exec dirname {} \;)
|
||||
)
|
||||
)
|
||||
listergen_internal_apis=(${listergen_internal_apis[@]/#/k8s.io/kubernetes/})
|
||||
listergen_internal_apis=("${listergen_internal_apis[@]/#/k8s.io/kubernetes/}")
|
||||
listergen_internal_apis_csv=$(IFS=,; echo "${listergen_internal_apis[*]}")
|
||||
${listergen} --input-dirs "${listergen_internal_apis_csv}" "$@"
|
||||
|
||||
listergen_external_apis=(
|
||||
$(
|
||||
cd ${KUBE_ROOT}/staging/src
|
||||
find k8s.io/api -name types.go | xargs -n1 dirname | sort
|
||||
)
|
||||
mapfile -t listergen_external_apis < <(
|
||||
cd "${KUBE_ROOT}/staging/src"
|
||||
sort <(find k8s.io/api -name types.go -exec dirname {} \;)
|
||||
)
|
||||
listergen_external_apis_csv=$(IFS=,; echo "${listergen_external_apis[*]}")
|
||||
${listergen} --output-base "${KUBE_ROOT}/vendor" --output-package "k8s.io/client-go/listers" --input-dirs "${listergen_external_apis_csv}" --go-header-file ${KUBE_ROOT}/hack/boilerplate/boilerplate.go.txt "$@"
|
||||
|
||||
informergen_internal_apis=(
|
||||
$(
|
||||
cd ${KUBE_ROOT}
|
||||
find pkg/apis -maxdepth 2 -name types.go | xargs -n1 dirname | sort
|
||||
mapfile -t informergen_internal_apis < <(
|
||||
cd "${KUBE_ROOT}"
|
||||
sort <(find pkg/apis -maxdepth 2 -name types.go -exec dirname {} \;)
|
||||
)
|
||||
)
|
||||
informergen_internal_apis=(${informergen_internal_apis[@]/#/k8s.io/kubernetes/})
|
||||
informergen_internal_apis=("${informergen_internal_apis[@]/#/k8s.io/kubernetes/}")
|
||||
informergen_internal_apis_csv=$(IFS=,; echo "${informergen_internal_apis[*]}")
|
||||
${informergen} \
|
||||
--input-dirs "${informergen_internal_apis_csv}" \
|
||||
@ -108,12 +110,10 @@ ${informergen} \
|
||||
--go-header-file ${KUBE_ROOT}/hack/boilerplate/boilerplate.go.txt \
|
||||
"$@"
|
||||
|
||||
informergen_external_apis=(
|
||||
$(
|
||||
cd ${KUBE_ROOT}/staging/src
|
||||
# because client-gen doesn't do policy/v1alpha1, we have to skip it too
|
||||
find k8s.io/api -name types.go | xargs -n1 dirname | sort | grep -v pkg.apis.policy.v1alpha1
|
||||
)
|
||||
mapfile -t informergen_external_apis < <(
|
||||
cd "${KUBE_ROOT}/staging/src"
|
||||
# because client-gen doesn't do policy/v1alpha1, we have to skip it too
|
||||
sort <(find k8s.io/api -name types.go -exec dirname {} \;) | grep -v pkg.apis.policy.v1alpha1
|
||||
)
|
||||
|
||||
informergen_external_apis_csv=$(IFS=,; echo "${informergen_external_apis[*]}")
|
||||
|
Loading…
Reference in New Issue
Block a user