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/agent/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
| [#172](https://github.com/dan-petty/devops-cli/issues/172) | [#174](https://github.com/dan-petty/devops-cli/pull/174) | Configurable K8s context setting and conditional Minikube autostart | `Done` | [`task-172-k8s-context-minikube-autostart.md`](tasks/task-172-k8s-context-minikube-autostart.md) |
| [#175](https://github.com/dan-petty/devops-cli/issues/175) | [#173](https://github.com/dan-petty/devops-cli/pull/173) | Project field options synchronization, complete pagination & generic owner resolution | `Done` | [`task-175-project-field-sync-pagination.md`](tasks/task-175-project-field-sync-pagination.md) |
| [#176](https://github.com/dan-petty/devops-cli/issues/176) | [#177](https://github.com/dan-petty/devops-cli/pull/177) | Remediate DevSecOps review findings & enhance review self-improvement loop | `In Review` | [`task-176-review-findings-self-improvement.md`](tasks/task-176-review-findings-self-improvement.md) |
| [#183](https://github.com/dan-petty/devops-cli/issues/183) | [#182](https://github.com/dan-petty/devops-cli/pull/182) | Resolve Helm Stack Deploy SSA Conflicts, Loki Validation, and PodSecurity Failures | `In Review` | [`task-183-stack-deploy-conflicts.md`](tasks/task-183-stack-deploy-conflicts.md) |


---

Expand Down
44 changes: 44 additions & 0 deletions docs/agent/tasks/task-183-stack-deploy-conflicts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Task 183: Resolve Helm Stack Deploy SSA Conflicts, Loki Validation, and PodSecurity Failures

**Issue**: [#183](https://github.com/dan-petty/devops-cli/issues/183)
**PR**: [#182](https://github.com/dan-petty/devops-cli/pull/182)
**Status**: In Review
**Milestone**: `v0.2.17`
**Priority**: `priority/p1-high`
**Scope**: `scope/k8s`

---

## 1. Description & Architectural Objectives

Resolve the 5 deployment errors encountered during `devops k8s deploy-stack --stack all`:
1. **ArgoCD, Kube-Prometheus, and Qdrant SSA Field Conflicts**:
- Helm v4 Server-Side Apply fails when resources were previously touched by `kubectl-set` or `kubectl-patch`.
- Remediate by passing `--force-conflicts` in `helm upgrade --install` invocations in `stack_lifecycle.py`.
2. **Loki Chart Template Validation Failure**:
- Chart `grafana/loki` requires `read.replicas: 0`, `write.replicas: 0`, and `backend.replicas: 0` when `deploymentMode: SingleBinary` is configured.
3. **Fluent-Bit DaemonSet Admission Block**:
- Namespace `logging` was set to `pod-security.kubernetes.io/enforce: baseline`, which rejects hostPath volumes required by Fluent-Bit to tail `/var/log`.
- Update namespace `logging` to `privileged` standard (consistent with `monitoring` and `llm`).
4. **Fluent-Bit Invalid Output Plugin**:
- Fluent-Bit v5 deprecated and removed `grafana-loki` in favor of core `Name loki`.
- Update `fluent-bit-values.yaml` to use `Name loki`.
5. **Qdrant InitContainer Ownership Error**:
- The default `ensure-dir-ownership` container attempts `chown` as unprivileged user 1000.
- Disable via `updateVolumeFsOwnership: false` since `podSecurityContext.fsGroup: 1000` already ensures proper group ownership.

---

## 2. Implementation Checklist

- [x] Ground issue [#183](https://github.com/dan-petty/devops-cli/issues/183) in GitHub tracking and sync project view
- [x] Author dedicated task tracking file `docs/agent/tasks/task-183-stack-deploy-conflicts.md`
- [x] Update `src/devops_cli/commands/k8s/stack_lifecycle.py` to pass `--force-conflicts` on Helm upgrades
- [x] Update `k8s/namespaces.yaml` namespace `logging` PodSecurity standard to `privileged`
- [x] Update `k8s/logging/loki-values.yaml` with `read.replicas: 0`, `write.replicas: 0`, `backend.replicas: 0`
- [x] Update `k8s/logging/fluent-bit-values.yaml` to use output plugin `Name loki`
- [x] Update `k8s/llm/values-qdrant.yaml` to set `updateVolumeFsOwnership: false`
- [x] Add unit test in `tests/test_k8s.py` verifying `--force-conflicts` flag
- [x] Verify template rendering for Loki, Fluent-Bit, and Qdrant
- [x] Verify local quality gates via `uv run pytest` and `devops ci`
- [x] Verify live deployment via `devops k8s deploy-stack --stack all`
3 changes: 3 additions & 0 deletions k8s/llm/values-qdrant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@ podSecurityContext:
runAsUser: 1000
runAsGroup: 1000
fsGroup: 1000

# fsGroup: 1000 manages volume permissions; disable root chown initContainer
updateVolumeFsOwnership: false
4 changes: 2 additions & 2 deletions k8s/logging/fluent-bit-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ config:

outputs: |
[OUTPUT]
Name grafana-loki
Name loki
Match kube.*
host loki.logging.svc.cluster.local
port 3100
labels job=fluent-bit, namespace=$kubernetes['namespace_name'], pod=$kubernetes['pod_name'], container=$kubernetes['container_name']
labels job=fluent-bit
auto_kubernetes_labels on
10 changes: 10 additions & 0 deletions k8s/logging/loki-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@ chunksCache:

resultsCache:
enabled: false

# Zero out scalable targets to satisfy SingleBinary deploymentMode validation
read:
replicas: 0

write:
replicas: 0

backend:
replicas: 0
6 changes: 3 additions & 3 deletions k8s/namespaces.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ metadata:
name: logging
labels:
app.kubernetes.io/part-of: devops-cli-stack
pod-security.kubernetes.io/enforce: baseline
pod-security.kubernetes.io/warn: baseline
pod-security.kubernetes.io/audit: baseline
pod-security.kubernetes.io/enforce: privileged
pod-security.kubernetes.io/warn: privileged
pod-security.kubernetes.io/audit: privileged
Comment thread
dan-petty marked this conversation as resolved.
Resolved
---
apiVersion: v1
kind: Namespace
Expand Down
1 change: 1 addition & 0 deletions src/devops_cli/commands/k8s/stack_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ def deploy_stack(
"helm",
"upgrade",
"--install",
"--force-conflicts",
Comment thread
dan-petty marked this conversation as resolved.
Resolved
release["name"],
release["chart"],
"--namespace",
Expand Down
34 changes: 34 additions & 0 deletions tests/test_k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@ def test_k8s_deploy_stack_no_wait() -> None:
cmd = call_args[0][0]
if isinstance(cmd, list) and "helm" in cmd and "upgrade" in cmd:
assert "--wait" not in cmd
assert "--force-conflicts" in cmd
Comment thread
dan-petty marked this conversation as resolved.
Resolved


def test_k8s_workload_resource_limits_and_probes() -> None:
Expand Down Expand Up @@ -896,3 +897,36 @@ def test_k8s_workload_resource_limits_and_probes() -> None:
assert gfd_res["requests"]["memory"] == "64Mi"
assert gfd_res["limits"]["cpu"] == "200m"
assert gfd_res["limits"]["memory"] == "256Mi"


def test_k8s_stack_deploy_ssa_and_manifest_contracts() -> None:
"""Verify deploy-stack enforces --force-conflicts and k8s manifests meet security & chart contracts."""
repo_root = Path(__file__).resolve().parent.parent

# 1. Namespaces: logging has privileged pod-security standard for hostPath daemonset
ns_docs = list(
yaml.safe_load_all((repo_root / "k8s" / "namespaces.yaml").read_text(encoding="utf-8"))
)
logging_ns = next(d for d in ns_docs if d and d.get("metadata", {}).get("name") == "logging")
assert logging_ns["metadata"]["labels"]["pod-security.kubernetes.io/enforce"] == "privileged"

# 2. Loki values: zeroed scalable target replicas for SingleBinary mode
loki_values = yaml.safe_load(
(repo_root / "k8s" / "logging" / "loki-values.yaml").read_text(encoding="utf-8")
)
assert loki_values["read"]["replicas"] == 0
assert loki_values["write"]["replicas"] == 0
assert loki_values["backend"]["replicas"] == 0

# 3. Fluent-bit values: official loki output plugin
fb_values = yaml.safe_load(
(repo_root / "k8s" / "logging" / "fluent-bit-values.yaml").read_text(encoding="utf-8")
)
assert "Name loki" in fb_values["config"]["outputs"]
assert "grafana-loki" not in fb_values["config"]["outputs"]

# 4. Qdrant values: disabled unprivileged volume chown initContainer
qdrant_values = yaml.safe_load(
(repo_root / "k8s" / "llm" / "values-qdrant.yaml").read_text(encoding="utf-8")
)
assert qdrant_values["updateVolumeFsOwnership"] is False
Loading