Skip to content

fix: never prune when the EndpointSlice advertises no addresses - #115

Open
andrejatcastai wants to merge 1 commit into
masterfrom
NOJIRA/ip
Open

andrejatcastai wants to merge 1 commit into
masterfrom
NOJIRA/ip

Conversation

@andrejatcastai

Copy link
Copy Markdown

No description provided.

@kimchi-review

kimchi-review Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Kimchi Code Review

Property Value
Commit 46c2d9b
Author @andrejatcastai
Files changed 2
Review status Completed
Comments 4 (3 info, 1 warning)
Duration 635s

Summary

📊 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.

What to expect

Kimchi will analyze the changes in this pull request and post:

  • A summary of the overall changes
  • Inline comments on specific lines with findings categorized by issue type

The review typically completes within a few minutes. This comment will be updated once the review is ready.

Interact with Kimchi
  • @getkimchi review — re-trigger a full review on the latest commit
  • @getkimchi summary — regenerate the PR summary
  • @getkimchi ignore — skip this PR (no review will be posted)
  • Reply to any inline comment to ask follow-up questions or request clarification
Configuration

Reviews are configured by your organization admin.
Review instructions, excluded directories, and severity thresholds can be adjusted per repository in the Kimchi dashboard.


Powered by Kimchi — AI-powered code review by CAST AI

@github-actions github-actions Bot added the fix label Nov 17, 2026

@kimchi-review kimchi-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️🧪 Testing

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)).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️⚡ 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]{})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️🏗️ 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️🔧 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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant