Skip to content

Conversation

sheidkamp
Copy link
Contributor

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:

  • -c/--container
  • --since
  • --since-time
  • --tail

Change Type

Select one or more of the following by including the corresponding slash-command:

/kind cleanup

Changelog

NONE

Additional Notes

@Copilot Copilot AI review requested due to automatic review settings October 6, 2025 19:54
@github-actions github-actions bot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. release-note-none labels Oct 6, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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.

@sheidkamp sheidkamp changed the title [WIP] Add options to GetContainerLogs Add options to GetContainerLogs Oct 7, 2025
}

// 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) {
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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

@sheidkamp sheidkamp force-pushed the sah/container-log-opts branch from 0e5923e to f9f5312 Compare October 7, 2025 14:15
@sheidkamp sheidkamp enabled auto-merge October 7, 2025 14:21
@sheidkamp sheidkamp added this pull request to the merge queue Oct 7, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 7, 2025
@timflannagan timflannagan added this pull request to the merge queue Oct 7, 2025
Merged via the queue into kgateway-dev:main with commit e3f4e1c Oct 7, 2025
27 checks passed
josh-pritchard pushed a commit to josh-pritchard/kgateway that referenced this pull request Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants