-
Notifications
You must be signed in to change notification settings - Fork 345
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,6 @@ import ( | |
"path" | ||
"path/filepath" | ||
|
||
"github.com/sirupsen/logrus" | ||
|
||
"github.com/heptio/sonobuoy/pkg/config" | ||
"github.com/pkg/errors" | ||
|
||
|
@@ -34,10 +32,19 @@ import ( | |
"k8s.io/client-go/tools/remotecommand" | ||
) | ||
|
||
func (c *SonobuoyClient) RetrieveResults(cfg *RetrieveConfig) (io.Reader, error) { | ||
var tarCommand = []string{ | ||
"/usr/bin/env", | ||
"bash", | ||
"-c", | ||
fmt.Sprintf("tar cf - %s/*.tar.gz", config.MasterResultsPath), | ||
} | ||
|
||
func (c *SonobuoyClient) RetrieveResults(cfg *RetrieveConfig) (io.Reader, <-chan error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
ec := make(chan error, 1) | ||
client, err := c.Client() | ||
if err != nil { | ||
return nil, err | ||
ec <- err | ||
return nil, ec | ||
} | ||
restClient := client.CoreV1().RESTClient() | ||
req := restClient.Post(). | ||
|
@@ -48,34 +55,30 @@ func (c *SonobuoyClient) RetrieveResults(cfg *RetrieveConfig) (io.Reader, error) | |
Param("container", config.MasterContainerName) | ||
req.VersionedParams(&corev1.PodExecOptions{ | ||
Container: config.MasterContainerName, | ||
Command: []string{"tar", "cf", "-", config.MasterResultsPath}, | ||
Command: tarCommand, | ||
Stdin: false, | ||
Stdout: true, | ||
Stderr: true, | ||
Stderr: false, | ||
}, 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) { | ||
go func(writer *io.PipeWriter, ec chan error) { | ||
defer writer.Close() | ||
defer close(ec) | ||
err = executor.Stream(remotecommand.StreamOptions{ | ||
Stdout: writer, | ||
Stderr: os.Stderr, | ||
Tty: false, | ||
}) | ||
if err != nil { | ||
// Since this function returns an io.Reader to the consumer and does | ||
// not buffer the entire (potentially large) output, RetrieveResults | ||
// has to return the reader first to be read from. This means we | ||
// either lose this error (easy) or provide a significantly more | ||
// complex error mechanism for the consumer (hard). | ||
logrus.Error(err) | ||
ec <- err | ||
} | ||
}(writer) | ||
}(writer, ec) | ||
|
||
return reader, nil | ||
return reader, ec | ||
} | ||
|
||
/** Everything below this marker has been copy/pasta'd from k8s/k8s. The only modification is exporting UntarAll **/ | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
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
?There was a problem hiding this comment.
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*
globbingThere was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.