@@ -122,9 +122,10 @@ func desiredLbState(
122122
123123 for _ , port := range serviceInfo .Service .Spec .Ports {
124124
125- if port .Protocol != "TCP" {
125+ if port .Protocol != v1 . ProtocolTCP && port . Protocol != v1 . ProtocolUDP {
126126 return nil , fmt .Errorf (
127- "service %s: cannot use %s for %d, only TCP is supported" ,
127+ "service %s: cannot use %s for %d" +
128+ ", only TCP and UDP are supported" ,
128129 serviceInfo .Service .Name ,
129130 port .Protocol ,
130131 port .Port )
@@ -145,10 +146,15 @@ func desiredLbState(
145146 }
146147 }
147148
149+ poolProtocol := protocol
150+ if port .Protocol != v1 .ProtocolTCP {
151+ poolProtocol = "udp"
152+ }
153+
148154 pool := cloudscale.LoadBalancerPool {
149155 Name : poolName (port .Protocol , port .Name ),
150156 Algorithm : algorithm ,
151- Protocol : protocol ,
157+ Protocol : poolProtocol ,
152158 }
153159 s .pools = append (s .pools , & pool )
154160
@@ -213,7 +219,7 @@ func desiredLbState(
213219 s .monitors [& pool ] = append (s .monitors [& pool ], * monitor )
214220
215221 // Add a listener for each pool
216- listener , err := listenerForPort (serviceInfo , int ( port . Port ) )
222+ listener , err := listenerForPort (serviceInfo , port )
217223 if err != nil {
218224 return nil , err
219225 }
@@ -813,16 +819,21 @@ func runActions(
813819// annotations into consideration.
814820func listenerForPort (
815821 serviceInfo * serviceInfo ,
816- port int ,
822+ port v1. ServicePort ,
817823) (* cloudscale.LoadBalancerListener , error ) {
818824
819825 var (
820826 listener = cloudscale.LoadBalancerListener {}
821827 err error
822828 )
823829
824- listener .Protocol = serviceInfo .annotation (LoadBalancerListenerProtocol )
825- listener .ProtocolPort = port
830+ listenerProtocol := serviceInfo .annotation (LoadBalancerListenerProtocol )
831+ if port .Protocol != v1 .ProtocolTCP {
832+ listenerProtocol = "udp"
833+ }
834+
835+ listener .Protocol = listenerProtocol
836+ listener .ProtocolPort = int (port .Port )
826837 listener .Name = listenerName (listener .Protocol , listener .ProtocolPort )
827838
828839 listener .TimeoutClientDataMS , err = serviceInfo .annotationInt (
0 commit comments