diff --git a/cloudprovider/alibabacloud/slb.go b/cloudprovider/alibabacloud/slb.go index 7bf29a3..2686918 100644 --- a/cloudprovider/alibabacloud/slb.go +++ b/cloudprovider/alibabacloud/slb.go @@ -144,8 +144,11 @@ func initLbCache(svcList []corev1.Service, minPort, maxPort int32, blockPorts [] var ports []int32 for _, port := range getPorts(svc.Spec.Ports) { if port <= maxPort && port >= minPort { - newCache[lbId][port] = true - ports = append(ports, port) + value, ok := newCache[lbId][port] + if !ok || !value { + newCache[lbId][port] = true + ports = append(ports, port) + } } } if len(ports) != 0 { @@ -577,12 +580,29 @@ func (s *SlbPlugin) consSvc(sc *slbConfig, pod *corev1.Pod, c client.Client, ctx svcPorts := make([]corev1.ServicePort, 0) for i := 0; i < len(sc.targetPorts); i++ { - svcPorts = append(svcPorts, corev1.ServicePort{ - Name: strconv.Itoa(sc.targetPorts[i]), - Port: ports[i], - Protocol: sc.protocols[i], - TargetPort: intstr.FromInt(sc.targetPorts[i]), - }) + if sc.protocols[i] == ProtocolTCPUDP { + svcPorts = append(svcPorts, corev1.ServicePort{ + Name: fmt.Sprintf("%s-%s", strconv.Itoa(sc.targetPorts[i]), corev1.ProtocolTCP), + Port: ports[i], + Protocol: corev1.ProtocolTCP, + TargetPort: intstr.FromInt(sc.targetPorts[i]), + }) + + svcPorts = append(svcPorts, corev1.ServicePort{ + Name: fmt.Sprintf("%s-%s", strconv.Itoa(sc.targetPorts[i]), corev1.ProtocolUDP), + Port: ports[i], + Protocol: corev1.ProtocolUDP, + TargetPort: intstr.FromInt(sc.targetPorts[i]), + }) + + } else { + svcPorts = append(svcPorts, corev1.ServicePort{ + Name: fmt.Sprintf("%s-%s", strconv.Itoa(sc.targetPorts[i]), sc.protocols[i]), + Port: ports[i], + Protocol: sc.protocols[i], + TargetPort: intstr.FromInt(sc.targetPorts[i]), + }) + } } svcAnnotations := map[string]string{ diff --git a/docs/en/user_manuals/network.md b/docs/en/user_manuals/network.md index 6e8fd5f..89299e3 100644 --- a/docs/en/user_manuals/network.md +++ b/docs/en/user_manuals/network.md @@ -421,7 +421,7 @@ SlbIds PortProtocols - Meaning: the ports in the pod to be exposed and the protocols. You can specify multiple ports and protocols. -- Value: in the format of port1/protocol1,port2/protocol2,... The protocol names must be in uppercase letters. +- Value: in the format of port1/protocol1,port2/protocol2,... (same protocol port should like 8000/TCPUDP) The protocol names must be in uppercase letters. - Configuration change supported or not: yes. Fixed diff --git "a/docs/\344\270\255\346\226\207/\347\224\250\346\210\267\346\211\213\345\206\214/\347\275\221\347\273\234\346\250\241\345\236\213.md" "b/docs/\344\270\255\346\226\207/\347\224\250\346\210\267\346\211\213\345\206\214/\347\275\221\347\273\234\346\250\241\345\236\213.md" index 5faf64b..0c7dfc2 100644 --- "a/docs/\344\270\255\346\226\207/\347\224\250\346\210\267\346\211\213\345\206\214/\347\275\221\347\273\234\346\250\241\345\236\213.md" +++ "b/docs/\344\270\255\346\226\207/\347\224\250\346\210\267\346\211\213\345\206\214/\347\275\221\347\273\234\346\250\241\345\236\213.md" @@ -424,7 +424,7 @@ SlbIds PortProtocols - 含义:pod暴露的端口及协议,支持填写多个端口/协议 -- 格式:port1/protocol1,port2/protocol2,...(协议需大写) +- 格式:port1/protocol1,port2/protocol2,... (多协议相同端口 比如: 8000/TCPUDP)(协议需大写) - 是否支持变更:支持 Fixed