Navigation Menu

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

Look up sonobuoy master pod name by label #787

Merged
merged 1 commit into from Jul 2, 2019

Conversation

lander2k2
Copy link
Contributor

What this PR does / why we need it:
Currently sonobuoy always expects it's pod name to be sonobuoy.
So if you run sonobuoy with a CronJob, the controller will create a pod name
something like sonobuoy-1561584180-zrwjf and sonobuoy will fail to update
it's own status. Also the sonobuoy CLI will not find the pod if you
check status or try to retrieve results.

This change removes the statically-set sonobuoy master pod name and
looks up the pod name based on the label given to that pod:
'run=sonobuoy-master`.

This assumes that this label is always set and will fail if more than
one pod exists in the namespace with that label.

Which issue(s) this PR fixes

Special notes for your reviewer:
This PR is an alternative implementation to: #779

Release note:

Allow use of alternative pod names to enable using controllers (e.g. CronJob) to run sonobuoy scans.

Signed-off-by: Richard Lander landerr@vmware.com

@codecov-io
Copy link

codecov-io commented Jul 1, 2019

Codecov Report

Merging #787 into master will decrease coverage by 0.17%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #787      +/-   ##
==========================================
- Coverage    42.9%   42.73%   -0.18%     
==========================================
  Files          71       71              
  Lines        4165     4182      +17     
==========================================
  Hits         1787     1787              
- Misses       2272     2289      +17     
  Partials      106      106
Impacted Files Coverage Δ
pkg/plugin/aggregation/status.go 48.38% <0%> (-1.62%) ⬇️
pkg/discovery/discovery.go 0% <0%> (ø) ⬆️
pkg/plugin/aggregation/update.go 29.76% <0%> (-6.47%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c3b5afa...3245c48. Read the comment docs.

pod, err := client.CoreV1().Pods(namespace).Get(StatusPodName, metav1.GetOptions{})
if err != nil {
return nil, errors.Wrap(err, "could not retrieve sonobuoy pod")
return nil, errors.New("could not retrieve sonobuoy pod")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the change in the error? Seems like that would just obfuscate issues by not returning the actual error to the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To test this error I created a second pod with the 'run:sonobuoy-master' label in the same namespace.

This is the error if we don't make this change:

$ sonobuoy status
ERRO[0001] More than one pod with label 'run:sonobuoy-master'
ERRO[0001] error attempting to run sonobuoy: could not retrieve sonobuoy pod: pods "sonobuoy" not found

This seemed a little confusing to me b/c the user will wonder "why are you looking for a pod called 'sonobuoy' - my pod has a different name?"

This happens because the SetStatusPodName function doesn't set the pod name if there's an error and it reverts back to the default name "sonobuoy". (I'm wondering now if this was wise.)

This is the error output if we do make this change:

$ sonobuoy status
ERRO[0006] More than one pod with label 'run:sonobuoy-master'
ERRO[0006] error attempting to run sonobuoy: could not retrieve sonobuoy pod

With the both errors provided together, I think this is clearer. But open to suggestions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update for clarity: Due to other changes based on other review items...

There is no longer an error if there are multiple pods with the run:sonobuoy-master label. The first pod is selected (with a warning) and the status command runs.

If there are no pods with the label the output is now as follows:

$ sonobuoy status
ERRO[0001] No pods found with label 'run=sonobuoy-master' in namespace heptio-sonobuoy, using default pod name 'sonobuoy'
ERRO[0001] error attempting to run sonobuoy: could not retrieve sonobuoy pod

Copy link
Contributor

@johnSchnake johnSchnake left a comment

Choose a reason for hiding this comment

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

Requesting a few minor changes; otherwise I think it is great.

Thanks for the submission!

@johnSchnake
Copy link
Contributor

Looks great. I restarted the test run; it failed due to an upstream flakiness (known issue).

If you could just rebase onto master and squash down to one commit I'll merge this once it goes green on CI.

Currently sonobuoy always expects it's pod name to be sonobuoy.
So if you run sonobuoy with a CronJob, the controller will create a pod name
something like `sonobuoy-1561584180-zrwjf` and sonobuoy will fail to update
it's own status.  Also the sonobuoy CLI will not find the pod if you
check status or try to retrieve results.

This change removes the statically-set sonobuoy master pod name and
looks up the pod name based on the label given to that pod:
'run=sonobuoy-master`.

This assumes that this label is always set and will fail if the label is
not present.  If there are multiple pods with the label it will log a
warning and pick the first pod in the list returned.

Signed-off-by: Richard Lander <landerr@vmware.com>
@lander2k2
Copy link
Contributor Author

Done and done :). Thanks for reviewing!

@johnSchnake
Copy link
Contributor

💯

@johnSchnake johnSchnake self-requested a review July 2, 2019 00:37
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

3 participants