Skip to content

Namespaced Client unable to List non-namespaced objects #3347

@fishmoose

Description

@fishmoose

In the List function, the client's namespace is appended to the ListOptions regardless of the scope of the objects:

if n.namespace != "" {
opts = append(opts, InNamespace(n.namespace))
}

This makes it unusable with objects that have a cluster-wide scope, as it will never find anything.

It is also inconsistent with the Get implementation, where there is a check if the object is namepaced or not, before setting the namespace:

isNamespaceScoped, err := n.IsObjectNamespaced(obj)
if err != nil {
return fmt.Errorf("error finding the scope of the object: %w", err)
}
if isNamespaceScoped {
if key.Namespace != "" && key.Namespace != n.namespace {
return fmt.Errorf("namespace %s provided for the object %s does not match the namespace %s on the client", key.Namespace, obj.GetName(), n.namespace)
}
key.Namespace = n.namespace
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions