-
Notifications
You must be signed in to change notification settings - Fork 5
WIP: change ep service bind #125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -375,7 +375,7 @@ func (c *Controller) syncService(logger klog.Logger, key string) error { | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| esLabelSelector := labels.Set(map[string]string{ | ||||||||||||||||||||||||||
| discovery.LabelServiceName: service.Name, | ||||||||||||||||||||||||||
| discovery.LabelServiceName: endpointsliceutil.GetServiceLabelFromSvcName(service.Name), | ||||||||||||||||||||||||||
| discovery.LabelManagedBy: c.reconciler.GetControllerName(), | ||||||||||||||||||||||||||
| }).AsSelectorPreValidated() | ||||||||||||||||||||||||||
| endpointSlices, err := c.endpointSliceLister.EndpointSlices(service.Namespace).List(esLabelSelector) | ||||||||||||||||||||||||||
|
|
@@ -461,8 +461,8 @@ func (c *Controller) onEndpointSliceUpdate(logger klog.Logger, prevObj, obj inte | |||||||||||||||||||||||||
| // EndpointSlice generation does not change when labels change. Although the | ||||||||||||||||||||||||||
| // controller will never change LabelServiceName, users might. This check | ||||||||||||||||||||||||||
| // ensures that we handle changes to this label. | ||||||||||||||||||||||||||
| svcName := endpointSlice.Labels[discovery.LabelServiceName] | ||||||||||||||||||||||||||
| prevSvcName := prevEndpointSlice.Labels[discovery.LabelServiceName] | ||||||||||||||||||||||||||
| svcName, _ := endpointsliceutil.GetServiceNameFromEpLabel(endpointSlice.Labels[discovery.LabelServiceName]) | ||||||||||||||||||||||||||
| prevSvcName, _ := endpointsliceutil.GetServiceNameFromEpLabel(prevEndpointSlice.Labels[discovery.LabelServiceName]) | ||||||||||||||||||||||||||
|
Comment on lines
+464
to
+465
|
||||||||||||||||||||||||||
| svcName, _ := endpointsliceutil.GetServiceNameFromEpLabel(endpointSlice.Labels[discovery.LabelServiceName]) | |
| prevSvcName, _ := endpointsliceutil.GetServiceNameFromEpLabel(prevEndpointSlice.Labels[discovery.LabelServiceName]) | |
| svcName, err := endpointsliceutil.GetServiceNameFromEpLabel(endpointSlice.Labels[discovery.LabelServiceName]) | |
| if err != nil { | |
| logger.Error(err, "failed to parse service name from EndpointSlice label", "endpointslice", klog.KObj(endpointSlice)) | |
| return | |
| } | |
| prevSvcName, err := endpointsliceutil.GetServiceNameFromEpLabel(prevEndpointSlice.Labels[discovery.LabelServiceName]) | |
| if err != nil { | |
| logger.Error(err, "failed to parse service name from previous EndpointSlice label", "endpointslice", klog.KObj(prevEndpointSlice)) | |
| return | |
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,8 @@ limitations under the License. | |||||||||||||||||||||||||||||||||
| package util | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||||||||||||||
| "strings" | ||||||||||||||||||||||||||||||||||
| "sync" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| v1 "k8s.io/api/core/v1" | ||||||||||||||||||||||||||||||||||
|
|
@@ -187,6 +189,20 @@ func (est *EndpointSliceTracker) GenerationsForSliceUnsafe(endpointSlice *discov | |||||||||||||||||||||||||||||||||
| // getServiceNN returns a namespaced name for the Service corresponding to the | ||||||||||||||||||||||||||||||||||
| // provided EndpointSlice. | ||||||||||||||||||||||||||||||||||
| func getServiceNN(endpointSlice *discovery.EndpointSlice) types.NamespacedName { | ||||||||||||||||||||||||||||||||||
| serviceName := endpointSlice.Labels[discovery.LabelServiceName] | ||||||||||||||||||||||||||||||||||
| serviceName, _ := GetServiceNameFromEpLabel(endpointSlice.Labels[discovery.LabelServiceName]) | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| serviceName, _ := GetServiceNameFromEpLabel(endpointSlice.Labels[discovery.LabelServiceName]) | |
| serviceName, err := GetServiceNameFromEpLabel(endpointSlice.Labels[discovery.LabelServiceName]) | |
| if err != nil { | |
| fmt.Printf("Error extracting service name from label: %v\n", err) | |
| return types.NamespacedName{Name: "", Namespace: endpointSlice.Namespace} | |
| } |
Copilot
AI
Jun 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The delimiter "-----" is arbitrary and could conflict with service names. Consider defining it as a constant or choosing a safer separator.
| return fmt.Sprintf("%s-----%s", "nauti-service", serviceName) | |
| } | |
| func GetServiceNameFromEpLabel(label string) (string, error) { | |
| parts := strings.Split(label, "-----") | |
| return fmt.Sprintf("%s%s%s", "nauti-service", serviceLabelDelimiter, serviceName) | |
| } | |
| func GetServiceNameFromEpLabel(label string) (string, error) { | |
| parts := strings.Split(label, serviceLabelDelimiter) |
Copilot
AI
Jun 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this error more descriptive by including the invalid label value to aid diagnostics, e.g., fmt.Errorf("invalid label format: %q", label).
| return "", fmt.Errorf("invalid label format") | |
| return "", fmt.Errorf("invalid label format: %q", label) |
Copilot
AI
Jun 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Avoid using the literal prefix "nauti-service" here; extract it (and the delimiter) into package-level constants to reduce magic strings and improve consistency.
| return fmt.Sprintf("%s-----%s", "nauti-service", serviceName) | |
| } | |
| func GetServiceNameFromEpLabel(label string) (string, error) { | |
| parts := strings.Split(label, "-----") | |
| if len(parts) != 2 { | |
| return "", fmt.Errorf("invalid label format") | |
| } | |
| if parts[0] != "nauti-service" { | |
| return fmt.Sprintf("%s%s%s", serviceLabelPrefix, serviceLabelDelimiter, serviceName) | |
| } | |
| func GetServiceNameFromEpLabel(label string) (string, error) { | |
| parts := strings.Split(label, serviceLabelDelimiter) | |
| if len(parts) != 2 { | |
| return "", fmt.Errorf("invalid label format") | |
| } | |
| if parts[0] != serviceLabelPrefix { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Remove or consolidate commented-out proxy lines to keep the Dockerfile clean and avoid confusion over which proxy is intended.