Repository navigation
Description
Update 2026-11-26 (infra move): the root stacks go to tf/github/ of dan-petty/homelab (ADR 0032), and tf/ is not in this repository. Repository settings belong to devops repos onboard (ADR 0035), and CronJob repos-drift already checks them each night. OpenTofu keeps only the organization checks and the transfer check. Check this design again before a build; the environment values and rule files that it cites are in homelab.
Problem or Motivation
A UI change or a lost setting stays hidden until someone runs a plan.
Order 13 of the plan in #5311. The owner approved the plan on 2026-11-13.
Proposed Solution & Architectural Design
Add the CronWorkflow github-settings-drift. For each stack it runs 'devops tf drift -lock=false' and 'devops tf plan -detailed-exitcode -lock=false', with the reader App credentials from a Secret that the owner creates. Timeouts nest: tofu < step < activeDeadlineSeconds. A failed Workflow raises the existing alert.
Target Subsystem
Kubernetes & Minikube Automation
Existing Tool Considered
A GitHub App with read permissions and no webhook, an Argo Workflows CronWorkflow, and the existing failed-Workflow alert through Alertmanager to Mattermost.
Cost: Build: about 800k tokens, 1 day. Keep: about 50k tokens a month. Fix: about 200k tokens for each break. Owner: about 30 min.
Acceptance Criteria
- A UI change that the owner makes on the probe repo fails the next run.
- Then 7 nights pass with exit 0, or with an explanation for each drift.
Dependencies
#5319, dan-petty/homelab#358, #5325 and dan-petty/homelab#360; the owner creates devops-settings-reader and its Secret. Part of #5311.
Source: #5311
Proposed design
Problem statement
A UI change or a lost GitHub setting stays hidden until someone runs a plan. This issue adds a nightly Argo Workflows CronWorkflow that runs devops tf drift and devops tf plan --detailed-exitcode for the GitHub stacks with a read-only GitHub App. A plan with changes exits 2 and fails the Workflow. A Prometheus rule routes that failure through the existing Alertmanager receiver to Mattermost. The live probe check waits on the owner-created App and Secret and on seven nights of runs, so it is deferred.
Acceptance criteria
Requirement: Nightly CronWorkflow
The devops kustomize base SHALL declare CronWorkflow github-settings-drift with a nightly schedule, concurrencyPolicy Forbid, an activeDeadlineSeconds, a ttlStrategy and a podGC.
Scenario: Kubernetes render of the CronWorkflow
- WHEN A developer runs
uv run devops ci --check --only k8s. - THEN The check passes for the rendered CronWorkflow github-settings-drift in namespace devops with schedule
17 3 * * *, concurrencyPolicy Forbid, activeDeadlineSeconds 3600, a ttlStrategy and a podGC.
Requirement: Parallel stack steps
The CronWorkflow SHALL run one step for each GitHub stack in a DAG that starts the stack steps in parallel.
Scenario: Stack step render
- WHEN A developer runs
uv run devops ci --check --only k8s. - THEN The check passes for the rendered DAG that holds one parallel step for each GitHub stack, including
tf/github/dan-pettyandtf/github/retric-ai.
Requirement: Drift and plan commands
Each stack step SHALL run devops tf drift <stack> --no-lock and devops tf plan <stack> --detailed-exitcode --no-lock.
Scenario: Workflow command render
- WHEN A developer runs
uv run devops ci --check --only k8s. - THEN The check passes for the rendered CronWorkflow that runs both commands with the stack directory for each GitHub stack.
Requirement: Detailed exit code and no-lock options
devops tf plan MUST accept --detailed-exitcode and --no-lock, devops tf drift MUST accept --no-lock, and devops tf plan --detailed-exitcode MUST exit 2 when the plan has changes.
Scenario: Command options and exit code
- WHEN A developer runs
uv run devops ci test tests/commands/test_tf.py tests/commands/test_tf_dry_run.py tests/tf/test_tf_analysis.py. - THEN The tests pass for
build_tf_plan_cmdwith-detailed-exitcode -lock=false, fordevops tf plan --detailed-exitcodethat exits 2 without a traceback, and fordevops tf drift --no-lockthat passes-lock=false.
Requirement: Read-only App credentials
The CronWorkflow MUST mount Secret devops-settings-reader as a volume for the PEM file, set GITHUB_APP_PEM_FILE to that file path, and set GITHUB_APP_ID and GITHUB_APP_INSTALLATION_ID from the Secret; it MUST set no GITHUB_TOKEN or GH_TOKEN.
Scenario: Credential reference render
- WHEN A developer runs
uv run devops ci --check --only k8s. - THEN The check passes for the rendered CronWorkflow that mounts only Secret devops-settings-reader for the App values, sets GITHUB_APP_PEM_FILE to the mounted file path, and sets no GITHUB_TOKEN or GH_TOKEN.
Requirement: Nested timeouts
The CronWorkflow MUST set the tofu timeout below the step timeout and the step timeout below activeDeadlineSeconds.
Scenario: Timeout order render
- WHEN A developer runs
uv run devops ci --check --only k8s. - THEN The check passes for the rendered CronWorkflow whose timeouts are tofu 1800s below the step 2700s below activeDeadlineSeconds 3600s.
Requirement: Failed-run alert
A Prometheus rule MUST fire when a Workflow of CronWorkflow github-settings-drift fails, and it MUST route through the existing Alertmanager receiver to Mattermost.
Scenario: Alert rule render
- WHEN A developer runs
uv run devops ci --check --only k8s. - THEN The check passes for the rendered rule group whose alert selects the Argo Workflows controller's failed-Workflow series for github-settings-drift and carries severity warning.
Requirement: State and network access
The CronWorkflow ServiceAccount MUST read the tofu state Secret in namespace tofu-state, and its pods MUST reach GitHub over HTTPS.
Scenario: Role and NetworkPolicy render
- WHEN A developer runs
uv run devops ci --check --only k8s. - THEN The check passes for the rendered Role and RoleBinding that grant get on the tofu state Secret and the egress rule that admits TCP 443 from the github-settings-drift pods.
Existing Tool Considered
No alternatives check has run. OpenTofu covers the plan with -detailed-exitcode and -lock=false, but it has no scheduler and no GitHub App credential injection. Argo Workflows covers the nightly CronWorkflow and the failed-Workflow status, but it runs no OpenTofu plan. The integrations/github provider covers a read-only App's app_auth, but the project's devops tf plan and devops tf drift pass neither -detailed-exitcode nor -lock=false. The change adds two pass-through options. Cost: about 40k tokens to build, 5k a month to keep, 20k for each break, and about 2 hours. It builds no planner and no scheduler.
Key questions
- Which scheduler runs the nightly drift check?: Use an Argo Workflows CronWorkflow named github-settings-drift, with schedule
17 3 * * *in UTC and concurrencyPolicy Forbid. (best practice) [sources: docs/adr/0008-argo-workflows-run-the-roadmap-jobs-after-a-measured-go.md, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md, k8s/devops/cronworkflow-rag-ingest.yaml, docs/guidelines/kubernetes.md]- Chosen: Argo Workflows CronWorkflow. ADR 0008 and ADR 0021 choose Argo Workflows. The repository already has a CronWorkflow, and the controller exposes the Workflow status that the alert reads.
- Rejected: Kubernetes CronJob. It would need a second failure path and would not use the Argo Workflows controller's Workflow status.
- Rejected: GitHub Actions schedule. It runs outside the cluster and cannot mount the cluster Secret that holds the App credentials.
- Which namespace runs the CronWorkflow, and where does its Secret live?: Put the CronWorkflow and Secret devops-settings-reader in namespace devops, after feat(k8s): let Argo Workflows run roadmap pods in devops #4566 makes the controller watch devops. (best practice) [sources: k8s/argo-workflows/values.yaml, k8s/README.md, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md]
- Chosen: devops after feat(k8s): let Argo Workflows run roadmap pods in devops #4566. The Secret and the devops-cli config already live in devops. The existing CronWorkflow is there. ADR 0021 makes the controller watch devops from the engine step on.
- Rejected: argo-workflows. Its perimeter admits no public HTTPS. Its executor ServiceAccount can only patch workflowtaskresults. The k8s gate forbids Secret references in that directory.
- Rejected: Cluster mode with a ClusterRole. It expands the controller's RBAC and contradicts the one-namespace decision of ADR 0008.
- Which commands detect GitHub settings drift?: Run
devops tf drift <stack> --no-lockanddevops tf plan <stack> --detailed-exitcode --no-lockfor each GitHub stack. Add the two pass-through options to the CLI so it maps them to OpenTofu's-lock=falseand-detailed-exitcode. (best practice) [sources: src/devops_cli/commands/tf.py, src/devops_cli/tf/tf_plans.py, src/devops_cli/tf/analysis.py, tests/commands/test_tf.py]- Chosen: Extend the devops tf commands. The body names
devops tf. The CLI already builds the OpenTofu command. Only the two options and the exit code 2 handling are missing. - Rejected: Run tofu directly in the workflow. It duplicates the CLI interface and skips the project's config and dry-run handling.
- Rejected: Plan only. It loses the drift report and the remote-change detail.
- Chosen: Extend the devops tf commands. The body names
- How do the timeouts nest?: Set the tofu timeout to 1800s, the step timeout to 2700s and activeDeadlineSeconds to 3600s. Run the two stack steps in parallel so both fit. (best practice) [sources: docs/guidelines/kubernetes.md, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md, k8s/devops/workflowtemplate-rag-ingest.yaml]
- Chosen: Nested timeouts with parallel stack steps. The Kubernetes guideline requires a bounded Workflow. Parallel steps keep two 2700s steps below 3600s.
- Rejected: One timeout. It cannot tell which layer failed and gives no bounded step.
- Rejected: Sequential stack steps. Two 2700s steps exceed activeDeadlineSeconds 3600s.
- How does a failed run raise an alert?: Add a Prometheus rule on the Argo Workflows controller's failed-Workflow series for github-settings-drift, with severity warning. Let the existing Alertmanager receiver route it to Mattermost. (best practice) [sources: k8s/argo-workflows/values.yaml, k8s/devops/monitoring/prometheus-rules-values.yaml, k8s/monitoring/prometheus-values.yaml, k8s/README.md]
- Chosen: New Prometheus rule. The controller already exposes metrics. The Alertmanager receiver already routes warning and critical alerts to Mattermost. The body gives no rule name or expression to reuse.
- Rejected: Existing failed-Workflow alert. The body names the existing Alertmanager route, not a Workflow rule text.
- Rejected: Workflow onExit webhook. It adds glue that duplicates the alert route.
- How does the CronWorkflow authenticate to GitHub?: Mount Secret devops-settings-reader as a volume for the PEM file. Set GITHUB_APP_PEM_FILE to that file path. Set GITHUB_APP_ID and GITHUB_APP_INSTALLATION_ID from the Secret. Set no GITHUB_TOKEN or GH_TOKEN. (best practice) [sources: docs/adr/0026-github-settings-are-opentofu-code-the-owner-applies.md, k8s/devops/workflowtemplate-rag-ingest.yaml]
- Chosen: Read-only GitHub App with the PEM file on a volume. ADR 0026 records the App as read-only, with no webhook, installed on both accounts. The provider reads the App credentials. The PEM file needs a file path.
- Rejected: Personal access token. It carries broader scopes and is not tied to an App installation.
- Rejected: GitHub Actions token. It is not available to an in-cluster Workflow.
- How does the drift pod read the tofu state and reach GitHub?: Give the CronWorkflow its own ServiceAccount with a Role and RoleBinding in tofu-state for get on the state Secret. Add an egress rule to the devops perimeter for TCP 443 from the github-settings-drift pods. (best practice) [sources: docs/adr/0026-github-settings-are-opentofu-code-the-owner-applies.md, k8s/devops/serviceaccount.yaml, k8s/devops/networkpolicy.yaml]
- Chosen: Dedicated ServiceAccount and egress rule. The devops-cli ServiceAccount has automountServiceAccountToken false and no Role. The devops perimeter already admits public HTTPS but not the Kubernetes API.
- Rejected: Reuse the devops-cli ServiceAccount. It holds no token and no permission on the tofu-state Secret.
- Rejected: Local state file. ADR 0026 requires the Kubernetes backend and forbids local state.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
#5319, dan-petty/homelab#358, #5325, dan-petty/homelab#360, #4566
Watched files
A commit on the default branch that changes one of these files starts the next refine round.
k8s/argo-workflows/values.yaml
Alternatives check of 2026-11-28: partly.
Tool: opentofu/opentofu (https://github.com/opentofu/opentofu), MPL-2.0, last activity 2026-11-27, maintained.
Reason: Searches found no tool that runs the whole nightly GitHub-settings drift check: OpenTofu, already in use, supplies plan and drift detection only, scheduling and alerts need Argo Workflows, and ADR 0035 gives repository settings to repos-drift.
Covers:
- Plan with detailed exit code returns 2 on any drift
- Reads the Kubernetes backend state with locking disabled
- Applies the GitHub provider to the remaining organization checks
- No new planner or state engine is needed
Lacks:
- No scheduler, so a CronWorkflow or CronJob must call it
- No GitHub App credential injection, the pod mounts the PEM file
- No alert path, a Prometheus rule and receiver stay separate
- A read-only token reads merge settings as false, reporting drift nightly
- Repository settings now belong to repos-drift, not to the roots
Activity
dan-petty commentedon Nov 13, 2026
Both use Argo CronWorkflows in the cluster for nightly drift detection, but the candidate checks GitHub settings via a read-only App while dan-petty/devops-cli#5129 checks infra repos via devops infra drift.devops-cli-service commentedon Nov 17, 2026
Refine cannot set this item to Ready at 551a0c3 while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.
The next refine round also looks at the item again when a commit on the default branch changes one of these files:
k8s/argo-workflows/values.yaml.devops-cli-service commentedon Nov 21, 2026
Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies and Watched files in the section Proposed design of the body.
devops-cli-service commentedon Nov 23, 2026
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:
Sources:
dan-petty commentedon Nov 27, 2026
Evidence from dan-petty/homelab#379 (2026-11-27) for the next design check of this item:
github-settings-driftin namespacetofu-stateas the drift identity, and its acceptance criteria testsystem:serviceaccount:tofu-state:github-settings-drift. The design of this item runs the CronWorkflow in namespacedevopswith its own ServiceAccount. A Pod runs only as a ServiceAccount of its own namespace, so the two subjects do not match. One of the two items must name the subject of the other.internal/backend/remote-state/kubernetes/backend_state.go: when a workspace has no state,StateMgrcreates a Lease and writes an empty state Secret, also with-lock=false. A read-only Role (getandlistonsecrets) works only after a person's firsttofu initor apply wrote the state Secret.repos-drift(ADR 0035) already checks the repository settings each night and reads no OpenTofu state.dan-petty commentedon Nov 28, 2026
The plan of #7497 (pull request #7521, design D7) found a fault in the token of this design.
integrations/github6.13.0 reads them asfalse(upstream misleading diff (false -> true) for merge settings when authenticated with restricted GitHub App token integrations/terraform-provider-github#3382, open). A plan with the read-only Appdevops-settings-readerthen showsfalse -> truefor each merge setting on each run, so this job would report drift each night.CONST_GITHUB_APP_DRIFT_TOKEN_PERMISSIONS).tofu plan -detailed-exitcode -lock=falsea token with that permission set, and runs no apply. The roots are intf/github/of dan-petty/homelab (ADR 0032), and ADR 0041 (proposed in docs(spec): plan #7497 replace the onboard settings rows with OpenTofu #7521) gives them the repository settings again.dan-petty commentedon Nov 28, 2026
Update from the apply flow of ADR 0041 (#7497, the follow-up plan pull request names this item as the drift job):
tf/github/dan-petty(the public repositories) is in dan-petty/infra (feat(tf): add the root tf/github/dan-petty and its apply workflow infra#241).tf/github/dan-petty-private(the private repositories) stays in dan-petty/homelab (dan-petty/homelab#643). Both keep the state in namespacetofu-state.tofu plan -detailed-exitcode -lock=falseon each root with the token ofCONST_GITHUB_APP_DRIFT_TOKEN_PERMISSIONS(my comment above).github-settings, where an agent's merge could use it. So the drift job does not move to infra.devops-cli-service commentedon Nov 28, 2026
The result in the alternatives block of the issue body changed. Before this check:
in-use, tool https://github.com/opentofu/opentofu. A person decides what the new result means for the item.Searches (6)
Tools considered:
Searches run:
Sources: