Skip to content

fix(controllers): watch pods in RC and fall back to selector labels in RS#44

Open
indyjonesnl wants to merge 1 commit into
calfonso:mainfrom
indyjonesnl:upstream/controllers-rc-rs-pod-watch
Open

fix(controllers): watch pods in RC and fall back to selector labels in RS#44
indyjonesnl wants to merge 1 commit into
calfonso:mainfrom
indyjonesnl:upstream/controllers-rc-rs-pod-watch

Conversation

@indyjonesnl
Copy link
Copy Markdown

Problem

Two controller reaction-latency bugs surfaced by conformance:

  1. ReplicationController only watched its own resource and was driven by a 30s resync. Pod deletions (kubelet eviction, OOM, manual) took up to 30s to trigger a replacement create — conformance probes time out.
  2. ReplicaSet picked owned pods exclusively by `ownerReferences[].uid` matching the RS UID. Orphaned pods (RS recreated, owner stripped during foreground deletion) were ignored even when their labels still matched `spec.selector` — leading to pods being respawned alongside the orphans, exceeding the replica count.

Fix

  • RC: add a pod watch keyed by the same prefix as the RC, so any pod lifecycle event enqueues the owning RC for immediate reconcile. The 30s resync remains as a safety net.
  • RS: when scanning for owned pods, first try the ownerReference match (fast path), then fall back to label-selector match (`spec.selector.matchLabels` + `matchExpressions`) for any pod missing an ownerReference. This catches orphans without recreating duplicates.

Verification

`cargo build --workspace --locked` clean. Depends on #32 for green CI.

…n RS

ReplicationController only watched its own resource, so pod status flips
(Pending->Running, Ready condition) had to wait up to 30s for the
periodic resync before status.readyReplicas updated — long enough to
trip conformance "should serve a basic image" timeouts. Add a pod watch
that enqueues the owning RC on any pod event, and shorten the safety
resync to 5s to match the ReplicaSet controller.

Also make the ReplicaSet controller fall back to spec.selector.matchLabels
when the pod template has no labels. Without the fallback, created pods
had no labels, matches_selector returned false for them, and the
controller created replicas every cycle. RC already had this defensive
fallback; bring RS in line.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant