Skip to content

Commit

Permalink
support same port of tcp&udp
Browse files Browse the repository at this point in the history
Signed-off-by: ChrisLiu <[email protected]>
  • Loading branch information
chrisliu1995 committed Dec 16, 2024
1 parent 08dd134 commit 19f57ab
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions cloudprovider/alibabacloud/multi_nlbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const (

// service label defined by OKG
ServiceBelongNetworkTypeKey = "game.kruise.io/network-type"

ProtocolTCPUDP corev1.Protocol = "TCPUDP"
)

type MultiNlbsPlugin struct {
Expand Down Expand Up @@ -352,12 +354,27 @@ func (m *MultiNlbsPlugin) consSvc(conf *multiNLBsConfig, pod *corev1.Pod, lbName

svcPorts := make([]corev1.ServicePort, 0)
for i := 0; i < len(podLbsPorts.ports); i++ {
svcPorts = append(svcPorts, corev1.ServicePort{
Name: strconv.Itoa(podLbsPorts.targetPort[i]) + "-" + strings.ToLower(string(podLbsPorts.protocols[i])),
Port: podLbsPorts.ports[i],
TargetPort: intstr.FromInt(podLbsPorts.targetPort[i]),
Protocol: podLbsPorts.protocols[i],
})
if podLbsPorts.protocols[i] == ProtocolTCPUDP {
svcPorts = append(svcPorts, corev1.ServicePort{
Name: strconv.Itoa(podLbsPorts.targetPort[i]) + "-" + strings.ToLower(string(corev1.ProtocolTCP)),
Port: podLbsPorts.ports[i],
TargetPort: intstr.FromInt(podLbsPorts.targetPort[i]),
Protocol: corev1.ProtocolTCP,
})
svcPorts = append(svcPorts, corev1.ServicePort{
Name: strconv.Itoa(podLbsPorts.targetPort[i]) + "-" + strings.ToLower(string(corev1.ProtocolUDP)),
Port: podLbsPorts.ports[i],
TargetPort: intstr.FromInt(podLbsPorts.targetPort[i]),
Protocol: corev1.ProtocolUDP,
})
} else {
svcPorts = append(svcPorts, corev1.ServicePort{
Name: strconv.Itoa(podLbsPorts.targetPort[i]) + "-" + strings.ToLower(string(podLbsPorts.protocols[i])),
Port: podLbsPorts.ports[i],
TargetPort: intstr.FromInt(podLbsPorts.targetPort[i]),
Protocol: podLbsPorts.protocols[i],
})
}
}

loadBalancerClass := "alibabacloud.com/nlb"
Expand Down

0 comments on commit 19f57ab

Please sign in to comment.