Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not crash on empty NODE_NAMES array. #55682

Merged
merged 1 commit into from
Nov 16, 2017

Conversation

porridge
Copy link
Member

Which issue(s) this PR fixes:
Fixes #55675

Release note:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Nov 14, 2017
@porridge
Copy link
Member Author

porridge commented Nov 14, 2017 via email

@xiangpengzhao
Copy link
Contributor

/test pull-kubernetes-e2e-kops-aws

@@ -232,7 +232,7 @@ function dump_nodes() {
else
echo "Detecting nodes in the cluster"
detect-node-names &> /dev/null
node_names=( "${NODE_NAMES[@]}" )
node_names=( "${NODE_NAMES[@]:+${NODE_NAMES[@]}}" )
Copy link
Member

@shyamjvs shyamjvs Nov 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is making the script hard to understand. Instead of changes like this here and below, I guess you can simply do the following:

if [[ -n "${NODE_NAMES:-}" ]]; then
  node_names=( "${NODE_NAMES[@]}" )
fi

The code further should handle the case that node_names is empty.

@@ -306,7 +306,7 @@ function dump_nodes_with_logexporter() {
if ! "${KUBECTL}" create -f "${KUBE_ROOT}/cluster/log-dump/logexporter-daemonset.yaml"; then
echo "Failed to create logexporter daemonset.. falling back to logdump through SSH"
"${KUBECTL}" delete namespace "${logexporter_namespace}" || true
dump_nodes "${NODE_NAMES[@]}"
dump_nodes "${NODE_NAMES[@]:+${NODE_NAMES[@]}}}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here also, instead of making this change at 3 places inside the function. I would suggest changing the above condition in L286 to:

if [[ -z "${NODE_NAMES:-}" ]]; then
  echo "No nodes found!"
  return
fi

@porridge
Copy link
Member Author

Simplified.
These later checks were actually redundant, removed them.
PTAL
Holding for squash.
/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 14, 2017
@@ -232,7 +232,9 @@ function dump_nodes() {
else
echo "Detecting nodes in the cluster"
detect-node-names &> /dev/null
node_names=( "${NODE_NAMES[@]}" )
if (( ${#NODE_NAMES[@]} )); then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also change similar if condition inside dump_nodes_with_logexporter().

@porridge
Copy link
Member Author

squashed
/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 14, 2017
@porridge
Copy link
Member Author

porridge commented Nov 14, 2017 via email

@shyamjvs
Copy link
Member

/lgtm

@zmerlynn / @roberthbailey Could one of you please approve the PR?

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 14, 2017
@roberthbailey
Copy link
Contributor

/approve

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: porridge, roberthbailey, shyamjvs

Associated issue: 55675

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 14, 2017
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to @fejta).

Review the full test history for this PR.

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Nov 16, 2017

@porridge: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-kubernetes-unit 310ab8c link /test pull-kubernetes-unit

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 55682, 55444, 55456, 55717, 55131). If you want to cherry-pick this change to another branch, please follow the instructions here.

1 similar comment
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 55682, 55444, 55456, 55717, 55131). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit c523459 into kubernetes:master Nov 16, 2017
@porridge porridge deleted the unset-array branch December 28, 2017 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cluster/log-dump/log-dump.sh: line 235: NODE_NAMES[@]: unbound variable
8 participants