Repository navigation
fix: never prune when the EndpointSlice advertises no addresses - #115
andrejatcastai wants to merge 1 commit into
Conversation
Kimchi Code Review
Summary📊 Review Score: 84/100 (overall code quality — 0 lowest, 100 highest) 🧪 Tests: yes — Good unit coverage was added for the changed behavior: IP creation, recreation after deletion, skip-pruning on an empty endpoint set (asserting both the 📝 Found 4 issue(s). See inline comments for details. What to expectKimchi will analyze the changes in this pull request and post:
The review typically completes within a few minutes. This comment will be updated once the review is ready. Interact with Kimchi
ConfigurationReviews are configured by your organization admin. Powered by Kimchi — AI-powered code review by CAST AI |
There was a problem hiding this comment.
📊 Review Score: 84/100 (overall code quality — 0 lowest, 100 highest)
⏱️ Estimated effort to review: 3/5 (1 = trivial, 5 = very complex)
🧪 Tests: yes — Good unit coverage was added for the changed behavior: IP creation, recreation after deletion, skip-pruning on an empty endpoint set (asserting both the RequeueAfter result and IP preservation), stale-pruning on address change, and the ipToEndpointSliceRequests mapping function. The main gap is that the watch wiring in SetupWithManager (ipPredicates + event mapping + workqueue) is never exercised end-to-end, so the self-healing deletion path is only verified by invoking Reconcile directly.
📝 Found 4 issue(s). See inline comments for details.
| } | ||
|
|
||
| func TestEndpointSliceIPReconcilerRecreatesMissingMapping(t *testing.T) { | ||
| g := NewWithT(t) |
There was a problem hiding this comment.
The headline self-healing behavior is only tested by manually re-invoking Reconcile after cl.Delete. The production path — SetupWithManager registering the ipamv1alpha1.IP watch with ipPredicates and the delete event being mapped through ipToEndpointSliceRequests into the workqueue — is never exercised. If NewTypedAnyLabelsSetPredicate or NewTypedAnyNamespacePredicate were to return false for delete events, or the source registration regressed, IP deletion would silently stop triggering recreation and the feature would be dead in production.
💡 Suggestion: Add an envtest-based integration test that runs SetupWithManager against a real manager, deletes a derived ipamv1alpha1.IP, and asserts the controller runtime recreates it. Also consider covering the 'endpoints present but not ready' variant of the empty-guard, which is currently untested.
| return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlEndpointSlice). | ||
| WatchesRawSource(source.Kind(r.Cache, &discoveryv1.EndpointSlice{}, | ||
| &handler.TypedEnqueueRequestForObject[*discoveryv1.EndpointSlice]{}, predicates)). | ||
| &handler.TypedEnqueueRequestForObject[*discoveryv1.EndpointSlice]{}, epsPredicates)). |
There was a problem hiding this comment.
ℹ️⚡ Performance
ipPredicates filters only on namespace and labels, so every write to a derived IP — including status/condition updates performed by the IPAM controller — re-enqueues a full EndpointSlice reconcile. The reconcile is idempotent so this is benign, but it introduces steady reconcile churn proportional to IP status updates that did not exist before the new watch.
💡 Suggestion: Consider adding a predicate.TypedGenerationChangedPredicate[*ipamv1alpha1.IP]{} to ipPredicates so status-only updates are filtered out; Create and Delete events (the main self-healing triggers) still pass through. Verify first that the IP CRD actually bumps metadata.generation on spec changes, otherwise updates would be suppressed entirely.
| utilpredicates.NewTypedAnyNamespacePredicate[*discoveryv1.EndpointSlice](r.namespacesFilter), | ||
| utilpredicates.NewTypedAnyLabelsSetPredicate[*discoveryv1.EndpointSlice](r.labelsSetsFilter), | ||
| predicate.TypedGenerationChangedPredicate[*discoveryv1.EndpointSlice]{}) | ||
|
|
There was a problem hiding this comment.
ℹ️🏗️ Design
The IP-side watch is hardcoded to the label value kubernetesServiceName (and ipToEndpointSliceRequests hardcodes kubernetesServiceNamespace), while the EndpointSlice-side watch remains fully configurable via r.namespacesFilter and r.labelsSetsFilter, and forgeIPname/commonLabels operate on arbitrary slice names. Any IP derived from a watched EndpointSlice whose name differs from kubernetes (e.g., a secondary slice such as kubernetes-xxxxx created when the service exceeds 100 endpoints) will not be watched and will not self-heal.
💡 Suggestion: Derive the watched IPEndpointSliceNameLabelKey values from the same configuration used for the EndpointSlice watch, or document explicitly in SetupWithManager that the self-healing watch is intentionally scoped to the single primary kubernetes EndpointSlice.
| } | ||
| } | ||
|
|
||
| // Never prune when the EndpointSlice advertises no addresses: a temporarily empty endpoint set (e.g., while |
There was a problem hiding this comment.
ℹ️🔧 Maintainability
The empty-endpoints guard permanently disables pruning, so if the EndpointSlice stays empty indefinitely (or is deleted), the stale IP mappings — and their masquerade configuration for addresses that may later be reassigned — are retained forever, while the reconciler keeps requeueing every 30s with no possibility of convergence.
💡 Suggestion: Consider pruning after a sustained-empty grace period: record the timestamp of the first observed empty state (in-memory keyed by slice name, or as an annotation) and only skip pruning for the first N minutes. This preserves protection against transient endpoint churn while bounding retention of stale mappings.
No description provided.