Skip to content

Architecture decision

ADR 0013: Safely Generate and Verify PlatformService Repository Artifacts

Status

Accepted for Stage 5D review.

Context

Stage 5A established the strict idp/v1alpha1 PlatformService contract. Stage 5B proved deterministic golden-path Helm values rendering. Stage 5C proved deterministic Argo CD Application rendering and the self-service AppProject boundary.

The platform can now introduce repository writes because both generated artifacts already have pure compiler authorities. Stage 5D must add mutation without weakening the source-of-truth model, overwriting handwritten content, inventing a third state file, or pretending that two independent files can be replaced with one universal POSIX-atomic operation.

Decision

Add controlled generation and verification for the canonical production layout:

services/<service>/service.yaml
services/<service>/generated/values.yaml
services/<service>/generated/application.yaml

The source file must be named service.yaml, live directly under services/<service>/, be a regular non-symlink file, resolve inside the repository, and match metadata.name. Output paths are derived only by the platform. Stage 5D does not add --output, --generated-dir, or any developer-selected destination.

Generated files are platform-owned only when they begin with the deterministic generated-file banner already used by Stage 5B and Stage 5C. Existing generated artifacts without that exact marker are unmanaged and are refused. generated/ is a platform-managed directory whose persistent Stage 5D entries are exactly values.yaml and application.yaml.

Repository static validation permits source-only services and canonical platform-owned generated pairs. It rejects partial pairs, missing sources, symlinks, non-regular artifacts, unowned generated files, and third persistent entries. It intentionally does not compare generated bytes with compiler output; platformctl service verify owns deterministic drift detection.

The generator computes the complete values/Application pair in memory before mutating the repository. It validates source layout, compiles both artifacts, validates output paths, validates ownership for both targets, stages temporary files next to the final outputs, flushes them, and uses per-file atomic replacement. If an ordinary write or replacement error occurs after one artifact changed, the generator attempts to roll back changed artifacts to their exact previous bytes and removes temporary files.

Regeneration is idempotent. Existing owned files that already match expected compiler output are reported as unchanged and are not replaced. Existing owned files that differ are considered generated drift and may be repaired by generate.

Same-service generation uses a POSIX advisory lock on the service directory. This prevents ordinary concurrent invocations for one service from interleaving writes without adding a persistent repository lock file.

Add read-only drift verification:

platformctl service verify services/<service>/service.yaml

verify validates the same source layout, compiles expected bytes, inspects ownership and generated directory contents, and exits successfully only when both artifacts are owned and byte-exact. It reports states such as current, missing, drifted, unowned, and unexpected-entry without mutating the repository.

Rationale

Generation begins only after deterministic compilers exist so the source contract and platform policies remain the only authorities. The generated YAML files are derived review artifacts, not new developer inputs.

The ownership marker lets the platform distinguish managed generated output from handwritten or unknown files. Refusing unmanaged overwrites is stricter than a --force escape hatch and keeps accidental data loss out of the first write-capable self-service slice.

Keeping exactly two persistent generated artifacts avoids hidden drift authorities such as metadata manifests, lock files, generation databases, or committed state files. The deterministic source, policies, and compilers are enough to reproduce and verify output.

The transaction model is intentionally honest. Stage 5D provides compile-before-write safety, ownership-before-write safety, staged writes, per-file atomic replacement, ordinary error rollback, and deterministic drift detection. It does not claim a single atomic commit across two independent files if the process or host terminates between replacements. verify is the recovery detector for abnormal interruption or manual drift.

Git operations are excluded. Generation does not stage, commit, push, create branches, open pull requests, or call GitHub. This keeps repository mutation local and reviewable.

Automatic Argo registration is excluded. Generation writes local desired-state artifacts only; it does not call Kubernetes, Argo CD, ApplicationSet, app-of-apps discovery, or environment promotion. Those lifecycle concerns remain separate from safe repository artifact creation.

Consequences

Developers can move from preview to controlled local generation:

platformctl service generate services/<service>/service.yaml
platformctl service verify services/<service>/service.yaml

The generated pair can be regenerated safely, checked for drift, and repaired when owned generated content changes. Handwritten files, symlinks, unexpected persistent entries, and service-name/path mismatches fail closed before mutation.

Stage 5D still does not create real services, stage generated files in Git, commit, push, open PRs, register Applications with Argo CD, create ApplicationSets, implement app-of-apps, add environment promotion, or begin Stage 6.

Alternatives Considered

  • Write files directly after values compilation: rejected because Application compilation must succeed before any persistent mutation.
  • Add a committed manifest or state file: rejected because deterministic compilers already define expected state and only two generated artifacts should persist.
  • Provide --force: rejected because unowned overwrite protection is a core Stage 5D safety guarantee.
  • Use a generated directory rename as a whole transaction: rejected because existing generated files must be individually ownership-checked and because cross-platform directory replacement semantics are more complex than this slice needs.
  • Register the generated Application with Argo CD immediately: rejected because repository generation and cluster lifecycle registration are separate platform boundaries.