Repository navigation
fix(operator): KapeAgentServer reconcile never converges (metadata clobber + API defaults) - #272
Merged
Merged
Conversation
… loop The previous fix enumerated the API-defaulted Deployment fields by hand and missed revisionHistoryLimit/progressDeadlineSeconds (and would miss the next one). Generation kept churning on the live cluster at ~10/s, so the CR still never reached Ready. Replace the hand-written inheritance with a structural rule: walk desired vs live and copy every unset (zero) field from live, recursively through structs, pointers and same-length slices, and whole-value for map entries. Env vars are excluded — their Name/Value are renderer-owned and an intentionally empty value must not be back-filled from the live object. Test extended with the Deployment-level defaults (strategy, revisionHistoryLimit, progressDeadlineSeconds).
… them
ensure() assigned the rendered label and annotation maps wholesale, so the
merge patch carried {"metadata":{"annotations":null}} on every reconcile and
deleted annotations the platform maintains. On the live cluster that removed
deployment.kubernetes.io/revision, the Deployment controller re-added it
immediately, and the object was rewritten in a loop: generation 4166 -> 4172 in
20s while status.observedGeneration stayed pinned, so DeploymentStatus never
reported available and KapeAgentServer stayed Ready=False (Progressing).
Found by running a debug build of this operator against the cluster: the delta
was metadata.annotations:null and nothing else.
Merge base maps with the rendered keys winning; a nil rendered map leaves the
existing metadata untouched. New test asserts a foreign annotation and label
survive and that a re-apply does not patch.
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.
The KapeAgentServer reconciler never reached a steady state on a live cluster:
deployment.kubernetes.io/revisionwas deleted and re-added in a loop,metadata.generationran ahead ofstatus.observedGeneration(~7/s), and the CR stayedReady=False (Progressing: controller Deployment … is not available yet)even though the pod was 1/1 Ready withavailableReplicas=1.Two independent causes, one commit each.
1.
ensure()clobbered metadata (eff029c)A merge patch against a live object turns "nil map" into
{"metadata":{"annotations":null}}, deleting annotations the platform owns. Captured by running a debug build against the cluster — the entire delta was:{"metadata":{"annotations":null}}The Deployment controller immediately re-adds
deployment.kubernetes.io/revision, so the object was written forever.Fix: merge the rendered keys over the live maps (rendered wins, nil overlay leaves live untouched). Test:
TestAgentServerAdapterApplyKeepsForeignMetadata.2. Rendered spec zeroed API defaults (
58dabdb, supersedes #271's field list)live.Spec = d.Specdrops every field the API server defaults, so the merge-patch diff was never empty (revisionHistoryLimit,progressDeadlineSeconds, probe thresholds,terminationMessage*, volumedefaultMode, …). #271 enumerated them by hand and missed fields.Fix:
inheritUnset(desired, live)— structurally copy every unset (zero) field from the live object through structs, pointers and same-length slices; env vars excluded because theirName/Valueare renderer-owned and an intentionally emptyKAPE_DEFAULT_MODELmust not be back-filled. Test:TestAgentServerAdapterApplyIgnoresAPIDefaults.Verification
go test ./operator/infra/k8s/passes;go vetclean. (operator/controller/reconcile+operator/infra/qdrantfailures reproduce on unmodifiedmain— environment-dependent, unrelated.)0.1.3(this branch) → generation/observedGeneration frozen,kubectl get kas -n kape-system→Ready=True.Not in scope
buildControllerRoleBindingbindskape-controller-sandbox-readerin the CR's namespace only. With the CR inkape-systemand Sandbox CRs inopenshell, the controller's SA has no Sandbox read access (breaksResolveDaemonAddr→prompt_agent/exec). Tracked separately; the operator should bind inKAPE_SANDBOX_NAMESPACE.