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
2 changes: 2 additions & 0 deletions docs/ERRORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ and domain categorization for all exceptions inheriting from `DevOpsCLIError`.
| `LLM_INFERENCE_ERROR` | `10` | Devops_cli.ai.client.models | Raised when an AI provider request fails with a user-actionable message. |
| `AGENT_RUN_ERROR` | `20` | Ai | Raised when an error occurs during an agent run lifecycle. |
| `APPROVAL_REQUIRED` | `17` | Ai | Raised by a tool or validator when human approval is required to proceed. |
| `ARGO_ERROR` | `1` | Argo | Base exception for Argo CD, Rollouts, and Workflows operations. |
| `ARGO_RESOURCE_NOT_FOUND` | `1` | Argo | Raised when an Argo custom resource does not exist in the target cluster. |
| `BRANCH_ALREADY_EXISTS` | `1` | Git | Raised when attempting to create a branch that already exists. |
| `BUDGET_EXCEEDED` | `1` | Devops_cli.ai.agents.spend | Raised when an agent execution exceeds defined token or financial spend limits. |
| `CALL_DEFERRED` | `18` | Ai | Raised by a tool when execution is deferred to an external worker or async system. |
Expand Down
4 changes: 2 additions & 2 deletions docs/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ High-density product roadmap, engineering milestones, and open-source integratio
- *Deep Integration & Functional Extension*: Establish direct asynchronous communication over the local Docker daemon Unix domain socket (`/var/run/docker.sock`) using engine APIs; introspect BuildKit multi-stage layer caching; stream real-time container resource metrics and cgroup telemetry directly into reactive streams.
- *Code Optimization & Performance Acceleration*: Eliminate subshell latency when provisioning sandboxes; streamline ephemeral image builds via BuildKit cache mounts; implement zero-overhead container health probing via socket pings.
- *Refactoring Potential & Legacy Elimination*: Refactor `src/devops_cli/commands/docker.py` and `src/devops_cli/core/sandbox.py` to share a unified container engine client; replace unstructured stdout scraping with typed Pydantic container state models; eliminate legacy fallback shims.
- [ ] **ArgoCD Server API, CRD Reconciliation & Automated Canary Metric Verification Research (P1 - High, Issue #309)**:
- [x] **ArgoCD Server API, CRD Reconciliation & Automated Canary Metric Verification Research (P1 - High, Issue #309)**:
- *Context & Rationale*: GitOps fleet synchronization currently depends on external `argocd` and `kubectl-argo-rollouts` binary installations, creating environment friction and shallow subprocess orchestration.
- *Deep Integration & Functional Extension*: Native gRPC and REST client integration directly with the ArgoCD API server; direct Kubernetes Custom Resource Definition (`Application`, `ApplicationSet`, `Rollout`) manipulation; automated Canary rollout analysis verifying Prometheus SLO thresholds during progressive delivery.
- *Code Optimization & Performance Acceleration*: Eliminate external CLI binary prerequisites across CI runners and developer workstations; execute multi-application fleet synchronization queries in parallel over a single multiplexed HTTP/2 connection.
Expand Down Expand Up @@ -481,7 +481,7 @@ High-density product roadmap, engineering milestones, and open-source integratio
| | Structured Constraint Propagation Across Subagent Delegation | PydanticAI / Workflow | High | Medium | v0.2.25 | 📋 Scheduled (P1) |
| | MCP Resource-First Data Access & Tool Output Sandboxing | FastMCP / MCP Resources | High | Medium | v0.2.25 | 📋 Scheduled (P1) |
| | Docker Engine Socket API & Layer Caching Introspection Research | Docker Engine / BuildKit | High | Medium | v0.2.22 | ✅ Completed (P1) |
| | ArgoCD Server API, CRD Reconciliation & Canary Verification Research | ArgoCD / Rollouts | High | Medium | v0.2.22 | 📋 Scheduled (P1) |
| | ArgoCD Server API, CRD Reconciliation & Canary Verification Research | ArgoCD / Rollouts | High | Medium | v0.2.22 | ✅ Completed (P1) |
| | Terraform & OpenTofu HCL AST Analysis & Drift Optimization Research | OpenTofu / HCL AST | High | Medium | v0.2.22 | 📋 Scheduled (P1) |
| | HashiCorp Vault Native Client, Dynamic Leases & Envelope Encryption Research | Vault / HVAC / Keyring | High | Medium | v0.2.22 | 📋 Scheduled (P1) |
| | Valkey & Redis RESP3 Connection Pooling & Tiered L1/L2 Cache Research | Valkey / RESP3 / Redis | High | Medium | v0.2.22 | 📋 Scheduled (P1) |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Task 309: ArgoCD Server API, CRD Reconciliation & Automated Canary Metric Verification Research

**Issue**: [#309](https://github.com/dan-petty/devops-cli/issues/309)
**PR**: None (Draft)
**Status**: Backlog
**PR**: [#351](https://github.com/dan-petty/devops-cli/pull/351)
**Status**: In Review
**Milestone**: `v0.2.22`
**Priority**: `priority/p1-high`
**Scope**: `type/feature`, `scope/k8s`, `priority/p1-high`
Expand All @@ -11,13 +11,45 @@

## 1. Description & Objectives

GitOps fleet synchronization currently depends on external `argocd` and `kubectl-argo-rollouts` binary installations, creating environment friction and shallow subprocess orchestration.
GitOps fleet synchronization, workflow orchestration, and progressive delivery depended on external `argocd`, `argo`, `kubectl`, and `kubectl-argo-rollouts` binary installations, creating environment friction on CI runners and developer workstations and reducing every operation to a shell return-code check. This deliverable introduces `ArgoCRDService`, which reads and mutates Argo custom resources in-process through the official Kubernetes `CustomObjectsApi`, and projects every response into typed Pydantic state models.

#### Key Deliverables:
- Context & Rationale*: GitOps fleet synchronization currently depends on external `argocd` and `kubectl-argo-rollouts` binary installations, creating environment friction and shallow subprocess orchestration.
- Deep Integration & Functional Extension*: Native gRPC and REST client integration directly with the ArgoCD API server; direct Kubernetes Custom Resource Definition (`Application`, `ApplicationSet`, `Rollout`) manipulation; automated Canary rollout analysis verifying Prometheus SLO thresholds during progressive delivery.
- Code Optimization & Performance Acceleration*: Eliminate external CLI binary prerequisites across CI runners and developer workstations; execute multi-application fleet synchronization queries in parallel over a single multiplexed HTTP/2 connection.
- Refactoring Potential & Legacy Elimination*: Consolidate `src/devops_cli/commands/argo.py` into a declarative GitOps engine; replace shell returncode checks with typed gRPC status exceptions; eliminate procedural sync polling loops.
- Unit and integration test coverage with structural tuple equality assertions.
- Maintain cyclomatic complexity $M \le 10$ and nesting depth $\le 5$.
- 100% passing across Gated CI validation suite (`uv run devops ci`).
### Key Deliverables Completed:

- [x] **ArgoCRDService Architecture (`src/devops_cli/argo/crd.py`)**:
- Direct in-process manipulation of the `argoproj.io` API group via `CustomObjectsApi`, reusing the cached client and kubeconfig resolution already provided by `KubernetesService`.
- Generic custom resource access (`list_resources`, `get_resource`, `patch_resource`, `apply_resource`) with `apply_resource` creating a resource and patching it in place when it already exists.
- Typed accessors for Applications, ApplicationSets, Rollouts, AnalysisRuns, and Workflows.
- `workflow_pod_names` resolves the Pod-type DAG nodes backing a Workflow so logs stream natively through `KubernetesService.read_pod_logs`.
- [x] **CustomObjectsApi Exposure (`src/devops_cli/k8s/service.py`)**:
- New `custom_objects_api()` accessor constructing and caching `CustomObjectsApi` alongside the existing Core, Apps, and Version clients, raising `KubernetesContextError` when the cluster is unreachable.
- [x] **Native Rollout Control-Plane Mutations (`src/devops_cli/argo/rollouts.py`)**:
- `promote_rollout`, `abort_rollout`, and `restart_rollout` now patch the exact control-plane fields the rollouts controller watches — clearing `status.pauseConditions` / `status.controllerPause` (with `status.promoteFull` for a full promotion), setting `status.abort`, and stamping `spec.restartAt` — instead of shelling out to `kubectl argo rollouts`.
- Shared `_mutate_rollout` helper centralizes validation, dry-run short-circuiting, and typed error handling.
- [x] **Command Refactoring (`src/devops_cli/commands/argo.py`)**:
- `devops argo workflows list` / `submit` / `logs` read, submit, and stream natively; `--wait` polls the Workflow to a terminal phase under a bounded budget and exits non-zero on `Failed` / `Error`.
- `devops argo rollouts list` / `status` render typed progressive delivery state, including canary step position and replica counts, with `--watch` driven by `LiveResourceWatcher`.
- `devops argo cd apps bootstrap-gitops` applies the root Application manifest through the API server instead of `kubectl apply -f`.
- [x] **Typed Pydantic State Models (`src/devops_cli/models/argo.py`)**:
- `ArgoResourceState`, `ArgoRolloutState`, and `ArgoWorkflowState` replace stdout scraping, tolerating absent, null, and wrongly typed resource sections.
- [x] **Typed Exception Hierarchy (`src/devops_cli/exceptions/argo.py`)**:
- `ArgoError` and `ArgoResourceNotFoundError` with dedicated error codes, replacing shell return-code checks; HTTP 404 is distinguished from transport failures.
- Name validation inside the service raises `ArgoError` rather than `typer.Exit`, since the service is consumed by FastMCP tools and the TUI as well as the CLI.
- [x] **Centralized Constants & Defaults**:
- API group, version, resource plurals, Rollout control-plane field names, and terminal Workflow phases centralized in `src/devops_cli/config/constants.py`.
- Rollout watch interval and Workflow poll/wait budgets centralized in `src/devops_cli/config/defaults.py`.
- [x] **Automated Tests & Quality Gates**:
- 28 unit tests in `tests/test_argo_crd.py` using structural tuple equality assertions, covering client resolution, error translation, manifest application, rollout mutations, workflow projection, and sparse/malformed payload tolerance.
- Existing rollout and CLI suites migrated from subprocess assertions to control-plane patch assertions.
- `src/devops_cli/argo/crd.py` at 99% coverage; 119 Argo tests passing.
- Cyclomatic complexity $M \le 10$ and nesting depth $\le 5$ maintained.
- 100% passing status across Gated CI validation suite (`uv run devops ci`).

## Verification Results

- `uv run devops ci` — all gates pass (tests, coverage $\ge 90\%$, lint, format, mypy strict, audit, security, actionlint, docs, uv check, lockfile).
- `devops scan complexity` clean across `src/devops_cli/argo`.
- No `argo`, `argocd`, `kubectl`, or `kubectl argo rollouts` subprocess invocations remain in the Argo command group or package.

## Deferred

Native gRPC integration with the ArgoCD API server is not included. The existing authenticated REST client (`devops argo cd apps list` / `status` / `sync`) already multiplexes over HTTP/2 via `httpx2`, and CRD reconciliation through the Kubernetes API server covers the deliverable's fleet synchronization and progressive delivery objectives without introducing a protobuf toolchain dependency. Automated canary metric verification against Prometheus SLO thresholds continues to be served by `evaluate_rollout_gate`, which now drives aborts through the native control-plane patch path.
Loading
Loading