Skip to content

fix(k8s): report the workloads that no Argo CD Application manages #5480

Done

Description

@dan-petty

Problem or Motivation

k8s/README.md (GitOps) says: an object in the cluster that git does not hold is drift, so remove it or add it to git. The SRE service spec (docs/SRE.md, #5445) sets drift to 0 objects.

On 2026-11-13, 2 namespaces of a local test hold 11 Deployments that no Argo CD Application manages. A person made them on 2026-11-12. No check and no alert finds such workloads, so they stay until a person sees them. The orphan report of an AppProject (#1646) sees only the destination namespaces of that project, so it does not see a namespace outside each project.

Measured: compare the destination namespaces of kubectl -n argocd get applications with the namespaces of kubectl get deploy,statefulset,daemonset,cronjob -A. Leave out the k3s add-ons and the Applications that set the namespace of each object themselves.

Proposed Solution

  • Add a read-only check, for example to devops k8s doctor. It lists each workload that has no Argo CD tracking label or annotation and that no k3s add-on holds.
  • Ask the owner about the 2 namespaces of the local test. Then remove them, or add them to git.

Acceptance Criteria

  • A test with a fixture of cluster objects proves that the check lists an untracked Deployment. It leaves out the objects of an Application and of a k3s add-on.
  • Live proof: the check lists the 2 namespaces of the local test, and it lists none after the owner decides.

Existing Tool Considered

Argo CD marks each object that it applies with its tracking label or annotation (app.kubernetes.io/instance, or argocd.argoproj.io/tracking-id). kubectl get with a selector does the read. No new tool. Cost: about 0.3 M tokens and 2 hours.

Related

dan-petty/homelab#329.

Source: #5445

Alternatives check of 2026-11-23: covers.
Tool: guettli/konmon (https://github.com/guettli/konmon), Apache-2.0, last activity 2026-11-23, maintained.
Reason: Searches found korphan, now archived, whose rules moved to konmon: its read-only orphaned check reports resources with no Argo CD tracking label or annotation cluster-wide and skips the k3s system namespaces.

Covers:

  • Read-only cluster-wide scan for resources with no GitOps tracking
  • Honours the Argo CD instance label and tracking-id annotation
  • Skips kube-system, kube-public, kube-node-lease and k3s bootstrap objects
  • JSON output and non-zero exit for CI or cron

Lacks:

  • Separate binary, not a devops k8s doctor check
  • No fixture test inside this repository
  • Reports every orphan kind, more noise than workloads alone

Proposed design

Problem statement

Argo CD reports orphaned resources only inside the destination namespaces of an AppProject. A workload outside those namespaces stays invisible. The change adopts guettli/konmon as the orphan scanner and exposes its workload findings through devops k8s doctor.

Acceptance criteria

Requirement: Run the konmon orphaned check

The devops k8s doctor command SHALL run the orphaned check of the konmon executable that is on PATH.

Scenario: konmon on PATH

  • WHEN A test puts a fake konmon executable on PATH that records its arguments and exits 0.
  • THEN The recorded arguments contain orphaned.

Requirement: Map an orphan Deployment to a finding

The doctor report SHALL contain a finding whose resource is the kind, namespace and name of each workload in the JSON output of the konmon orphaned check.

Scenario: Orphan Deployment

  • WHEN A test puts a fake konmon on PATH that returns JSON with a Deployment in namespace apps named api.
  • THEN The doctor report contains a finding whose resource is Deployment/apps/api.

Requirement: Report each workload kind

The doctor report MUST contain a finding for each Deployment, StatefulSet, DaemonSet and CronJob in the JSON output of the konmon orphaned check.

Scenario: Four workload kinds

  • WHEN A test puts a fake konmon on PATH that returns JSON with one Deployment, one StatefulSet, one DaemonSet and one CronJob in namespace apps.
  • THEN The doctor report contains a finding for each of the four objects.

Requirement: Drop a non-workload orphan

The doctor report MUST NOT contain a finding for an orphan object whose kind is not Deployment, StatefulSet, DaemonSet or CronJob.

Scenario: Orphan Service

  • WHEN A test puts a fake konmon on PATH that returns JSON with a Service in namespace apps named api.
  • THEN The doctor report contains no finding for Service/apps/api.

Requirement: Report a missing konmon

When the konmon executable is not on PATH, the doctor report SHALL contain a finding that names konmon and MUST continue the other doctor checks.

Scenario: konmon absent

  • WHEN A test runs the doctor with a PATH that has no konmon executable and a fake kubectl that returns a healthy cluster.
  • THEN The report contains a finding that names konmon, and it contains the result of the fake kubectl check.

Requirement: Report a failed konmon run

When the konmon orphaned check exits non-zero or returns invalid JSON, the doctor report SHALL contain a finding that names the failure and MUST continue the other doctor checks.

Scenario: konmon exits 1

  • WHEN A test puts a fake konmon on PATH that exits 1 and writes permission denied to stderr.
  • THEN The report contains a finding with permission denied, and the doctor returns no unhandled exception.

Requirement: Read only

The doctor check MUST issue no request that changes a cluster object.

Scenario: Recorded konmon arguments

  • WHEN A test runs the check with a fake konmon executable that records each argument list.
  • THEN No recorded argument is apply, create, delete, patch, replace, edit, drain or scale.

Existing Tool Considered

guettli/konmon (Apache-2.0, maintained) has the verdict covers in the alternatives block of the issue body. The block gives the Covers: and Lacks: lists. The proposal adopts the tool as the orphan scanner behind a devops k8s doctor check, filters its orphan list to Deployment, StatefulSet, DaemonSet and CronJob, and adds an in-repository fixture test with a fake executable. The change builds no scanner.

Key questions

  • The alternatives check found that https://github.com/guettli/konmon covers this item. Adopt the tool, or keep the item and give the reason.: Adopt guettli/konmon. The owner replied that AGENTS.md rule 3 requires using an open tool before building. (best practice) [sources: AGENTS.md]
    • Chosen: Adopt guettli/konmon as the orphan scanner. The owner chose it, and the alternatives block gives the verdict covers.
    • Rejected: Keep the item and build a custom scan. The owner refused this, and AGENTS.md rule 3 puts an open tool first.
    • Rejected: Run konmon only from cron outside doctor. It leaves the doctor without the report that the issue asks for.
  • Where does the orphan report live?: Add a check inside devops k8s doctor that runs the konmon orphaned check and maps its workload entries to findings. (best practice) [sources: src/devops_cli/commands/k8s/diagnostics.py:573, k8s/README.md:990]
    • Chosen: A check inside devops k8s doctor. The body names doctor, and the command already reads the cluster read-only.
    • Rejected: A new devops k8s orphans command. It adds command surface and splits the cluster health report.
    • Rejected: A cron job that runs konmon alone. It gives no doctor finding and needs a second integration.
  • Which orphan kinds does the doctor report?: Report only Deployment, StatefulSet, DaemonSet and CronJob. Drop every other orphan kind that konmon returns. (best practice) [sources: k8s/README.md:1263]
    • Chosen: Filter to the four workload kinds. The issue asks for workloads, and the alternatives block says konmon reports every orphan kind.
    • Rejected: Report every orphan kind. It adds noise beyond the issue scope.
    • Rejected: Report only Deployments. It misses StatefulSet, DaemonSet and CronJob.
  • How does the doctor find the konmon executable?: Use the konmon executable from PATH. Report a finding when it is absent. Add no new config key. (best practice) [sources: AGENTS.md, src/devops_cli/commands/k8s/diagnostics.py:573]
    • Chosen: PATH lookup with a missing-tool finding. It needs no new setting and keeps the doctor usable.
    • Rejected: A required config key. It adds setup for one binary and blocks the check.
    • Rejected: Silent skip when absent. It hides a missing check from the operator.
  • How does the offline test supply konmon?: Put a fake konmon executable in tmp_path, prepend its directory to PATH, and return a JSON fixture. (best practice) [sources: tests/commands/k8s/test_k8s.py, tests/support/k8s_commands.py:1]
    • Chosen: Fake executable on PATH. It tests the real subprocess boundary and runs offline.
    • Rejected: Monkeypatch the Python adapter. It does not prove the executable call or PATH handling.
    • Rejected: Live cluster. It needs a cluster and is not offline.
  • How does the check treat a workload in a system namespace?: Use the konmon behavior. It skips kube-system, kube-public and kube-node-lease, so the doctor does not add a second scan for them. (best practice) [sources: k8s/README.md:1263]
    • Chosen: Accept the konmon system-namespace skip. The owner adopted konmon, and a second scan would build the code that rule 3 rejects.
    • Rejected: Add a second scan for system namespaces. It duplicates the tool and builds a custom scanner.
    • Rejected: Run konmon with a flag that includes system namespaces. The alternatives block gives no such option, and the check must not invent one.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Moved to new items

dan-petty/homelab#370

Activity

  1. added
    source/agent
    on Nov 13, 2026
  2. added
    type/bug
    scope/k8s
    status/new
    value/medium
    effort/low
    on Nov 13, 2026
  3. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor
  4. added
    priority/p2-medium
    on Nov 13, 2026
  5. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Alternatives check: in-use

    Reason: The searches surfaced no maintained, standalone tool that lists cluster workloads which no Argo CD Application manages; the only on-point tool is Argo CD itself, which the project already runs and which supplies the tracking label/annotation plus per-AppProject orphan monitoring. That covers part of the need (it gives the managed/unmanaged distinction the check reads), but not a cluster-wide, add-on-aware report, so the remaining work is the small read-only check in devops k8s doctor.

    The repository already uses this tool.

    Tool: argoproj/argo-cd (https://github.com/argoproj/argo-cd)

    • License: Apache-2.0
    • Last activity: 2026-11-16
    • Maintained: yes

    Covers:

    • Argo CD is the GitOps reconciler that keeps the k3s homelab in line with main, so the project already runs it and can read its Applications from the argocd namespace
    • Argo CD marks each object it applies with a tracking label or annotation (app.kubernetes.io/instance or argocd.argoproj.io/tracking-id), which is exactly the signal the check needs to separate managed from unmanaged workloads
    • Its AppProject orphaned-resource monitoring already reports objects that sit in a project's destination namespaces without being managed

    Lacks:

    • Orphan monitoring is scoped to each AppProject's destination namespaces, so a workload in a namespace that no project targets is never reported
    • No cluster-wide comparison of kubectl get deploy,statefulset,daemonset,cronjob -A against the Application destination namespaces
    • No exclusion of k3s add-on objects
    • No read-only devops k8s doctor check with a fixture test and a live proof; that glue has to be written in the repository

    Tools considered:

    Searches run:

    • kubectl plugin list unmanaged workloads missing argocd tracking label, results: 5
    • tool find Kubernetes resources not managed by Argo CD orphaned workloads, results: 5
    • Argo CD orphaned resources monitor, results: 5
    • popeye Kubernetes cluster sanitizer unmanaged deployments, results: 5
    • "Argo CD" "orphaned resources" AppProject, results: 5
    • kube-orphans github orphaned kubernetes objects finder, results: 5
    • argo-cd.readthedocs.io orphaned resources AppProject documentation, results: 5

    Sources:

    Checked on 2026-11-17. A person decides what this means for the item. The check changes no label and closes no issue.

  6. added
    status/ready
    and removed
    status/new
    on Nov 18, 2026
  7. devops-cli-service commented on Nov 18, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 2b7f32c (see proposed design in issue body).

    Moved to new items: dan-petty/homelab#370.

  8. 1 remaining item

  9. added
    status/new
    and removed
    status/ready
    on Nov 23, 2026
  10. devops-cli-service commented on Nov 23, 2026

    @devops-cli-service
    Contributor

    Owner question: See the first point of Open questions 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

  11. dan-petty commented on Nov 24, 2026

    @dan-petty
    OwnerAuthor

    Adopt the tool: guettli/konmon. AGENTS.md rule 3 requires using an open tool before building.

  12. added
    status/ready
    and removed
    status/new
    on Nov 24, 2026
  13. devops-cli-service commented on Nov 24, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See Moved to new items in the section Proposed design of the body.

  14. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 25, 2026
  15. removed
    status/in-review
    on Nov 25, 2026
  16. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-25 17:09 UTC

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/lowpriority/p2-mediumscope/k8ssource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions