Skip to content

epic: AgentRuntime CR — CR-triggered injection for the Kagenti platform #862

Closed

Description

@cwiklik

Problem

Summary

Implement the AgentRuntime CRD and controller in the kagenti-operator. AgentRuntime is the single source of truth for enrolling a workload into the Kagenti platform — it triggers sidecar injection and provides per-workload configuration overrides.

The operator already manages AgentCard CRs. AgentRuntime follows the same patterns (kubebuilder, controller-runtime, TargetRef duck typing) and lives alongside AgentCard in api/v1alpha1.

Motivation

Today, developers must add kagenti.io/type: agent labels to their Deployment manifests to trigger webhook injection. This creates an ownership inversion — developers modify workloads for what is fundamentally a platform concern. It also causes GitOps drift when the webhook mutates the Deployment.

With AgentRuntime:

  • Developer deploys a standard workload with no kagenti labels
  • Developer creates an AgentRuntime CR with targetRef pointing to the workload
  • The controller applies labels to the PodTemplateSpec, triggering a rolling update
  • The webhook injects sidecars at Pod CREATE time
  • Developer workloads stay clean

How it works

  1. Developer deploys a standard Deployment (no kagenti labels)
  2. Developer creates an AgentRuntime CR with targetRef pointing to the Deployment
  3. AgentRuntime controller reconciles:
    • Resolves targetRef to the target workload
    • Computes a config hash from the AgentRuntime spec merged with ConfigMap defaults
    • Applies kagenti.io/type: agent|tool label to the Deployment's PodTemplateSpec
    • Applies kagenti.io/config-hash: <hash> annotation to the PodTemplateSpec
    • May apply labels to the Deployment metadata for UI/TUI/API discovery
  4. PodTemplateSpec change triggers a rolling update
  5. Kubernetes creates new Pods — the admission webhook intercepts Pod CREATE and injects sidecars
  6. On AgentRuntime update: config-hash changes, rolling update, webhook re-injects with new config
  7. On AgentRuntime delete: finalizer preserves kagenti.io/type label, updates config-hash to defaults-only, rolling update redeploys with platform defaults

Scope: lean v1alpha1

The CRD is intentionally scoped to what we need for Summit. Fields not in v1alpha1 are deferred, not rejected.

In scope (v1alpha1):

  • spec.type — agent or tool
  • spec.targetRef — duck-typed workload reference (reuse existing TargetRef from AgentCard)
  • spec.identity.spiffe.trustDomain — override SPIFFE trust domain
  • spec.identity.clientRegistration.provider — IdP provider (keycloak)
  • spec.identity.clientRegistration.realm — IdP realm
  • spec.identity.clientRegistration.adminCredentialsSecret — secret reference
  • spec.trace.endpoint — OTEL collector endpoint
  • spec.trace.protocol — grpc or http
  • spec.trace.sampling.rate — sampling rate (0.0-1.0)
  • status.phase — Active, Pending, Error
  • status.configuredPods — count of pods with injected sidecars
  • status.conditions — standard metav1.Conditions

Deferred (post-Summit):

  • spec.trace.genai — GenAI capture (prompts, completions)
  • spec.trace.integration — MLflow, Prometheus integration
  • spec.trace.exporters — multiple exporter support
  • spec.trace.resourceAttributes — custom OTEL resource attributes

Progress tracker

Update checkboxes as work progresses. Each item links to its sub-issue below.

Last updated: 2026-04-15. Note: webhook was migrated from kagenti-extensions into kagenti-operator (PR #261).

Phase 1: CRD and core controller

Phase 2: Webhook coordination and RBAC

Phase 3: Helm and platform integration

  • Helm chart updates — operator (kagenti-operator#261 — chart 0.2.0-alpha.24)
  • Helm chart updates — platform chart (kagenti#1153 — switched to operator chart)
  • Example agents updated to use AgentRuntime CRs (kagenti#1153 — backend creates/deletes AgentRuntime CRs)

Phase 4: E2E and documentation

  • E2E tests on Kind (kagenti-operator#270 merged, 8 test scenarios, all CI green)
  • Documentation updates (kagenti-operator#290 — GETTING_STARTED.md, architecture RBAC tables, controller-webhook interaction doc, sample YAMLs)
  • Argo CD compatibility guide

Final

  • All CI passing
  • Design proposal updated to reflect implementation
  • Demo-ready on Kind cluster (validated by E2E tests in kagenti-operator#270)

Sub-issues

1. AgentRuntime CRD definition

Repo: kagenti-operator
Path: kagenti-operator/api/v1alpha1/agentruntime_types.go
Status: Done (kagenti-operator#212, #254)

Tasks:

  • Define AgentRuntimeSpec, AgentRuntimeStatus structs with kubebuilder markers
  • Reuse existing TargetRef type from agentcard_types.go
  • Add spec.type field with enum validation (agent or tool)
  • Add spec.identity section (spiffe trustDomain, clientRegistration provider/realm/secret)
  • Add spec.trace section (endpoint, protocol, sampling rate)
  • Add status.phase, status.configuredPods, status.conditions
  • Run make generate and make manifests to generate deepcopy and CRD YAML
  • Add printer columns: NAME, TYPE, TARGET, PHASE, AGE
  • Verify: kubectl apply the CRD successfully
  • Verify: kubectl get agentruntime shows printer columns
  • Verify: CRD validation rejects invalid specs (missing targetRef, invalid type)

2. AgentRuntime controller — label management

Repo: kagenti-operator
Path: kagenti-operator/internal/controller/agentruntime_controller.go
Status: Done (kagenti-operator#218, #242)

Tasks:

  • Scaffold controller with kubebuilder
  • Implement reconcile loop: watch AgentRuntime CRs for create/update/delete
  • Add finalizer (kagenti.io/cleanup) on AgentRuntime creation
  • On create/update:
    • Resolve targetRef to find target Deployment/StatefulSet (duck typing)
    • Compute config hash from spec
    • Apply kagenti.io/type: <spec.type> label to PodTemplateSpec
    • Apply kagenti.io/config-hash: <hash> annotation to PodTemplateSpec
    • Apply discovery labels to Deployment metadata (kagenti.io/type, app.kubernetes.io/managed-by: kagenti-operator)
    • Update AgentRuntime status (phase, configuredPods, conditions)
  • On delete (finalizer):
    • Preserve kagenti.io/type label on PodTemplateSpec
    • Update kagenti.io/config-hash to defaults-only hash (triggers rolling update)
    • Remove finalizer
  • Handle missing target workload gracefully (status condition = Error)
  • Handle target workload deletion (status condition = TargetNotFound)
  • Set up RBAC: get/list/watch/patch on deployments, statefulsets; get/list/watch on configmaps
  • Validating webhook for duplicate targetRef rejection (kagenti-operator#242)

3. Config hash computation

Repo: kagenti-operator
Path: kagenti-operator/internal/controller/config_hash.go
Status: Done (kagenti-operator#218, verified in #266)

Tasks:

  • Read platform defaults from ConfigMap (
    kagenti-webhook-defaults in kagenti-webhook-system namespace)
  • Merge AgentRuntime spec with defaults (spec fields override defaults)
  • Compute SHA256 hash of AgentRuntime spec
  • Ensure hash is deterministic (sorted keys, stable serialization)
  • When AgentRuntime is deleted, compute hash from defaults only
  • Verify: same spec + same defaults = same hash
  • Verify: changing any field produces a different hash
  • Verify: defaults-only hash differs from spec+defaults hash

4. RBAC and webhook coordination

Repo: kagenti-operator
Path: kagenti-operator/config/rbac/
Status: Done — webhook migrated from kagenti-extensions into kagenti-operator (#261, #249, #245)

Tasks:

  • Add RBAC for controller to patch Deployments and StatefulSets (PodTemplateSpec)
  • Add RBAC for controller to read ConfigMaps in kagenti-webhook-system
  • Coordinate with kagenti-extensions webhook changes Webhook migrated into operator (#261):
    • Webhook targets Pods at CREATE time (objectSelector on kagenti.io/type)
    • Webhook reads AgentRuntime CR to merge config at admission time
    • Webhook falls back to ConfigMap defaults when no AgentRuntime CR found
  • Document controller-webhook interaction (kagenti-operator#290 — sequence diagrams + responsibility split)
  • Verify: controller can patch target workloads across namespaces
  • Verify: webhook correctly merges config from AgentRuntime CR
  • Verify: webhook uses defaults when CR does not exist

5. Unit and integration tests

Repo: kagenti-operator
Path: kagenti-operator/internal/controller/agentruntime_controller_test.go
Status: Unit + envtest done (kagenti-operator#266); E2E done (#270 merged)

Tasks:

  • Unit tests: config hash computation
    • Deterministic output
    • Changes on spec change
    • Defaults-only vs spec+defaults
  • Unit tests: targetRef resolution
    • Deployment target
    • StatefulSet target
    • Missing target (error path)
  • Integration tests (envtest, Ginkgo/Gomega — follow agentcard_controller_test.go patterns):
    • Create AgentRuntime → labels added to target PodTemplateSpec
    • Update AgentRuntime → config-hash changes
    • Delete AgentRuntime → type label preserved, config-hash updated
    • AgentRuntime with missing target → error status
    • Target workload deleted after AgentRuntime created → status update
  • make test passes with all new tests

6. Helm chart updates

Repo: kagenti-operator (charts/) and kagenti (charts/kagenti/)
Status: Done (kagenti-operator#261, kagenti#1153)

Tasks:

  • Add AgentRuntime CRD to operator Helm chart
  • Add RBAC for new controller permissions in operator chart
  • Update kagenti platform chart to generate AgentRuntime CRs for example agents
  • Remove kagenti.io/type labels from example agent Deployment manifests
  • Verify: helm template renders correctly
  • Verify: helm install deploys operator with AgentRuntime CRD
  • Verify: existing AgentCard functionality not affected

7. E2E tests

Repo: kagenti-operator (kagenti-operator/test/e2e/)
Status: Done (kagenti-operator#270 merged, 8 test scenarios, all CI green)

Tasks:

  • Test: deploy agent without labels + create AgentRuntime CR → labels appear on PodTemplateSpec
  • Test: verify pods get sidecars injected after AgentRuntime creation
  • Test: update AgentRuntime → rolling update with new config
  • Test: delete AgentRuntime → pods redeployed with platform defaults
  • Test: opt-out — add kagenti.io/inject: disabled to PodTemplateSpec → no injection
  • All E2E tests pass on Kind cluster

8. Documentation

Repo: kagenti-operator (kagenti-operator/docs/)
Status: Partially done (kagenti-operator#290 merged)

Tasks:

  • Update design proposal (PR 📝 Consolidated compositional agent platform design proposal #770) to reflect MVP implementation
  • Add AgentRuntime user guide:
    • When to create an AgentRuntime CR
    • Minimal example (just targetRef + type)
    • Full example with identity and trace overrides
  • Document Argo CD compatibility:
    • Per-Application ignoreDifferences configuration
    • Cluster-wide argocd-cm configuration
  • Update install guide with new RBAC requirements

Dependencies

Dependency Repo Status Notes
Webhook targets Pods at CREATE time kagenti-operator (migrated from extensions) Done kagenti-operator#261; extensions#176 closed
Webhook reads AgentRuntime CR for config merging kagenti-operator (migrated from extensions) Done kagenti-operator#245, #261; extensions#177 closed
Platform Helm chart generates AgentRuntime CRs kagenti Done kagenti#1153

Out of scope

  • Layered CRD defaults (AgentRuntimeClusterConfig / AgentRuntimeConfig) — ConfigMaps sufficient for MVP
  • xDS config propagation — ConfigMap volume mounts sufficient for MVP
  • Sidecar consolidation (4 containers to fewer) — separate effort

design

No response

Goals and non-goals

No response

Success criteria

  • Developer deploys a standard Deployment (no kagenti labels) + creates an AgentRuntime CR → sidecars are injected into pods with correct configuration
  • kubectl get agentruntime -A shows all enrolled workloads with NAME, TYPE, TARGET, PHASE columns
  • Updating an AgentRuntime CR triggers a rolling update and pods receive updated sidecar configuration
  • Deleting an AgentRuntime CR preserves the type label and redeploys pods with platform defaults
  • Developer can opt out of injection with kagenti.io/inject: disabled
  • Webhook targets Pods at CREATE time — Deployment objects in etcd are not mutated by the webhook
  • All unit, integration, and E2E tests pass on Kind cluster (kagenti-operator#270 merged, all CI green)
  • Demo-ready: full agent lifecycle (create, update, delete AgentRuntime) works end-to-end on Kind

Stories to be associated with this epic

No response

Additional Context

No response

Activity

  1. added
    enhancement
    high priority
    on Mar 6, 2026
  2. added theissue type on Mar 6, 2026
  3. removed
    high priority
    on Mar 25, 2026
  4. pdettori commented on Apr 16, 2026

    @pdettori
    Member

    Status update (2026-04-15)

    Checked off completed items based on merged PRs:

    Remaining open items — @varshaprasad96 @cwiklik

    The following items are still unchecked. Can you clarify their status or whether they're still needed?

    1. Argo CD compatibility guide (Phase 4 tracker + sub-issue Update for Llama Stack 0.2.3 #8) — Is this still planned? No docs or PRs found for ignoreDifferences configuration or argocd-cm setup. Should this be a separate issue?

    2. Design proposal update (Final section) — PR 📝 Consolidated compositional agent platform design proposal #770 was merged on 2026-04-13. Does that satisfy "Design proposal updated to reflect implementation", or does 📝 Consolidated compositional agent platform design proposal #770 need a follow-up PR to reflect the final implementation details?

    3. Install guide update with new RBAC requirements (sub-issue Update for Llama Stack 0.2.3 #8) — The RBAC tables were added to architecture.md in bug: Weather tool does not start #290. Is a separate install guide update still needed, or does the architecture doc cover it?

    Once these are resolved, the epic can be closed.

  5. added
    epic
    on Apr 29, 2026
  6. moved this from New /:ToDo to Epics in Rossoctl Issue Prioritizationon May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementepic

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions