DRAFT: Feat agentruntime controller#218
Draft
varshaprasad96 wants to merge 4 commits intokagenti:mainfrom
Draft
Conversation
Add deterministic SHA256 config hash computation that merges AgentRuntime spec fields with platform defaults from the kagenti-webhook-defaults ConfigMap. The hash is used as a PodTemplateSpec annotation to trigger rolling updates when configuration changes. - ComputeConfigHash: merges spec + defaults into canonical JSON - ComputeDefaultsOnlyHash: defaults-only hash for CR deletion - Deterministic output via sorted-key JSON serialization - Graceful fallback when defaults ConfigMap is missing Includes unit tests covering determinism, change detection across type/trace/identity fields, defaults-only vs spec+defaults differentiation, and missing ConfigMap handling. Signed-off-by: Varsha Prasad Narsing <varshaprasad96@gmail.com> Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Implement the AgentRuntime reconciler that watches AgentRuntime CRs and applies configuration to target workloads via targetRef. Controller responsibilities: - Resolve targetRef to Deployment/StatefulSet (duck typing) - Apply kagenti.io/type label to workload metadata and PodTemplateSpec - Apply kagenti.io/config-hash annotation to PodTemplateSpec to trigger rolling updates on config changes - Apply app.kubernetes.io/managed-by label to workload metadata - Count configured pods and update status (phase, conditions) - Finalizer (kagenti.io/cleanup) preserves type label on deletion and updates config-hash to defaults-only Also: - Wire controller into cmd/main.go - Regenerate RBAC manifests for agentruntimes resources Signed-off-by: Varsha Prasad Narsing <varshaprasad96@gmail.com> Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Add Ginkgo/envtest integration tests covering the AgentRuntime controller lifecycle: - Finalizer added on first reconcile - Labels and config-hash applied to target Deployment - Status set to Active after successful configuration - Config-hash updates when spec changes (trace config) - Error status with TargetNotFound when target is missing - Deletion preserves type label, updates config-hash to defaults, removes managed-by label - Tool runtime type correctly applied Signed-off-by: Varsha Prasad Narsing <varshaprasad96@gmail.com> Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
MUST FIX:
- Use time.Second instead of raw nanosecond arithmetic for RequeueAfter
- Fix no-op check in applyWorkloadConfig to compare original labels
before mutation, not after
- Fix handleDeletion to properly check NotFound before updating
workload (was using client.IgnoreNotFound which allowed updates
on zero-value objects)
- Remove unused unstructured parameter from applyWorkloadConfig
(resolveTargetRef now only checks existence)
SHOULD FIX:
- Rename LabelConfigHash to AnnotationConfigHash (it's an annotation)
- Use consistent RequeueAfter strategy for all transient errors
- Remove unused ctx parameter from setPhase
- Simplify config_hash.go: remove sortedDefaults copy and marshalSorted
double-serialization (encoding/json already sorts map keys)
- Document isPodOwnedByWorkload prefix-matching limitation
- Use kebab-case controller name ("agentruntime" not "AgentRuntime")
Signed-off-by: Varsha Prasad Narsing <varshaprasad96@gmail.com>
Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
8a4626a to
f526405
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements Phase 1 of the AgentRuntime epic (kagenti/kagenti#862) — the CRD definition, controller with label management, config hash computation, and tests.
AgentRuntime is the declarative way to enroll a workload into the Kagenti platform. Instead of manually adding kagenti.io/type labels to Deployment manifests, developers create an AgentRuntime CR with a targetRef pointing to their workload. The controller applies labels and config-hash annotations to the PodTemplateSpec, triggering rolling updates when configuration changes.
What's included
How it works
What's NOT included (follow-up PRs)
Related issue(s)
(Optional) Testing Instructions
Fixes #