Unverified Commit fb5caac2 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

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 ```
parents b22e9a02 6beb1dda
...@@ -51,7 +51,7 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. ...@@ -51,7 +51,7 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/hack/lib/init.sh" source "${KUBE_ROOT}/hack/lib/init.sh"
server_addr="" server_addr=""
kubelet_addreses="" kubelet_addresses=""
kubelet_binary="" kubelet_binary=""
master_binary="" master_binary=""
scheduler_binary="" scheduler_binary=""
...@@ -97,7 +97,7 @@ while true; do ...@@ -97,7 +97,7 @@ while true; do
--master-binary) --master-binary)
shift shift
if [ -z "$1" ]; then if [ -z "$1" ]; then
>&2 echo "empty argumet to --master-binary flag" >&2 echo "empty argument to --master-binary flag"
exit 1 exit 1
fi fi
master_binary=$1 master_binary=$1
...@@ -111,16 +111,16 @@ while true; do ...@@ -111,16 +111,16 @@ while true; do
shift shift
profile_components="kubelet ${profile_components}" profile_components="kubelet ${profile_components}"
if [ -z "$1" ]; then if [ -z "$1" ]; then
>&2 echo "empty argumet to --kubelet flag" >&2 echo "empty argument to --kubelet flag"
exit 1 exit 1
fi fi
kubelet_addreses="$1 $kubelet_addreses" kubelet_addresses="$1 $kubelet_addresses"
shift shift
;; ;;
--kubelet-binary) --kubelet-binary)
shift shift
if [ -z "$1" ]; then if [ -z "$1" ]; then
>&2 echo "empty argumet to --kubelet-binary flag" >&2 echo "empty argument to --kubelet-binary flag"
exit 1 exit 1
fi fi
kubelet_binary=$1 kubelet_binary=$1
...@@ -133,7 +133,7 @@ while true; do ...@@ -133,7 +133,7 @@ while true; do
--scheduler-binary) --scheduler-binary)
shift shift
if [ -z "$1" ]; then if [ -z "$1" ]; then
>&2 echo "empty argumet to --scheduler-binary flag" >&2 echo "empty argument to --scheduler-binary flag"
exit 1 exit 1
fi fi
scheduler_binary=$1 scheduler_binary=$1
...@@ -142,7 +142,7 @@ while true; do ...@@ -142,7 +142,7 @@ while true; do
--scheduler-port) --scheduler-port)
shift shift
if [ -z "$1" ]; then if [ -z "$1" ]; then
>&2 echo "empty argumet to --scheduler-port flag" >&2 echo "empty argument to --scheduler-port flag"
exit 1 exit 1
fi fi
scheduler_port=$1 scheduler_port=$1
...@@ -155,7 +155,7 @@ while true; do ...@@ -155,7 +155,7 @@ while true; do
--controller-manager-binary) --controller-manager-binary)
shift shift
if [ -z "$1" ]; then if [ -z "$1" ]; then
>&2 echo "empty argumet to --controller-manager-binary flag" >&2 echo "empty argument to --controller-manager-binary flag"
exit 1 exit 1
fi fi
controller_manager_binary=$1 controller_manager_binary=$1
...@@ -164,10 +164,10 @@ while true; do ...@@ -164,10 +164,10 @@ while true; do
--controller-manager-port) --controller-manager-port)
shift shift
if [ -z "$1" ]; then if [ -z "$1" ]; then
>&2 echo "empty argumet to --controller-manager-port flag" >&2 echo "empty argument to --controller-manager-port flag"
exit 1 exit 1
fi fi
controller-managerr_port=$1 controller_manager_port=$1
shift shift
;; ;;
-o|--output) -o|--output)
...@@ -240,18 +240,18 @@ if [[ -z "${requested_profiles}" ]]; then ...@@ -240,18 +240,18 @@ if [[ -z "${requested_profiles}" ]]; then
exit 1 exit 1
fi 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..." 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") 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" EXIT
kube::util::trap_add 'kill $SSH_PID' SIGTERM kube::util::trap_add "kill $SSH_PID" SIGTERM
requested_profiles=$(echo ${requested_profiles} | 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) 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) kubelet_addresses=$(echo "${kubelet_addresses}" | xargs -n1 | LC_ALL=C sort -u | xargs)
echo "requested profiles: ${requested_profiles}" echo "requested profiles: ${requested_profiles}"
echo "flags for heap profile: ${mem_pprof_flags}" echo "flags for heap profile: ${mem_pprof_flags}"
...@@ -291,7 +291,7 @@ for component in ${profile_components}; do ...@@ -291,7 +291,7 @@ for component in ${profile_components}; do
esac esac
if [[ "${component}" == "kubelet" ]]; then 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}" grab_profiles_from_component "${requested_profiles}" "${mem_pprof_flags}" "${binary}" "${tunnel_port}" "${path}/${node}" "${output_dir}/${component}" "${timestamp}"
done done
else else
......
...@@ -38,7 +38,7 @@ informergen=$(kube::util::find-binary "informer-gen") ...@@ -38,7 +38,7 @@ informergen=$(kube::util::find-binary "informer-gen")
# that generates the set-gen program. # that generates the set-gen program.
# #
GROUP_VERSIONS=(${KUBE_AVAILABLE_GROUP_VERSIONS}) IFS=" " read -ra GROUP_VERSIONS <<< "$KUBE_AVAILABLE_GROUP_VERSIONS"
GV_DIRS=() GV_DIRS=()
INTERNAL_DIRS=() INTERNAL_DIRS=()
for gv in "${GROUP_VERSIONS[@]}"; do for gv in "${GROUP_VERSIONS[@]}"; do
...@@ -50,20 +50,28 @@ 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 # skip groups that aren't being served, clients for these don't matter
if [[ " ${KUBE_NONSERVER_GROUP_VERSIONS} " == *" ${gv} "* ]]; then if [[ " ${KUBE_NONSERVER_GROUP_VERSIONS} " == *" ${gv} "* ]]; then
continue continue
fi fi
GV_DIRS+=("${pkg_dir}") GV_DIRS+=("${pkg_dir}")
# collect internal groups # collect internal groups
int_group="${pkg_dir%/*}/" int_group="${pkg_dir%/*}/"
if [[ "${pkg_dir}" = core/* ]]; then 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 fi
if ! [[ " ${INTERNAL_DIRS[@]:-} " =~ " ${int_group} " ]]; then
INTERNAL_DIRS+=("${int_group}")
fi
done done
# delimit by commas for the command # delimit by commas for the command
GV_DIRS_CSV=$(IFS=',';echo "${GV_DIRS[*]// /,}";IFS=$) GV_DIRS_CSV=$(IFS=',';echo "${GV_DIRS[*]// /,}";IFS=$)
...@@ -74,32 +82,26 @@ INTERNAL_DIRS_CSV=$(IFS=',';echo "${INTERNAL_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} --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 "$@" ${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=( mapfile -t listergen_internal_apis < <(
$( cd "${KUBE_ROOT}"
cd ${KUBE_ROOT} sort <(find pkg/apis -maxdepth 2 -name types.go -exec dirname {} \;)
find pkg/apis -maxdepth 2 -name types.go | xargs -n1 dirname | sort
)
) )
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_internal_apis_csv=$(IFS=,; echo "${listergen_internal_apis[*]}")
${listergen} --input-dirs "${listergen_internal_apis_csv}" "$@" ${listergen} --input-dirs "${listergen_internal_apis_csv}" "$@"
listergen_external_apis=( mapfile -t listergen_external_apis < <(
$( cd "${KUBE_ROOT}/staging/src"
cd ${KUBE_ROOT}/staging/src sort <(find k8s.io/api -name types.go -exec dirname {} \;)
find k8s.io/api -name types.go | xargs -n1 dirname | sort
)
) )
listergen_external_apis_csv=$(IFS=,; echo "${listergen_external_apis[*]}") 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 "$@" ${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=( mapfile -t informergen_internal_apis < <(
$( cd "${KUBE_ROOT}"
cd ${KUBE_ROOT} sort <(find pkg/apis -maxdepth 2 -name types.go -exec dirname {} \;)
find pkg/apis -maxdepth 2 -name types.go | xargs -n1 dirname | sort
)
) )
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_internal_apis_csv=$(IFS=,; echo "${informergen_internal_apis[*]}")
${informergen} \ ${informergen} \
--input-dirs "${informergen_internal_apis_csv}" \ --input-dirs "${informergen_internal_apis_csv}" \
...@@ -108,12 +110,10 @@ ${informergen} \ ...@@ -108,12 +110,10 @@ ${informergen} \
--go-header-file ${KUBE_ROOT}/hack/boilerplate/boilerplate.go.txt \ --go-header-file ${KUBE_ROOT}/hack/boilerplate/boilerplate.go.txt \
"$@" "$@"
informergen_external_apis=( mapfile -t informergen_external_apis < <(
$( cd "${KUBE_ROOT}/staging/src"
cd ${KUBE_ROOT}/staging/src # because client-gen doesn't do policy/v1alpha1, we have to skip it too
# 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
find k8s.io/api -name types.go | xargs -n1 dirname | sort | grep -v pkg.apis.policy.v1alpha1
)
) )
informergen_external_apis_csv=$(IFS=,; echo "${informergen_external_apis[*]}") informergen_external_apis_csv=$(IFS=,; echo "${informergen_external_apis[*]}")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment