Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions RELEASE_CYCLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ Use the unified `--create-pr` flag (or `devops release pr`) to automate version
uv run devops release prepare X.Y.Z --create-pr
```

Before branching, modifying files, or creating the release commit, the cut runs a deterministic offline gate verifying that every Argo CD application in `k8s/argocd/apps/` and `k8s/argocd/bootstrap/` targeting this repository builds at the fetched remote release tip:
- Each path application is built with Kustomize from an exported archive of the release head (`git archive`), ensuring that uncommitted or gitignored files cannot hide broken kustomizations.
- Template domain placeholder values (`example.com`, `$DOMAIN`, etc.) are validated: placeholders are permitted only in host fields of homelab applications (`"devops"`, `"ingress"`), and are rejected anywhere else (ConfigMaps, non-host fields, Helm value files, or non-homelab applications).
- If any application fails to build or contains invalid placeholders, the cut stops immediately with an `ArgoCDGateError` before any files are changed, any branch is checked out, or any git/gh commands reach origin.


### Step 3: CI Quality Gate & PR Review Gate
1. The opened Pull Request triggers `.github/workflows/ci.yml` which validates:
- Python 3.14 runtime environment
Expand Down
1 change: 1 addition & 0 deletions docs/ERRORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The Exit Code column is the exception's `exit_code` attribute. Only `devops clou
| `AICredentialsError` | `LLM_INFERENCE_ERROR` | `10` | Devops_cli.ai.client.models | Raised when a provider rejects the request's credentials; retrying cannot help. |
| `AgentRunError` | `AGENT_RUN_ERROR` | `20` | Ai | Raised when an error occurs during an agent run lifecycle. |
| `ApprovalRequired` | `APPROVAL_REQUIRED` | `17` | Ai | Raised by a tool or validator when human approval is required to proceed. |
| `ArgoCDGateError` | `ARGOCD_GATE_ERROR` | `1` | K8s | Raised when an Argo CD application fails offline build, value, or placeholder validation (#1343). |
| `ArgoError` | `ARGO_ERROR` | `1` | Argo | Base exception for Argo CD, Rollouts, and Workflows operations. |
| `ArgoResourceNotFoundError` | `ARGO_RESOURCE_NOT_FOUND` | `1` | Argo | Raised when an Argo custom resource does not exist in the target cluster. |
| `BranchAlreadyExistsError` | `BRANCH_ALREADY_EXISTS` | `1` | Git | Raised when attempting to create a branch that already exists. |
Expand Down
35 changes: 35 additions & 0 deletions docs/agent/tasks/task-1343-argocd-build-gate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Task: Argo CD Application Build Gate at Release Cut (#1343)

**Issue**: [#1343](https://github.com/dan-petty/devops-cli/issues/1343)
**Scope**: scope/release
**Feasibility**: Verified against local Argo CD applications in `k8s/argocd/apps` and `k8s/argocd/bootstrap`, `git archive` export behavior, `kubectl kustomize` execution against extracted archives, and `cut_release` orchestration in `tests/test_release.py`.

## Description

A release cut must guarantee that every GitOps application managed by Argo CD builds deterministically at the release head before cutting the release. This deliverable (Part 1 of #1343) implements the offline deterministic Argo CD build gate:
- Discovers all Argo CD `Application` resources across `k8s/argocd/apps` and `k8s/argocd/bootstrap` pointing to this repository (`CONST_K8S_ARGOCD_APPLICATION_DIRS`).
- Exports a clean snapshot of the release tip using `git archive` into an isolated temporary directory, ensuring uncommitted or gitignored files cannot mask broken kustomizations.
- Builds every path application using Kustomize (`build_manifest_path`) and verifies template domain placeholder safety: placeholders (`example.com`, `$DOMAIN`, etc.) are permitted only in host fields of homelab applications (`"devops"`, `"ingress"`), and are rejected in ConfigMaps, non-host fields, Helm value files, or non-homelab applications.
- Fails closed with typed `ArgoCDGateError` before any release branching, file modifications, commits, or pushes occur in `cut_release`.
- Updates `RELEASE_CYCLE.md` documenting the gate in Step 2 of the release procedure.

## Acceptance Criteria

- [x] Every Argo CD `Application` pointing to this repository is discovered and validated.
- [x] Path applications are built using Kustomize from an exported archive of the release tip.
- [x] Template domain placeholder values outside allowed homelab host fields trigger gate failure.
- [x] Missing kustomization files, broken resources, or missing Helm value files raise `ArgoCDGateError`.
- [x] A gate failure prevents `cut_release` from creating branches, writing files, or pushing to origin.
- [x] `RELEASE_CYCLE.md` documents the Argo CD build gate in Step 2.
- [x] Unit and integration tests verify pass and failure conditions across all application permutations.
- Live Argo CD diff and override report after the offline gate (closes #1343 in follow-up PR).

## Deliverables

- [x] Added `CONST_K8S_KUSTOMIZATION_NAMES` and `CONST_K8S_ARGOCD_APPLICATION_DIRS` in `src/devops_cli/config/constants.py`.
- [x] Added `ArgoCDGateError` in `src/devops_cli/exceptions/k8s.py`.
- [x] Added `holds_template_domain_value` and `build_manifest_path` in `src/devops_cli/k8s/template.py`.
- [x] Implemented `src/devops_cli/k8s/argocd_gate.py` with `check_argocd_gate`, `discover_argocd_applications`, and `discover_path_applications`.
- [x] Integrated `check_argocd_gate` into `cut_release` in `src/devops_cli/release/cut.py`.
- [x] Documented the Argo CD build gate in `RELEASE_CYCLE.md`.
- [x] Added comprehensive tests in `tests/test_k8s_argocd_gate.py` and `tests/test_release.py`, and updated `tests/test_k8s_argocd_apps.py`.
11 changes: 11 additions & 0 deletions src/devops_cli/config/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,17 @@
"""The ConfigMap `devops k8s deploy-stack` renders from config.yaml; no Argo CD Application owns it."""
CONST_K8S_ARGOCD_HOMELAB_APPLICATIONS: Final[tuple[str, ...]] = ("devops", "ingress")
"""The Argo CD Applications whose hosts deploy-stack sets from the configured domain (#1290)."""
CONST_K8S_KUSTOMIZATION_NAMES: Final[tuple[str, ...]] = (
"kustomization.yaml",
"kustomization.yml",
"Kustomization",
)
"""The standard file names Kustomize recognizes for a directory overlay."""
CONST_K8S_ARGOCD_APPLICATION_DIRS: Final[tuple[Path, ...]] = (
Path("k8s/argocd/apps"),
Path("k8s/argocd/bootstrap"),
)
"""Directories scanned for Argo CD Applications (#1343)."""
CONST_K8S_ARGOCD_HOMELAB_APPLICATIONS_BY_STACK: Final[dict[str, tuple[str, ...]]] = {
"infra": ("ingress",),
"devops": ("devops", "ingress"),
Expand Down
27 changes: 27 additions & 0 deletions src/devops_cli/exceptions/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,32 @@ def __init__(
)


class ArgoCDGateError(KubernetesError):
"""Raised when an Argo CD application fails offline build, value, or placeholder validation (#1343)."""

def __init__(
self,
message: str,
*,
failures: dict[str, list[str]] | None = None,
context: str | None = None,
exit_code: int = CONST_EXIT_FAILURE,
error_code: str = "ARGOCD_GATE_ERROR",
details: dict[str, Any] | None = None,
) -> None:
err_details = dict(details or {})
if failures:
err_details["failures"] = failures
super().__init__(
message,
context=context,
exit_code=exit_code,
error_code=error_code,
details=err_details,
)
self.failures: dict[str, list[str]] = failures or {}


class ChaosExecutionError(KubernetesError, RuntimeError):
"""Raised when chaos engineering injection or validation fails."""

Expand Down Expand Up @@ -209,6 +235,7 @@ def __init__(


__all__ = [
"ArgoCDGateError",
"ChaosExecutionError",
"ClusterJobError",
"ClusterSecretPushError",
Expand Down
Loading
Loading