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

Retrieve error handling #453

Merged
merged 3 commits into from
Jul 9, 2018

Conversation

liztio
Copy link
Contributor

@liztio liztio commented Jun 27, 2018

What this PR does / why we need it:
Right now sonobuoy retrieve provides very bad error handling. This improves it:

$ sonobuoy retrieve
error retrieving results: error sending request: Post https://liz-k8s-liz-d22b5dmgmt.eastus.cloudapp.azure.com/api/v1/namespaces/heptio-sonobuoy/pods/sonobuoy/exec?command=%2Fusr%2Fbin%2Fenv&command=bash&command=-c&command=tar+cf+-+%2Ftmp%2Fsonobuoy%2F%2A.tar.gz&container=kube-sonobuoy&container=kube-sonobuoy&stdout=true: dial tcp: lookup liz-k8s-liz-d22b5dmgmt.eastus.cloudapp.azure.com: no such host
zsh: exit 2     sonobuoy retrieve
$ sonobuoy retrieve
Results not ready yet. Check `sonobuoy status` for status.
zsh: exit 1     sonobuoy retrieve

Which issue(s) this PR fixes

Special notes for your reviewer:

Release note:

better sonobuoy retrieve error handling
client.Retrieve returns error channel

@liztio liztio requested a review from chuckha June 27, 2018 20:10
@liztio liztio force-pushed the retrieve-error-handling branch 4 times, most recently from 673bbcb to f82915b Compare June 27, 2018 20:20
@timothysc timothysc self-requested a review June 27, 2018 21:30
@timothysc timothysc self-assigned this Jun 27, 2018
@timothysc timothysc added the lifecycle/triage Needs reproduction/decisions before advancing label Jun 28, 2018
@timothysc timothysc added this to the v1.11-upstream sync milestone Jun 28, 2018
@timothysc timothysc added lifecycle/consideration Requires discussion before advancing and removed lifecycle/consideration Requires discussion before advancing labels Jun 28, 2018
Copy link
Contributor

@chuckha chuckha left a comment

Choose a reason for hiding this comment

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

one question; one change request. Overall looks good though!

}, scheme.ParameterCodec)
executor, err := remotecommand.NewSPDYExecutor(c.RestConfig, "POST", req.URL())
if err != nil {
return nil, err
ec <- err
return nil, ec
}
reader, writer := io.Pipe()
go func(writer *io.PipeWriter) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should be consistent with passing vars into this func. we should either pass the ec chan error into this func or take out writer. I prefer passing it in to make it explicit, but it doesn't really matter since this isn't in a for loop.

@@ -34,10 +32,19 @@ import (
"k8s.io/client-go/tools/remotecommand"
)

func (c *SonobuoyClient) RetrieveResults(cfg *RetrieveConfig) (io.Reader, error) {
var tarCommand = []string{
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to wrap this call with bash -c?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because the sh execution doesn't handle the * globbing

Copy link
Contributor

Choose a reason for hiding this comment

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

were you running into issues with the existing code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. If you ran the command before sonobuoy had finished running, it would tar up and retrieve a temporary directory that didn't have anything useful in it. Users had to detect if the untarred file ended in .tar.gz to determine if it was successful.

Copy link
Contributor

@timothysc timothysc left a comment

Choose a reason for hiding this comment

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

We're changing the contract so we should be explicit on the behavior we are expecting and desire.

fmt.Sprintf("tar cf - %s/*.tar.gz", config.MasterResultsPath),
}

func (c *SonobuoyClient) RetrieveResults(cfg *RetrieveConfig) (io.Reader, <-chan error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

From a client perspective, the channel makes the signature appear non-blocking, when we indeed do want the function to be blocking with a possible list of errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can't really be blocking if we want to keep the io.Reader contract. In the correct case, the error code isn't available until after execution is completed. In the error case, it could be an arbitrary amount of time (10 or more seconds) until we get the report of the status code.

Copy link
Contributor

@timothysc timothysc Jul 9, 2018

Choose a reason for hiding this comment

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

I don't mind blocking for (X) with a ctx arg provided, that is standard go. Otherwise, we need to revisit the whole interface.

Signed-off-by: liz <liz@heptio.com>
sonobuoy retrieve now has better, more user-friendly error handling

closes vmware-tanzu#407

Signed-off-by: liz <liz@heptio.com>
Copy link
Contributor

@timothysc timothysc left a comment

Choose a reason for hiding this comment

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

/lgtm - thanks for the walk through.

@timothysc timothysc merged commit 3d46d23 into vmware-tanzu:master Jul 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/triage Needs reproduction/decisions before advancing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make 'sonobuoy retrieve' cli command aware if tarball is available or not
3 participants