Skip to content

kubernetes_resources data source incorrectly defaults to "default" namespace instead of listing across all namespaces #2849

@Taiki130

Description

@Taiki130

Terraform Version, Provider Version and Kubernetes Version

Terraform version: v1.12.2
Kubernetes provider version: 2.33.0
Kubernetes version: v1.33.5

Affected Resource(s)

  • kubernetes_resources (data source)

Terraform Configuration Files

data "kubernetes_resources" "ingresses" {
  api_version = "networking.k8s.io/v1"
  kind        = "Ingress"
  # namespace not specified — expected to list across all namespaces
}

Debug Output

N/A

Panic Output

N/A

Steps to Reproduce

  1. Create Ingress resources in multiple namespaces (e.g. foo and bar)
  2. Configure kubernetes_resources data source without specifying namespace
  3. Run terraform apply
  4. Observe that only resources in the default namespace are returned

Expected Behavior

When namespace is not specified (or set to ""), the data source should return resources across all namespaces, consistent with how kubectl get ingress --all-namespaces works.

Actual Behavior

The data source only returns resources in the default namespace. This happens because manifest/provider/datasource.go explicitly overrides an empty namespace string with "default", preventing a cluster-wide list request:

if ns {
    var namespace string
    dsConfig["namespace"].As(&namespace)
    if namespace == "" {
        namespace = "default" // silently falls back to "default"
    }
    res, err = rcl.Namespace(namespace).List(ctx, listOptions)
} else {
    res, err = rcl.List(ctx, listOptions)
}

Note: cluster-scoped resources (where IsResourceNamespaced returns false) are already handled correctly via the else branch and are unaffected.

Important Factoids

This is related to the investigation in #2830, but specifically addresses the incorrect namespace filtering logic.

References

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

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