Skip to content

Conversation

@chrisseto
Copy link
Contributor

client.Client and kube.Ctl treated namespace (client.InNamespace) as an optional parameter. If not provided, it default to "default".

This parameter has been missed multiple times across various places in our codebase and resulted in latent errors, often because tests utilised the default namespace.

This commit changes the signature of Ctl.List to require a namespace string parameter to make it impossible to forget. It additionally adds it to a few places (lifecycle client) that it was previously forgotten.

`client.Client` and `kube.Ctl` treated `namespace` (`client.InNamespace`) as an
optional parameter. If not provided, it default to `"default"`.

This parameter has been missed multiple times across various places in our
codebase and resulted in latent errors, often because tests utilised the
default namespace.

This commit changes the signature of `Ctl.List` to require a `namespace string`
parameter to make it impossible to forget. It additionally adds it to a few
places (lifecycle client) that it was previously forgotten.
// var pods corev1.PodList
// ctl.List(ctx, &pods)
func (c *Ctl) List(ctx context.Context, objs ObjectList, opts ...client.ListOption) error {
func (c *Ctl) List(ctx context.Context, namespace string, objs ObjectList, opts ...client.ListOption) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with this, but wondering, does it make more sense to reverse the order of objs and namespace to be a bit more consistent with the top-level package List?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO this is consistent? It follows:

// struct methods
(c *Ctl) Blah(context.Context, RequireArgs, Object/Generic, Options...)

// generics
Blah[T](context.Context, *Ctl, RequireArgs, Options...)

// Get
(c *Ctl) Get(context.Context, ObjectKey, Object)
Get[T](context.Context, ObjectKey)

// List
(c *Ctl) List(context.Context, Namespace, ObjectList, Options...)
List[T](context.Context, Namespace, Options...)

The inclusion of Options isn't super consistent and the All methods are a bit weird to support a variadic list of objects 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, maybe the generic methods should have had ctl first in hindsight.

Get[T](*Ctl, context.Context, ObjectKey)

@chrisseto chrisseto merged commit 9e08d14 into main Oct 1, 2025
15 of 16 checks passed
@github-actions
Copy link

github-actions bot commented Oct 1, 2025

💚 All backports created successfully

Status Branch Result
release/v2.4.x
release/v25.1.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation and see the Github Action logs for details

@chrisseto chrisseto deleted the chris/p/kube-list-ns branch October 1, 2025 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants