Skip to content

Conversation

@Airren
Copy link
Member

@Airren Airren commented May 13, 2025

No description provided.

@Airren Airren changed the title feat: change ep service bind WIP: change ep service bind May 13, 2025
Signed-off-by: Airren <qiang.ren@intel.com>
Signed-off-by: Airren <qiang.ren@intel.com>
@Airren Airren requested a review from Copilot June 9, 2025 02:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors how EndpointSlice service labels are encoded/decoded with custom utility functions, and updates build configurations for consistent GOPROXY settings and streamlined image pushes.

  • Introduce GetServiceLabelFromSvcName and GetServiceNameFromEpLabel for custom label formatting
  • Refactor code in utils.go, endpointslice.go, and endpointslice_tracker.go to use these utilities
  • Update Dockerfiles and Makefile to set GOPROXY and use inline push flags, and hardcode IMAGE_TAG

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
pkg/controller/endpointslice/utils.go Switched label get/set to use new utility functions
pkg/controller/endpointslice/util/endpointslice_tracker.go Added label encoding/decoding helpers and updated service NN lookup
pkg/controller/endpointslice/endpointslice.go Updated label selector and change detection to use parsing utility
build/ep-controller.Dockerfile Added GOPROXY environment variable
build/cnf.Dockerfile Added GOPROXY env and commented out old proxy setting
Makefile Hardcoded IMAGE_TAG, updated build targets to use --push, commented out separate push steps
Comments suppressed due to low confidence (2)

pkg/controller/endpointslice/util/endpointslice_tracker.go:196

  • New utility functions are introduced without accompanying unit tests. Add tests for GetServiceLabelFromSvcName and GetServiceNameFromEpLabel to ensure correctness.
func GetServiceLabelFromSvcName(serviceName string) string {

Makefile:18

  • [nitpick] Hardcoding IMAGE_TAG to svctest overrides the dynamic git describe tag. Consider parameterizing this or reverting to the previous default for consistency.
IMAGE_TAG = svctest

Comment on lines +197 to +204
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" {
Copy link

Copilot AI Jun 9, 2025

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.

Suggested change
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 {

Copilot uses AI. Check for mistakes.
Comment on lines +197 to +200
return fmt.Sprintf("%s-----%s", "nauti-service", serviceName)
}
func GetServiceNameFromEpLabel(label string) (string, error) {
parts := strings.Split(label, "-----")
Copy link

Copilot AI Jun 9, 2025

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.

Suggested change
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 uses AI. Check for mistakes.
func GetServiceNameFromEpLabel(label string) (string, error) {
parts := strings.Split(label, "-----")
if len(parts) != 2 {
return "", fmt.Errorf("invalid label format")
Copy link

Copilot AI Jun 9, 2025

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

Suggested change
return "", fmt.Errorf("invalid label format")
return "", fmt.Errorf("invalid label format: %q", label)

Copilot uses AI. Check for mistakes.
// provided EndpointSlice.
func getServiceNN(endpointSlice *discovery.EndpointSlice) types.NamespacedName {
serviceName := endpointSlice.Labels[discovery.LabelServiceName]
serviceName, _ := GetServiceNameFromEpLabel(endpointSlice.Labels[discovery.LabelServiceName])
Copy link

Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

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

The error from GetServiceNameFromEpLabel is ignored here, which can lead to empty serviceName. Handle or log the error to avoid silent failures.

Suggested change
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 uses AI. Check for mistakes.
Comment on lines +464 to +465
svcName, _ := endpointsliceutil.GetServiceNameFromEpLabel(endpointSlice.Labels[discovery.LabelServiceName])
prevSvcName, _ := endpointsliceutil.GetServiceNameFromEpLabel(prevEndpointSlice.Labels[discovery.LabelServiceName])
Copy link

Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

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

Ignoring the error returned by GetServiceNameFromEpLabel may mask parsing failures. Consider handling the error or logging it.

Suggested change
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
}

Copilot uses AI. Check for mistakes.
Comment on lines +6 to +8
# ENV GOPROXY='https://goproxy.io,direct'
ENV GOPROXY=https://goproxy.cn,direct

Copy link

Copilot AI Jun 9, 2025

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.

Suggested change
# ENV GOPROXY='https://goproxy.io,direct'
ENV GOPROXY=https://goproxy.cn,direct
ENV GOPROXY=https://goproxy.cn,direct

Copilot uses AI. Check for mistakes.
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