Skip to content

fix(k8s): k8s lint reads folder sources with no namespace #7899

Backlog

Description

@dan-petty

Problem

devops k8s lint gives the destination namespace of an Application to its chart renders only (#7889). A path source with no kustomization, whose object names no namespace, reaches kube-linter with none. A chart pod in the destination namespace then does not match that ServiceAccount or NetworkPolicy, and kube-linter reports it as missing.

Reproduction

kube-linter 0.8.3 on a folder with a ServiceAccount web that names no namespace and a Deployment of namespace web that names it reports serviceAccount "web" not found (check: non-existent-service-account).

Expected behavior

Each namespaced object of a path source that names no namespace takes the destination namespace of its Application, as Argo CD applies it. A path source that the lint passes today still passes.

Notes

The step of the chart renders, a kubectl kustomize build with a NamespaceTransformer, does not fit a folder with no kustomization: the build fails on a YAML file that is no manifest ("missing Resource metadata"), on two objects with one kind, namespace and name ("may not add resource with an already registered id") and on an object with generateName ("missing metadata.name"). Measured with Kustomize 5.8.1.

On the environment tree of dan-petty/homelab at 795c247, each path object with no namespace was of a cluster-scoped kind, so no finding there comes from this.

Existing Tool Considered

Kustomize sets the namespace of chart renders. It refuses the files above, so the plan must name how a folder source gets the namespace. No tool is built here.

New findings since v0.263.1

Since the chart renders take the destination namespace (#7889), a path folder with no kustomization causes findings that the lint did not report before. A chart pod now has the destination namespace, and the ServiceAccount or the NetworkPolicy of that folder has none, so a tree that passed the default lint now fails with non-existent-service-account or non-isolated-pod. With a destination that names no namespace, the chart renders get none once #7904 merges, so only a destination that names a namespace stays affected.

Measured with kube-linter 0.8.3 at commit 8f7654a: a chart with a Deployment that names the ServiceAccount web, and a folder with that ServiceAccount and a NetworkPolicy, passed at commit 1966142. The change of #7904 covers a Kustomize build of a path source, not this folder.

Alternatives check of 2026-11-30: partly.
Tool: kpt set-namespace (https://github.com/kptdev/kpt), Apache-2.0, last activity 2026-11-30, maintained.
Reason: Searches found the kpt set-namespace function. It sets the namespace of namespaced kinds in a plain folder and skips cluster-scoped kinds. It does not read the Application destination, so the caller supplies the namespace.

Covers:

  • Sets a namespace on namespaced kinds of a plain YAML folder
  • Skips cluster-scoped kinds through the OpenAPI schema
  • Transforms each resource alone, so duplicate ids and generateName pass

Lacks:

  • Takes the destination namespace as an input argument
  • Needs a function image pull from a registry
  • Needs additionalNamespacedResources for custom resource kinds
  • Does not read the Argo CD Application destination

Proposed design

Problem statement

devops k8s lint gives the destination namespace of an Argo CD Application to chart renders and to Kustomize builds of path sources only. A path source with no kustomization keeps no namespace on its built-in namespaced objects. A chart pod in the destination namespace then does not match the ServiceAccount or NetworkPolicy of the folder. The lint reports a missing ServiceAccount or an isolated pod. The change sets the destination namespace on the built-in namespaced objects of such a path source, as Argo CD applies it. Custom resource kinds are deferred to a new issue.

Acceptance criteria

Requirement: Folder source namespace

devops k8s lint SHALL set the destination namespace of an Argo CD Application on each built-in namespaced object of a path source with no kustomization that names no namespace.

Scenario: ServiceAccount in a folder source

  • WHEN The gate test writes an Application with destination namespace web and a path folder with no kustomization.yaml that holds a ServiceAccount web with no namespace and a Deployment in namespace web that names it.
  • THEN uv run pytest tests/gate/k8s_checks/destination_namespace.py -k folder_source passes and the built ServiceAccount has metadata.namespace: web.

Requirement: Explicit namespace

devops k8s lint MUST keep a namespace that a built-in namespaced object of a path source sets.

Scenario: Explicit namespace differs from the destination

  • WHEN The gate test writes an Application with destination namespace web and a path folder that holds a ServiceAccount web in namespace other and a Deployment in namespace other that names it.
  • THEN uv run pytest tests/gate/k8s_checks/destination_namespace.py -k explicit_namespace passes and the built ServiceAccount has metadata.namespace: other.

Requirement: Cluster-scoped kind

devops k8s lint MUST NOT add a namespace to a cluster-scoped kind of a path source.

Scenario: ClusterRole in a folder source

  • WHEN The gate test writes an Application with destination namespace web and a path folder that holds a ClusterRole with no namespace.
  • THEN uv run pytest tests/gate/k8s_checks/destination_namespace.py -k cluster_scoped passes and the built ClusterRole has no metadata.namespace.

Requirement: Non-manifest YAML

devops k8s lint MUST skip a YAML file in a path source that is no Kubernetes manifest.

Scenario: YAML file with no manifest fields

  • WHEN The gate test writes a path folder with a YAML file that has no apiVersion or kind and a valid ServiceAccount.
  • THEN uv run pytest tests/gate/k8s_checks/destination_namespace.py -k non_manifest passes and the lint reports no parse error for that file.

Requirement: Duplicate ids and generateName

devops k8s lint MUST process a path source that holds two objects with one kind, namespace and name, and an object with generateName.

Scenario: Duplicate ids and generateName

  • WHEN The gate test writes a path folder with two ConfigMaps with the same name and a Pod with generateName.
  • THEN uv run pytest tests/gate/k8s_checks/destination_namespace.py -k duplicate_ids passes and the lint reports no already registered id or missing metadata.name error.

Requirement: No destination namespace

devops k8s lint MUST NOT add a namespace to a path source when the Argo CD Application destination names no namespace.

Scenario: Empty destination namespace

  • WHEN The gate test writes an Application with no destination namespace and a path folder that holds a ServiceAccount with no namespace.
  • THEN uv run pytest tests/gate/k8s_checks/destination_namespace.py -k empty_destination passes and the built ServiceAccount has no metadata.namespace.

Requirement: NetworkPolicy in a folder source

devops k8s lint SHALL set the destination namespace on a NetworkPolicy of a path source with no kustomization that names no namespace.

Scenario: NetworkPolicy with no namespace

  • WHEN The gate test writes an Application with destination namespace web and a path folder that holds a NetworkPolicy with no namespace.
  • THEN uv run pytest tests/gate/k8s_checks/destination_namespace.py -k network_policy passes and the built NetworkPolicy has metadata.namespace: web.

Requirement: Existing path sources

devops k8s lint MUST keep the findings of a path source that it passes today.

Scenario: Existing path source cases

  • WHEN The gate test file tests/gate/k8s_checks/destination_namespace.py runs.
  • THEN uv run pytest tests/gate/k8s_checks/destination_namespace.py passes.

Existing Tool Considered

The alternatives check in the issue body records the verdict partly for kpt set-namespace (https://github.com/kptdev/kpt). The block lists what the tool covers and lacks. The plan reads the destination namespace from the Application and supplies it. It selects only Kubernetes manifest documents and keeps explicit namespaces. It pins the set-namespace function image by digest and pre-pulls it in the Static Analysis job. It adds the kpt binary to the devtools image, builds no namespace transformer, and defers custom resource kinds to a new issue.

Key questions

  • Which open tool sets a namespace on namespaced kinds of a plain YAML folder?: Use kpt set-namespace. The alternatives check in the issue body records the verdict partly for kpt set-namespace. It sets the namespace on namespaced kinds of a plain YAML folder and skips cluster-scoped kinds. The lint reads the destination namespace from the Application and supplies it. The plan pins the set-namespace function image by digest. The plan builds no namespace transformer. (best practice) [sources: AGENTS.md:9]
    • Chosen: kpt set-namespace. It is open and maintained. It sets the namespace on namespaced kinds of a plain YAML folder and skips cluster-scoped kinds.
    • Rejected: Kustomize NamespaceTransformer. Kustomize 5.8.1 fails on a folder with no kustomization on non-manifest YAML, duplicate ids and generateName.
    • Rejected: A new YAML namespace transformer. kpt set-namespace covers the transform, and AGENTS.md rule 3 prefers an open tool.
  • How does the lint give the destination namespace to a folder source?: The lint reads the destination namespace from the Application with _destination_namespace. It selects the manifest documents of the path source. It calls kpt set-namespace with that namespace. It does not run a Kustomize build for a source with no kustomization. (best practice) [sources: src/devops_cli/k8s/image_pins.py:394, src/devops_cli/k8s/image_pins.py:442]
    • Chosen: Read the Application destination and call kpt. The lint already reads the destination for chart renders and Kustomize path sources. kpt lacks the Application read.
    • Rejected: Run a Kustomize build. The issue notes show that Kustomize 5.8.1 fails on the folder files.
    • Rejected: Add a namespace transformer. kpt set-namespace covers the transform.
  • How does the lint keep an explicit namespace on an object of a folder source?: The lint filters the objects before the kpt call. It passes only namespaced objects that have no namespace. An object with an explicit namespace stays unchanged. (best practice) [sources: tests/gate/k8s_checks/destination_namespace.py, src/devops_cli/k8s/image_pins.py:394]
    • Chosen: Filter objects before the kpt call. The alternatives block does not state that kpt keeps an explicit namespace. The filter keeps the result of the Kustomize path build.
    • Rejected: Rely on kpt to keep an explicit namespace. The alternatives block gives no such coverage.
    • Rejected: Write a namespace transformer. kpt set-namespace covers the transform.
  • How does the lint keep a YAML file that is no Kubernetes manifest from stopping the namespace step?: The lint selects only YAML documents that have apiVersion and kind. It leaves other documents unchanged. It does not pass a non-manifest YAML file to kpt. (best practice) [sources: src/devops_cli/k8s/template.py, CHANGELOG.md:7452]
    • Chosen: Select manifest documents. The folder build reads every YAML file as text. The issue notes show that Kustomize fails on a YAML file that is no manifest.
    • Rejected: Pass the whole folder to kpt. The alternatives block does not state that kpt skips a non-manifest YAML file.
  • What namespace does a folder source get when the Application destination names no namespace?: The lint adds no namespace. It makes no kpt call when the destination names none. (best practice) [sources: tests/gate/k8s_checks/destination_namespace.py, src/devops_cli/k8s/image_pins.py:394]
    • Chosen: Add no namespace. The issue says only a destination that names a namespace stays affected.
    • Rejected: Add the default namespace. It would change objects that Argo CD applies with no destination namespace.
  • How does the lint get the kpt binary and the set-namespace function image?: The plan adds the kpt binary to the devtools-bin stage of the devtools image. The Static Analysis job copies it with the other tools and already uses Docker. The plan pins the set-namespace function image by digest and pre-pulls it in that job. The lint call uses the local image. The work waits on a published devtools image that includes kpt. (best practice) [sources: .github/workflows/ci.yml:90, .github/workflows/devcontainer-image.yml]
    • Chosen: Add kpt to the devtools image. The CI job copies each tool from the pinned devtools image, and the devtools-bin stage holds the commands.
    • Rejected: Pull kpt at each lint run. It adds a network step and a version that no pin holds.
    • Rejected: Build a namespace transformer. kpt set-namespace covers the transform, and AGENTS.md rule 3 prefers an open tool.

Fit

Fits in one pull request.

Suspected block

A published devtools image that includes the kpt binary must exist before the Static Analysis job can run the lint with kpt.

Dependencies

None.

Watched files

A commit on the default branch that changes one of these files starts the next refine round.

  • .github/workflows/ci.yml
  • .github/workflows/devcontainer-image.yml

Activity

  1. added
    type/bug
    scope/k8s
    source/agent
    status/new
    value/medium
    effort/medium
    priority/p2-medium
    on Nov 30, 2026
  2. added
    priority/p1-high
    and removed
    priority/p2-medium
    on Nov 30, 2026
  3. devops-cli-service commented on Nov 30, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (10)

    Tools considered:

    Searches run:

    • kpt fn set-namespace function namespaced resources openapi, results: 5
    • tool set namespace on Kubernetes YAML manifests without kustomization, skip cluster-scoped resources, results: 5
    • kpt set-namespace kpt fn eval, results: 5
    • kyverno cli apply mutate add namespace to manifests, results: 5
    • kpt, results: 5
    • kube-linter non-existent-service-account namespace folder source, results: 5
    • kubernetes yaml tool add namespace to namespaced resources only openapi scope, results: 5
    • kpt fn eval set-namespace additionalNamespacedResources, results: 5
    • krm function set-namespace kpt-functions-catalog set namespace on namespaced resources, results: 5
    • kyverno, results: 5

    Sources:

  4. devops-cli-service commented on Dec 1, 2026

    @devops-cli-service
    Contributor

    Owner question: See Suspected block and Watched files in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  5. devops-cli-service commented on Dec 1, 2026

    @devops-cli-service
    Contributor

    Owner question: See Suspected block and Watched files in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p1-highscope/k8ssource/agentstatus/newtype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions