feat: provide container logs on container startup failures #1297
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR adds 3 things:
it extract the logic to start the wait strategies from the Start container method to the default life cycle hooks, as the first PostStart function.
it adds the string representation of the wait strategy struct to the log, using the
%+v
formatter, which will add fields and values. I'm doing it in this manner for simplicity: to avoid adding a String method to all the wait strategies, with custom output message. But I'm OK if we want to do that in this PR or in a follow up one.The
c.printLogs
method will be called on any failure occurring at both the Starting and Started hooks: we have access to the container here, so we can get its logs.Why is it important?
Many times the container fails the wait strategy and the user does not have feedback on why. Printing the logs will help them troubleshoot any error at that time.
Related issues
Follow-ups
We could implement the Stringer interface in all the existing wait strategies, adding custom and explicit info for each. Nowadays, with the current proposal, the pointer types will be printed as their memory representation (e.g. timeout, which TBH I do not know why it's a pointer)
Another follow-up would be adding the print container logs on the rest of hooks where we have access to a running container: stopping/stopped/terminating/terminated 🤔 . I can do it in this PR if needed