feat: auto-label namespaces with Istio ambient mesh on AgentRuntime reconcile#403
Conversation
Add ensureIstioMeshLabels() to AgentRuntime reconciler that patches namespaces with istio-discovery=enabled and istio.io/dataplane-mode=ambient for ztunnel L4 mTLS enrollment. - Opt-out via kagenti.io/istio-mesh=disabled annotation - IstioMeshEnrolled status condition (True/False with reason) - Non-fatal: reconcile continues if patch fails - Short-circuits when labels already present - RBAC: namespace patch verb added to manager-role Signed-off-by: Ian Miller <milleryan2003@gmail.com>
5 envtest cases for ensureIstioMeshLabels: - bare namespace gets labels - idempotent on already-labeled namespace - opt-out annotation skipped - existing labels preserved - non-"disabled" annotation value still labels Signed-off-by: Ian Miller <milleryan2003@gmail.com>
5 e2e test cases in new Describe("Istio Mesh Enrollment E2E"):
- namespace auto-labeled on AgentRuntime create
- IstioMeshEnrolled condition set to True
- opt-out annotation prevents labeling
- labels survive AgentRuntime deletion
- drift recovery via reconcile
Signed-off-by: Ian Miller <milleryan2003@gmail.com>
- api-reference.md: document IstioMeshEnrolled condition variants - architecture.md: add namespace patch verb to RBAC table Signed-off-by: Ian Miller <milleryan2003@gmail.com>
b9c12f3 to
8cb9a4c
Compare
pdettori
left a comment
There was a problem hiding this comment.
Clean, well-structured PR. The ensureIstioMeshLabels() implementation correctly uses MergeFrom(DeepCopy()) for safe namespace patching, handles opt-out via annotation, short-circuits when labels already present, and is properly non-fatal. RBAC is correctly scoped (only patch added to namespaces, services split into read-only rule). Unit tests cover the main paths and E2E tests verify real cluster behavior including drift recovery. All CI checks pass.
Areas reviewed: Go (implementation + tests), YAML/RBAC, Docs
Commits: 4, all signed-off ✓
CI: 15/15 passing ✓
| | `SkillsDiscovered` | True | `SkillsFound` | Linked skills discovered from `kagenti.io/skills` annotation on the target workload | | ||
| | `SkillsMounted` | True | `SkillsApplied` | OCI skill ImageVolumes applied to the target workload | | ||
| | `SkillsMounted` | False | `FeatureGateDisabled` | Skills defined but `skillImageVolumes` feature gate is disabled | | ||
| | `SkillsMounted` | False | `UnsupportedWorkloadKind` | Skills defined but the target workload kind (e.g., Sandbox) does not support skill ImageVolumes | |
There was a problem hiding this comment.
suggestion: SkillsMounted condition docs (lines 483-485) appear unrelated to the Istio mesh enrollment feature — this condition isn't implemented anywhere in this diff. Consider moving to a separate commit or the PR that introduces the SkillsMounted logic, to keep this PR focused on its stated scope.
Summary
Automatically labels namespaces with Istio ambient mesh labels when an AgentRuntime CR is reconciled, enabling ztunnel L4 mTLS for agent-to-agent traffic without manual namespace configuration.
Jira: [RHAIENG-5502]
What it does
istio-discovery=enabledandistio.io/dataplane-mode=ambientduring AgentRuntime reconciliationIstioMeshEnrolledstatus condition on the AgentRuntime CR (True/Falsewith reason)kagenti.io/istio-mesh=disabledto skip labelingChanges
internal/controller/agentruntime_istio.goensureIstioMeshLabels()method, constants, RBAC markerinternal/controller/agentruntime_controller.goconfig/rbac/role.yamlpatchverb added for namespacesinternal/controller/agentruntime_istio_test.gotest/e2e/e2e_test.gotest/e2e/fixtures.godocs/api-reference.mdIstioMeshEnrolledconditiondocs/architecture.mdpatchto RBAC tableDesign decisions
ensureNamespaceConfigMaps)Test plan
make test— all existing + 5 new unit tests passmake manifests— RBAC generated correctlyCross-Namespace L4 mTLS Verification — OpenShift (RHAIENG-5502)
Setup
Two agents in separate namespaces, neither pre-labeled with Istio labels.
The operator auto-labels each namespace when its AgentRuntime CR is reconciled.
mesh-agent-aagent-a(quay.io/redhattraining/hello-world-nginx:v1.0, port 8080) + Servicemesh-agent-bagent-b(quay.io/curl/curl:8.5.0, sleep container)1. Cross-Namespace Traffic
2. ztunnel Logs — L4 mTLS Proof
ztunnel enrolled pods from both namespaces
Inbound (ztunnel terminates mTLS, delivers to agent-a)
Outbound (ztunnel intercepts agent-b, wraps in mTLS)
Key mTLS Indicators
ns/mesh-agent-b→ns/mesh-agent-a3. Namespace Labels
Both namespaces auto-labeled by operator — no manual labeling required.
4. AgentRuntime Status — mesh-agent-a
5. AgentRuntime Status — mesh-agent-b
Summary
Closes #399
Signed-off-by: Ian Miller milleryan2003@gmail.com
🤖 Co-Authored with Claude Code