Skip to content

Commit 379f3a6

Browse files
authored
fix: port name should always set to endpointPortName (#224)
Signed-off-by: Ashing Zheng <[email protected]>
1 parent 6ca4414 commit 379f3a6

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

pkg/utils/endpoints.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"fmt"
2222
"net"
2323

24+
"github.com/api7/gopkg/pkg/log"
25+
"go.uber.org/zap"
2426
corev1 "k8s.io/api/core/v1"
2527
discoveryv1 "k8s.io/api/discovery/v1"
2628
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -72,9 +74,7 @@ func ConvertEndpointsToEndpointSlice(ep *corev1.Endpoints) []discoveryv1.Endpoin
7274
epPort := discoveryv1.EndpointPort{
7375
Port: &p.Port,
7476
Protocol: &p.Protocol,
75-
}
76-
if p.Name != "" {
77-
epPort.Name = &p.Name
77+
Name: &p.Name,
7878
}
7979
ports = append(ports, epPort)
8080
}
@@ -140,6 +140,8 @@ func ConvertEndpointsToEndpointSlice(ep *corev1.Endpoints) []discoveryv1.Endpoin
140140
}
141141
}
142142

143+
log.Debugw("Converted Endpoints to EndpointSlices", zap.Any("endpointSlices", endpointSlices))
144+
143145
return endpointSlices
144146
}
145147

pkg/utils/endpoints_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func TestConvertEndpointsToEndpointSlice(t *testing.T) {
308308
},
309309
want: []discoveryv1.EndpointSlice{
310310
createTestEndpointSlice("test-service-0-v4", discoveryv1.AddressTypeIPv4,
311-
[]discoveryv1.EndpointPort{createPlainPort(80)},
311+
[]discoveryv1.EndpointPort{createPlainPortWithEmptyName(80)},
312312
[]discoveryv1.Endpoint{createEndpointWithHostname("192.168.1.1", "pod-1")}),
313313
},
314314
},
@@ -462,8 +462,9 @@ func createHTTPSPort(port int32) discoveryv1.EndpointPort {
462462
}
463463
}
464464

465-
func createPlainPort(port int32) discoveryv1.EndpointPort {
465+
func createPlainPortWithEmptyName(port int32) discoveryv1.EndpointPort {
466466
return discoveryv1.EndpointPort{
467+
Name: ptr.To(""),
467468
Port: ptr.To(port),
468469
Protocol: ptr.To(corev1.ProtocolTCP),
469470
}

test/e2e/scaffold/httpbin.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ spec:
8383
selector:
8484
app: httpbin-deployment-e2e-test
8585
ports:
86-
- name: http
87-
port: 80
86+
- port: 80
8887
protocol: TCP
8988
targetPort: 80
9089
type: ClusterIP

0 commit comments

Comments
 (0)