-
Notifications
You must be signed in to change notification settings - Fork 585
Add options to GetContainerLogs #12527
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
Add options to GetContainerLogs #12527
Conversation
Signed-off-by: sheidkamp <[email protected]>
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.
Pull Request Overview
Adds a variadic options mechanism to GetContainerLogs to allow passing kubectl log flags (container, since, since-time, tail) and introduces helper utilities and tests for building those arguments.
- Introduces LogOption pattern and BuildLogArgs/FormatSinceTime helpers.
- Modifies GetContainerLogs signature to accept optional LogOption values.
- Adds unit tests for argument construction (individual and combined cases).
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
pkg/utils/kubeutils/kubectl/logs_options.go | Adds LogOption implementations and argument builder for kubectl logs flags. |
pkg/utils/kubeutils/kubectl/logs_options_test.go | Adds tests for BuildLogArgs and time formatting helpers. |
pkg/utils/kubeutils/kubectl/cli.go | Extends GetContainerLogs to accept variadic log options and forwards them to Execute. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Signed-off-by: sheidkamp <[email protected]>
pkg/utils/kubeutils/kubectl/cli.go
Outdated
} | ||
|
||
// GetContainerLogsWithOptions retrieves the logs for the specified container with the specified options | ||
func (c *Cli) GetContainerLogsWithOptions(ctx context.Context, namespace string, name string, options ...LogOption) (string, error) { |
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.
since options
is optional, looks like you could just add the new arg to the existing GetContainerLogs
function instead of defining a new func
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.
technically a breaking change (if the type is being used anywhere), but reverted to avoid cruft
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.
Talked offline, but just to document it here: ok, I saw copilot's comment above that it could be a breaking change. Since this is only used in tests, and it doesn't break any of the current callers, I would suggest ignoring copilot and just adding the arg to the existing func.
Also (doesn't need to be done in this PR) it would be good to move the func to a pkg under test/
since it's only used in tests
Signed-off-by: sheidkamp <[email protected]>
0e5923e
to
f9f5312
Compare
Signed-off-by: sheidkamp <[email protected]>
Description
I am using the kubeutils as a library in another repo, and would like to be able to pass options (specifically
since-time
) to GetContainerLogs.While implementing the changes, added a few more options that may be useful in a testing context:
Change Type
Select one or more of the following by including the corresponding slash-command:
Changelog
Additional Notes