Skip to content

Commit 7a4290e

Browse files
authored
[occm] KEP-1860: Add support for LoadBalancer ipMode (kubernetes#2587)
* KEP-1860: Add support for LoadBalancer ipMode * cleaner: use assertEqual for test
1 parent b6d73d6 commit 7a4290e

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

pkg/openstack/loadbalancer.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,18 +1568,26 @@ func (lbaas *LbaasV2) createLoadBalancerStatus(service *corev1.Service, svcConf
15681568
status.Ingress = []corev1.LoadBalancerIngress{{Hostname: hostname}}
15691569
return status
15701570
}
1571-
// If the load balancer is using the PROXY protocol, expose its IP address via
1572-
// the Hostname field to prevent kube-proxy from injecting an iptables bypass.
1573-
// This is a workaround until
1574-
// https://github.com/kubernetes/enhancements/tree/master/keps/sig-network/1860-kube-proxy-IP-node-binding
1575-
// is implemented (maybe in v1.22).
1576-
if svcConf.enableProxyProtocol && lbaas.opts.EnableIngressHostname {
1577-
fakeHostname := fmt.Sprintf("%s.%s", addr, lbaas.opts.IngressHostnameSuffix)
1578-
status.Ingress = []corev1.LoadBalancerIngress{{Hostname: fakeHostname}}
1579-
return status
1571+
1572+
ipMode := corev1.LoadBalancerIPModeVIP
1573+
if svcConf.enableProxyProtocol {
1574+
// If the load balancer is using the PROXY protocol, expose its IP address via
1575+
// the Hostname field to prevent kube-proxy from injecting an iptables bypass.
1576+
// Setting must be removed by the user to allow the use of the LoadBalancerIPModeProxy.
1577+
if lbaas.opts.EnableIngressHostname {
1578+
fakeHostname := fmt.Sprintf("%s.%s", addr, lbaas.opts.IngressHostnameSuffix)
1579+
status.Ingress = []corev1.LoadBalancerIngress{{Hostname: fakeHostname}}
1580+
return status
1581+
}
1582+
// Set the LoadBalancerIPMode to Proxy to prevent kube-proxy from injecting an iptables bypass.
1583+
// https://github.com/kubernetes/enhancements/tree/master/keps/sig-network/1860-kube-proxy-IP-node-binding
1584+
ipMode = corev1.LoadBalancerIPModeProxy
15801585
}
15811586
// Default to IP
1582-
status.Ingress = []corev1.LoadBalancerIngress{{IP: addr}}
1587+
status.Ingress = []corev1.LoadBalancerIngress{{
1588+
IP: addr,
1589+
IPMode: &ipMode,
1590+
}}
15831591
return status
15841592
}
15851593

pkg/openstack/loadbalancer_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,12 +709,15 @@ func TestLbaasV2_checkListenerPorts(t *testing.T) {
709709
}
710710
}
711711
func TestLbaasV2_createLoadBalancerStatus(t *testing.T) {
712+
ipmodeProxy := corev1.LoadBalancerIPModeProxy
713+
ipmodeVIP := corev1.LoadBalancerIPModeVIP
712714
type fields struct {
713715
LoadBalancer LoadBalancer
714716
}
715717
type result struct {
716718
HostName string
717719
IPAddress string
720+
IPMode *corev1.LoadBalancerIPMode
718721
}
719722
type args struct {
720723
service *corev1.Service
@@ -800,6 +803,33 @@ func TestLbaasV2_createLoadBalancerStatus(t *testing.T) {
800803
},
801804
want: result{
802805
IPAddress: "10.10.0.6",
806+
IPMode: &ipmodeVIP,
807+
},
808+
},
809+
{
810+
name: "it should return ipMode proxy if using proxyProtocol and not EnableIngressHostname",
811+
fields: fields{
812+
LoadBalancer: LoadBalancer{
813+
opts: LoadBalancerOpts{
814+
EnableIngressHostname: false,
815+
IngressHostnameSuffix: "ingress-suffix",
816+
},
817+
},
818+
},
819+
args: args{
820+
service: &corev1.Service{
821+
ObjectMeta: v1.ObjectMeta{
822+
Annotations: map[string]string{"test": "key"},
823+
},
824+
},
825+
svcConf: &serviceConfig{
826+
enableProxyProtocol: true,
827+
},
828+
addr: "10.10.0.6",
829+
},
830+
want: result{
831+
IPAddress: "10.10.0.6",
832+
IPMode: &ipmodeProxy,
803833
},
804834
},
805835
}
@@ -812,6 +842,7 @@ func TestLbaasV2_createLoadBalancerStatus(t *testing.T) {
812842
result := lbaas.createLoadBalancerStatus(tt.args.service, tt.args.svcConf, tt.args.addr)
813843
assert.Equal(t, tt.want.HostName, result.Ingress[0].Hostname)
814844
assert.Equal(t, tt.want.IPAddress, result.Ingress[0].IP)
845+
assert.Equal(t, tt.want.IPMode, result.Ingress[0].IPMode)
815846
})
816847
}
817848
}

0 commit comments

Comments
 (0)