fix(cache): updating the k8s service endpoints to handle new random suffix appended to the name#72
Conversation
… random suffix appended to the name on the services
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the ServiceEndpointHashBucket to improve the handling of Kubernetes EndpointSlices by switching from Get to List operations and updating the matching logic from using Name to GenerateName, as well as updating corresponding tests and cleaning up redundant comments.
- Refactors the Start method to use a List operation with proper error handling
- Updates onEndpointUpdate to match EndpointSlices using the GenerateName prefix
- Enhances test cases to include GenerateName, labels, and annotations for EndpointSlices and removes redundant compile-time interface check comments
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| logging/dedupe_handler.go | Removed redundant compile-time interface check comments for clarity |
| cache/service_endpoint_hash_bucket_test.go | Updated tests to use GenerateName and added extra metadata to EndpointSlice test fixtures |
| cache/service_endpoint_hash_bucket.go | Switched from Get to List for fetching EndpointSlices and updated matching logic using GenerateName |
Comments suppressed due to low confidence (1)
cache/service_endpoint_hash_bucket.go:156
- Consider handling cases where GetGenerateName() might return an empty string. If GenerateName is not set, falling back to using the Name field would ensure robust matching of EndpointSlices.
if !strings.HasPrefix(coreNewEndpoints.GetGenerateName(), sb.appName) || coreNewEndpoints.GetNamespace() != sb.appNamespace {
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the EndpointSlice handling in the cache package for improved compatibility with Kubernetes naming conventions and simplifies the code by removing redundant compile-time interface checks.
- Refactored ServiceEndpointHashBucket to list EndpointSlices using a label selector and handle missing slices.
- Updated onEndpointUpdate to use the GenerateName prefix for EndpointSlice matching.
- Enhanced test coverage with additional test cases that include GenerateName, labels, and annotations.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| logging/dedupe_handler.go | Removed compile-time interface check comments to simplify the file. |
| cache/service_endpoint_hash_bucket.go | Updated Start method to use List with a label selector; revised onEndpointUpdate to incorporate GenerateName matching logic. |
| cache/service_endpoint_hash_bucket_test.go | Updated tests to reflect changes in EndpointSlice handling, including test cases for scenarios with and without GenerateName. |
Comments suppressed due to low confidence (2)
cache/service_endpoint_hash_bucket.go:90
- [nitpick] Verify that the new List approach with a label selector reliably captures all relevant EndpointSlices. Consider adding a brief comment discussing any potential edge cases where endpoints may be filtered unintentionally.
endpointSliceList, err := sb.kubeClient.DiscoveryV1().EndpointSlices(sb.appNamespace).List(ctx, metav1.ListOptions{ LabelSelector: fmt.Sprintf("%s=%s", k8sNameLabel, sb.appName), })
cache/service_endpoint_hash_bucket.go:166
- [nitpick] Consider adding an inline comment to clarify the intent behind matching EndpointSlices using the GenerateName prefix, improving readability for future maintainers.
generateName := coreNewEndpoints.GetGenerateName()
|
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Describe your changes
This pull request refactors the
ServiceEndpointHashBucketimplementation to improve its handling of Kubernetes EndpointSlices and updates related tests. Additionally, it removes redundant compile-time interface checks for clarity.Refactoring and Enhancements for EndpointSlices:
Startmethod inServiceEndpointHashBucketto useListinstead ofGetfor fetching EndpointSlices, applying a label selector for filtering, and handling cases where no slices are found. It also combines hosts from multiple slices into a unified set. (cache/service_endpoint_hash_bucket.go, cache/service_endpoint_hash_bucket.goL87-L93)onEndpointUpdatemethod to match EndpointSlices usingGenerateNameprefix instead ofNamefor better compatibility with Kubernetes naming conventions. (cache/service_endpoint_hash_bucket.go, cache/service_endpoint_hash_bucket.goL146-R156)Test Updates for EndpointSlices:
Test_Lifecycleto includeGenerateName, labels, and annotations in the mock EndpointSlice, ensuring tests align with the new implementation. (cache/service_endpoint_hash_bucket_test.go, cache/service_endpoint_hash_bucket_test.goL27-R43)Test_onEndpointUpdateto useGenerateNamefor EndpointSlice matching in test cases. (cache/service_endpoint_hash_bucket_test.go, [1] [2]Codebase Simplification:
ServiceEndpointHashBucketanddedupeHandlerto reduce verbosity without impacting functionality. (cache/service_endpoint_hash_bucket.go, [1];logging/dedupe_handler.go, [2]