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
7 changes: 7 additions & 0 deletions RELEASE_CYCLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ Before branching, modifying files, or creating the release commit, the cut runs
- 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.

Immediately following the offline gate, the cut executes a live, non-blocking Argo CD diff and override report against the configured cluster:
- If `argocd.url`, the Argo CD authentication token, or the `argocd` CLI binary is missing, a single warning is emitted and the cut proceeds without interruption.
- When configured, each Application is diffed at the release tip SHA using `--grpc-web` (multi-source Applications use their git source position via `--source-positions`), with the authentication token passed strictly via environment variable `ARGOCD_AUTH_TOKEN` (never in `argv`).
- Differences (exit code 1) are reported as "differs", command errors (exit code 2) are reported as "failed" with stderr truncated to `CONST_MAX_ERROR_DETAIL_LENGTH`, and neither condition halts the release cut.
- For homelab applications (`devops`, `ingress`), any template domain placeholder host at the release tip that lacks a live `test` operation in the cluster's active patches is reported alongside the corrective stack deployment command (`devops k8s deploy-stack --stack <stack>`).



### Step 3: CI Quality Gate & PR Review Gate
1. The opened Pull Request triggers `.github/workflows/ci.yml` which validates:
Expand Down
5 changes: 5 additions & 0 deletions changelog.d/1343.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Added

- Offline deterministic Argo CD build gate in `devops release prepare --create-pr` (and `cut_release`), building all repository-managed `Application` manifests via Kustomize from an isolated `git archive` snapshot at the release head before cutting a release (#1343).
- Strict template domain placeholder safety validation across all rendered manifests and Helm value files, ensuring placeholders appear only in authorized host fields of homelab applications (`devops`, `ingress`).
- Live, non-blocking Argo CD application diff and override reporting using `argocd app diff --grpc-web`, verifying live cluster diffs and surfacing any template domain placeholder hosts lacking active live overrides alongside their remediation command (`devops k8s deploy-stack --stack <stack>`) (#1343).
31 changes: 21 additions & 10 deletions docs/agent/tasks/task-1343-argocd-build-gate.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# Task: Argo CD Application Build Gate at Release Cut (#1343)
# Task: Argo CD Application Build Gate and Live Report 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`.
**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, `argocd app diff` command surface with fake subprocess runner, 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:
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 (#1343) implements the complete offline deterministic Argo CD build gate and live non-blocking cluster diff and override report:
- 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.
- Executes a live, non-blocking Argo CD application diff report against the configured cluster: diffs each Application at the release tip SHA using `--grpc-web` (multi-source Applications use their git source position via `--source-positions`), with the token passed strictly via environment variable `ARGOCD_AUTH_TOKEN` (never in `argv`).
- Evaluates homelab application overrides: surfaces any template domain placeholder hosts at the tip lacking active live `test` operations alongside the remedial command (`devops k8s deploy-stack --stack <stack>`).
- Emits a single warning and proceeds without interruption if `argocd.url`, the authentication token, or the `argocd` CLI binary is absent.
- Documents the gate and live report in Step 2 of `RELEASE_CYCLE.md`.

## Acceptance Criteria

Expand All @@ -20,16 +23,24 @@ A release cut must guarantee that every GitOps application managed by Argo CD bu
- [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).
- [x] With an Argo CD server configured, the cut reports each Application's diff at the release tip SHA with `--grpc-web`, multi-source Applications by their git source position, and the token appearing only in the environment.
- [x] Diff exit 1 is reported as "differs", exit 2 as "failed" with stderr truncated to `CONST_MAX_ERROR_DETAIL_LENGTH`, and neither halts the release cut.
- [x] Placeholder hosts at the tip not named by live `test` operations are reported with their `deploy-stack --stack` command.
- [x] Without `argocd.url`, token, or the `argocd` binary, one warning names what is missing and the cut continues.
- [x] `RELEASE_CYCLE.md` documents both the offline gate and the live report in Step 2.
- [x] Unit and integration tests verify offline validation and live reporting with a fake runner.
- [x] Changelog fragment `changelog.d/1343.md` added.

## 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`.
- [x] Created `src/devops_cli/argo/credentials.py` for lifted server and token resolution and re-exported in `src/devops_cli/argo/__init__.py`.
- [x] Updated `src/devops_cli/commands/argo.py` to use `resolve_argocd_server_and_token`.
- [x] Implemented `src/devops_cli/k8s/argocd_live_report.py` with `report_argocd_live_diff`, `extract_live_tested_hosts`, and `_find_repo_source_position`.
- [x] Integrated `check_argocd_gate` and `report_argocd_live_diff` into `cut_release` in `src/devops_cli/release/cut.py`.
- [x] Updated `RELEASE_CYCLE.md` documenting the offline gate and live diff report.
- [x] Added `changelog.d/1343.md`.
- [x] Authored comprehensive tests in `tests/test_k8s_argocd_gate.py`, `tests/test_k8s_argocd_live_report.py`, `tests/test_k8s_argocd_apps.py`, and `tests/test_release.py`.
6 changes: 6 additions & 0 deletions src/devops_cli/argo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

from __future__ import annotations

from devops_cli.argo.credentials import (
resolve_argocd_server_address,
resolve_argocd_server_and_token,
)
from devops_cli.argo.fleet import sync_fleet, sync_single_target
from devops_cli.argo.gitops import (
GitOpsWatcher,
Expand All @@ -22,6 +26,8 @@
"compute_manifest_state",
"evaluate_rollout_gate",
"promote_rollout",
"resolve_argocd_server_address",
"resolve_argocd_server_and_token",
"restart_rollout",
"scan_manifest_drift",
"sync_fleet",
Expand Down
38 changes: 38 additions & 0 deletions src/devops_cli/argo/credentials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Argo CD server and authentication token resolution (#1343)."""

from __future__ import annotations

import urllib.parse
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from devops_cli.config.settings import Settings


def resolve_argocd_server_address(url: str) -> str:
"""Extract host:port address from Argo CD URL for the CLI --server flag."""
parsed = urllib.parse.urlsplit(url)
return parsed.netloc or url.split("://")[-1].rstrip("/")


def resolve_argocd_server_and_token(
settings: Settings | None = None,
) -> tuple[str | None, str | None]:
"""Resolve Argo CD server URL and bearer token from configuration or keyring."""
if settings is None:
from devops_cli.config.settings import load_settings

settings = load_settings()

url = settings.argocd.url
if not url:
return None, None

from devops_cli.config.settings import get_argocd_token
from devops_cli.k8s.credentials import get_or_mint_argocd_token

clean_url = url.rstrip("/")
token = get_argocd_token(settings) or get_or_mint_argocd_token(settings)
if token and token.startswith("*"):
token = None
return clean_url, token
11 changes: 5 additions & 6 deletions src/devops_cli/commands/argo.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,25 +160,24 @@ def _rollout_status_table(state: ArgoRolloutState) -> TablePayload:


def _argocd(settings: Any) -> tuple[str, dict[str, str]]:
from devops_cli.config.settings import get_argocd_token
from devops_cli.k8s.credentials import get_or_mint_argocd_token
from devops_cli.argo.credentials import resolve_argocd_server_and_token

if not settings.argocd.url:
url, token = resolve_argocd_server_and_token(settings)
if not url:
print_error(
MESSAGES.argo.url_not_configured,
prefix=False,
)
raise typer.Exit(1)
try:
validate_service_url(settings.argocd.url, "ArgoCD", allow=settings.ai.allow_private_network)
validate_service_url(url, "ArgoCD", allow=settings.ai.allow_private_network)
except ValueError as exc:
print_error(str(exc), prefix=False)
raise typer.Exit(1) from exc
headers: dict[str, str] = {"Content-Type": "application/json"}
token = get_argocd_token(settings) or get_or_mint_argocd_token(settings)
if token:
headers["Authorization"] = f"Bearer {token}"
return settings.argocd.url.rstrip("/"), headers
return url, headers


# =============================================================================
Expand Down
Loading
Loading