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

[kubernetes] improve parsing namespaces #1442

Conversation

pmoravec
Copy link
Contributor

@pmoravec pmoravec commented Oct 3, 2018

Handle (theoretical) cases when "kubectl get namespace" returns a line with
white characters only, and prevent IndexError to be raised.

Resolves: #1442

Signed-off-by: Pavel Moravec pmoravec@redhat.com


Please place an 'X' inside each '[]' to confirm you adhere to our Contributor Guidelines

  • Is the commit message split over multiple lines and hard-wrapped at 72 characters?
  • Is the subject and message clear and concise?
  • Does the subject start with [plugin_name] if submitting a plugin patch or a [section_name] if part of the core sosreport code?
  • Does the commit contain a Signed-off-by: First Lastname email@example.com?

@pmoravec
Copy link
Contributor Author

pmoravec commented Oct 3, 2018

This is rather improvement of theoretical situation when kubectl returns some error output like:

Error: unknown flag: --config\n\n\nExamples:\n  # List all pods in ps output format.\n  kubectl get pods\n  \n  # List all pods in ps output format with more information (such as node name).\n  kubectl get pods -o wide\n  \n..'

Then parsing the lines '\n \n' raises the exception.

knsps = [n.split()[0] for n in kn['output'].splitlines()[1:] if n]
# namespace is the 1st word on line, until the line has spaces only
knsps = [n.split()[0] for n in kn['output'].splitlines()[1:]
if n and len(n.split())]
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this might be more readable as:

    kn_output = kn['output'].splitlines()[1:]
    knsps = [n.split()[0] for n in kn_output if n and len(n.split())]

70 chars on the long line... I don't know, but that hanging if really confused my eyes for a moment on the first look.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point for more code clarity there, updating the PR..

Handle (theoretical) cases when "kubectl get namespace" returns a line with
white characters only, and prevent IndexError to be raised.

Resolves: sosreport#1442

Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
@pmoravec pmoravec force-pushed the sos-pmoravec-kubernetes-kubectl-namespaces-line-with-spaces-only branch from 926c1b0 to cacca69 Compare March 12, 2019 21:04
@bmr-cymru bmr-cymru closed this in 71d6cf9 Mar 18, 2019
@bmr-cymru bmr-cymru added this to the 3.7 milestone Mar 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants