Repository navigation
Description
Problem
- After dan-petty/homelab#96, the environment Secret rows are both in homelab
k8s/cluster-secrets.tomland insrc/devops_cli/k8s/cluster_secrets.py. - Readers of the table:
commands/k8s/cluster_secret_push.py,k8s/secret_push.py,commands/config.py(config set --generate),commands/k8s/stack_lifecycle.py(deploy-stack),mattermost_bootstrap.pyandroadmap_key_bootstrap.py. - The rows are frozen dataclasses (
cluster_secrets.py:55-200); no pydantic model of them exists. src/devops_cli/k8s/environment.pyresolves the environment tree (--k8s-dir, the profile factkubernetes.dir,infra.repos).
Proposed remedy
- A pydantic
TypeAdapterover a file model readscluster-secrets.tomland builds the existing dataclasses, with one tagged form for each source kind (keyring, setting, literal, derived) and the generator andadopt_fromtables. No second row model. - push-secrets and the other readers load the file from the environment tree and add the product rows.
- Delete the moved rows from
cluster_secrets.py. - Write the tests first, with a fixture file under
tests/fixtures/.
Acceptance criteria
- A new test fails on main and passes on the branch: a fixture file with one row of each source kind gives the same
ClusterSecretobjects as equal Python rows.uv run pytest tests/k8s -q -k cluster_secretpasses. -
git grep -n -E 'stack=(BASE_STACK|"(chat|gitea|infra)")' src/finds nothing, and the onlyllmrows left incluster_secrets.pyarevalkey-devops-authandvalkey-runs-auth. -
uv run devops ci --check --only test,lint,typecheckpasses.
Person steps
- Run
devops k8s push-secrets --planwith an unlocked keyring against the live cluster and post the count of changes (expected: 0). Post no value.
Dependencies
- dan-petty/homelab#96.
Alternatives check of 2026-11-21: not-applicable.
Class: refactor, no search.
Tool: none found.
Proposed design
Problem statement
The environment Secret rows live in homelab k8s/cluster-secrets.toml and in src/devops_cli/k8s/cluster_secrets.py. The duplicate rows make two sources of truth. The change reads the homelab file into the existing dataclasses. It keeps only the product rows in code. The readers load the file from the environment tree.
Acceptance criteria
Requirement: File rows load into existing dataclasses
The loader SHALL build the existing ClusterSecret dataclasses from k8s/cluster-secrets.toml.
Scenario: One row of each source kind
- WHEN the test
tests/k8s/test_cluster_secrets_file.pyloadstests/fixtures/cluster-secrets.tomlwith one keyring, setting, literal and derived row - THEN each loaded object equals the equal
ClusterSecretPython row anduv run pytest tests/k8s -q -k cluster_secretpasses.
Requirement: Generator and adopt_from tables load
The file model SHALL read the generator and adopt_from tables for each row.
Scenario: A generated row and an adopted row
- WHEN the fixture file holds a generator table and an
adopt_fromtable - THEN the loaded
SecretEntryhas the sameSecretGeneratorandSecretKeyRefas the equal Python row, anduv run pytest tests/k8s -q -k cluster_secretpasses.
Requirement: Environment rows removed from code
The module src/devops_cli/k8s/cluster_secrets.py MUST contain no environment Secret rows after the change.
Scenario: No moved stack rows remain
- WHEN the test
tests/k8s/test_cluster_secret_source.pyrunsgit grep -n -E 'stack=(BASE_STACK|"(chat|gitea|infra)")' src/ - THEN the command finds no match, and
git grep -n 'name="valkey-' src/devops_cli/k8s/cluster_secrets.pyfinds onlyvalkey-devops-authandvalkey-runs-auth.
Requirement: Push-secrets uses the environment file
devops k8s push-secrets MUST load the environment rows from cluster-secrets.toml and append the product rows.
Scenario: A fixture environment tree
- WHEN the test
tests/k8s/test_cluster_secret_push.pyruns with--k8s-dirpointing at a fixture environment tree - THEN the plan contains each fixture row and each product row, and
uv run pytest tests/k8s -q -k cluster_secretpasses.
Requirement: CI checks pass
The change MUST pass the project test, lint and typecheck checks.
Scenario: The scoped CI check
- WHEN
uv run devops ci --check --only test,lint,typecheckruns - THEN the command exits 0.
Requirement: Live plan shows no change
The refactor MUST keep the live cluster Secret plan unchanged.
Scenario: The live push plan
- WHEN a person runs
uv run devops k8s push-secrets --planwith an unlocked keyring against the live cluster - THEN the command reports 0 changes and posts no Secret value.
Existing Tool Considered
The alternatives check in the issue body records not-applicable for a refactor with no search and Tool: none found. The change uses the existing pydantic TypeAdapter and the standard library tomllib; it adds no new tool. The loader glue costs about 20k tokens and 2 hours to build, keep and fix.
Key questions
- How does the loader read
cluster-secrets.tomlinto the existing frozen dataclasses?: Usetomllib.loadto read the file. Use a pydanticTypeAdapterover a file model to validate the data. The file model has one tagged form for each source kind, plus the generator andadopt_fromtables. The loader builds the existingClusterSecretdataclasses. It adds no second row model. (best practice) [sources: src/devops_cli/k8s/cluster_secrets.py, src/devops_cli/config/settings.py]- Chosen: pydantic TypeAdapter over a file model. It reuses the project's existing pydantic dependency and keeps the dataclasses as the row model.
- Rejected: hand-written TOML parser. It adds code to keep and does not validate the file schema.
- Rejected: second pydantic row model. It duplicates the dataclasses and makes two row models.
- Where do the readers find
cluster-secrets.toml?: The readers callsrc/devops_cli/k8s/environment.pyto resolve the environment tree. The resolver reads--k8s-dir, the profile factkubernetes.dir, orinfra.repos. The readers do not hardcode a homelab path. (best practice) [sources: src/devops_cli/k8s/environment.py, src/devops_cli/commands/k8s/cluster_secret_push.py, src/devops_cli/k8s/secret_push.py]- Chosen: environment tree resolver. It follows the existing
--k8s-dirand profile rules. - Rejected: hardcoded homelab path. It breaks other environment trees and the product base.
- Rejected: current working directory. It does not follow the environment tree rules.
- Chosen: environment tree resolver. It follows the existing
- Which rows stay in
src/devops_cli/k8s/cluster_secrets.py?: Only the product rows stay insrc/devops_cli/k8s/cluster_secrets.py. The environment rows move tok8s/cluster-secrets.toml. The onlyllmrows left arevalkey-devops-authandvalkey-runs-auth. (best practice) [sources: src/devops_cli/k8s/cluster_secrets.py]- Chosen: product rows only. It removes the duplicate environment rows and matches the issue's grep criterion.
- Rejected: keep all rows. It keeps two sources of truth.
- Rejected: load all rows from the file. The product base
k8s/devopsis not part of the environment tree.
- How does the file model carry a generator and an
adopt_fromreference?: EachSecretEntrytable gets an optionalgeneratortable and an optionaladopt_fromtable. The loader maps them toSecretGeneratorandSecretKeyRef. A plain source kind has no such table. (best practice) [sources: src/devops_cli/k8s/cluster_secrets.py, src/devops_cli/k8s/secret_push.py]- Chosen: optional nested tables. It keeps the existing dataclass fields and reads them from the file.
- Rejected: flat string fields. It needs parsing and loses the typed
SecretGeneratorandSecretKeyRef. - Rejected: leave generator and
adopt_fromin Python. It keeps part of the row in code and splits the row across two files.
- How does the change prove the file rows equal the Python rows?: Add a fixture
tests/fixtures/cluster-secrets.tomlwith one row of each source kind. A test compares each loadedClusterSecretwith an equal Python row. The test runs offline. (best practice) [sources: tests/k8s/test_cluster_secret_plan.py, tests/k8s/test_cluster_secret_push.py]- Chosen: fixture and equality test. It tests each source kind offline and catches a wrong field.
- Rejected: live cluster only. It is not offline and shows no field detail.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 21, 2026
Both deal with cluster Secret rows in cluster_secrets.py, but 741 established the push-from-keyring pattern while the candidate refactors where the row data is stored and read.devops-cli-service commentedon Nov 22, 2026
Next step: the stage job writes the plan of the item. See the section Proposed design of the body.
refactor(k8s): read the environment Secret rows from homelab (#6685)
devops-cli-service commentedon Nov 23, 2026
Released in v0.203.6: https://github.com/dan-petty/devops-cli/releases/tag/v0.203.6