Skip to content

Commit

Permalink
openstack: support setting LB IP
Browse files Browse the repository at this point in the history
Add support for setting the (deprecated) Service field: `loadBalancerIP`
on platform OpenStack when the LB is not internal.
  • Loading branch information
EmilienM committed Oct 4, 2024
1 parent e43555c commit 73575b3
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/operator/controller/ingress/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,27 @@ func setDefaultPublishingStrategy(ic *operatorv1.IngressController, platformStat
statusLB.ProviderParameters.IBM.Protocol = specProtocol
changed = true
}
case operatorv1.OpenStackLoadBalancerProvider:
// The only provider parameter that is supported
// for OpenStack is the FloatingIP parameter.
var statusFloatingIP string
specFloatingIP := specLB.ProviderParameters.OpenStack.FloatingIP
if statusLB.ProviderParameters != nil && statusLB.ProviderParameters.OpenStack != nil {
statusFloatingIP = statusLB.ProviderParameters.OpenStack.FloatingIP
}
if specFloatingIP != statusFloatingIP {
if statusLB.ProviderParameters == nil {
statusLB.ProviderParameters = &operatorv1.ProviderLoadBalancerParameters{}
}
if len(statusLB.ProviderParameters.Type) == 0 {
statusLB.ProviderParameters.Type = operatorv1.OpenStackLoadBalancerProvider
}
if statusLB.ProviderParameters.OpenStack == nil {
statusLB.ProviderParameters.OpenStack = &operatorv1.OpenStackLoadBalancerParameters{}
}
statusLB.ProviderParameters.OpenStack.FloatingIP = specFloatingIP
changed = true
}
}
return changed
}
Expand Down Expand Up @@ -739,6 +760,14 @@ func setDefaultProviderParameters(lbs *operatorv1.LoadBalancerStrategy, ingressC
if lbs.ProviderParameters.IBM == nil {
lbs.ProviderParameters.IBM = &operatorv1.IBMLoadBalancerParameters{}
}
case operatorv1.OpenStackLoadBalancerProvider:
if lbs.ProviderParameters == nil {
lbs.ProviderParameters = &operatorv1.ProviderLoadBalancerParameters{}
}
lbs.ProviderParameters.Type = provider
if lbs.ProviderParameters.OpenStack == nil {
lbs.ProviderParameters.OpenStack = &operatorv1.OpenStackLoadBalancerParameters{}
}
}
}

Expand Down
17 changes: 17 additions & 0 deletions pkg/operator/controller/ingress/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,16 @@ func TestSetDefaultPublishingStrategyHandlesUpdates(t *testing.T) {
}
return eps
}
openstackLB = func(floatingIP string) *operatorv1.EndpointPublishingStrategy {
eps := eps(lbs(operatorv1.ExternalLoadBalancer, &managedDNS))
eps.LoadBalancer.ProviderParameters = &operatorv1.ProviderLoadBalancerParameters{
Type: operatorv1.OpenStackLoadBalancerProvider,
OpenStack: &operatorv1.OpenStackLoadBalancerParameters{
FloatingIP: floatingIP,
},
}
return eps
}
nodePort = func(proto operatorv1.IngressControllerProtocol) *operatorv1.EndpointPublishingStrategy {
return &operatorv1.EndpointPublishingStrategy{
Type: operatorv1.NodePortServiceStrategyType,
Expand Down Expand Up @@ -725,6 +735,13 @@ func TestSetDefaultPublishingStrategyHandlesUpdates(t *testing.T) {
expectedIC: makeIC(spec(ibmLB(operatorv1.TCPProtocol)), status(ibmLB(operatorv1.TCPProtocol))),
domainMatchesBaseDomain: true,
},
{
name: "loadbalancer OpenStack floating IP changed",
ic: makeIC(spec(openstackLB("1.2.3.4")), status(openstackLB("192.168.0.1"))),
expectedResult: true,
expectedIC: makeIC(spec(openstackLB("1.2.3.4")), status(openstackLB("1.2.3.4"))),
domainMatchesBaseDomain: true,
},
{
// https://bugzilla.redhat.com/show_bug.cgi?id=1997226
name: "nodeport protocol changed to PROXY with null status.endpointPublishingStrategy.nodePort",
Expand Down
9 changes: 9 additions & 0 deletions pkg/operator/controller/ingress/load_balancer_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,15 @@ func desiredLoadBalancerService(ci *operatorv1.IngressController, deploymentRef
if !isInternal {
service.Annotations[alibabaCloudLBAddressTypeAnnotation] = alibabaCloudLBAddressTypeInternet
}
case configv1.OpenStackPlatformType:
// Set a floating IP only if the load balancer scope is external.
if !isInternal {
if lb != nil && lb.ProviderParameters != nil &&
lb.ProviderParameters.Type == operatorv1.OpenStackLoadBalancerProvider &&
lb.ProviderParameters.OpenStack != nil {
service.Spec.LoadBalancerIP = lb.ProviderParameters.OpenStack.FloatingIP
}
}
}
// Azure load balancers are not customizable and are set to (2 fail @ 5s interval, 2 healthy)
// GCP load balancers are not customizable and are set to (3 fail @ 8s interval, 1 healthy)
Expand Down
25 changes: 25 additions & 0 deletions pkg/operator/controller/ingress/load_balancer_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ func Test_desiredLoadBalancerService(t *testing.T) {
},
}
}
openstackLbWithFloatingIP = func(scope operatorv1.LoadBalancerScope, floatingIP string) *operatorv1.EndpointPublishingStrategy {
return &operatorv1.EndpointPublishingStrategy{
Type: operatorv1.LoadBalancerServiceStrategyType,
LoadBalancer: &operatorv1.LoadBalancerStrategy{
Scope: scope,
ProviderParameters: &operatorv1.ProviderLoadBalancerParameters{
Type: operatorv1.OpenStackLoadBalancerProvider,
OpenStack: &operatorv1.OpenStackLoadBalancerParameters{
FloatingIP: floatingIP,
},
},
},
}
}
// nps returns an EndpointPublishingStrategy with type
// "NodePortService" and the specified protocol.
nps = func(proto operatorv1.IngressControllerProtocol) *operatorv1.EndpointPublishingStrategy {
Expand Down Expand Up @@ -663,6 +677,17 @@ func Test_desiredLoadBalancerService(t *testing.T) {
localWithFallbackAnnotation: {true, ""},
},
},
{
description: "external load balancer for openstack platform with floating IP",
platformStatus: platformStatus(configv1.OpenStackPlatformType),
strategyStatus: openstackLbWithFloatingIP(operatorv1.ExternalLoadBalancer, "1.2.3.4"),
expectService: true,
expectedExternalTrafficPolicy: corev1.ServiceExternalTrafficPolicyLocal,
expectedServiceAnnotations: map[string]annotationExpectation{
openstackInternalLBAnnotation: {false, ""},
localWithFallbackAnnotation: {true, ""},
},
},
{
description: "internal load balancer for openstack platform",
platformStatus: platformStatus(configv1.OpenStackPlatformType),
Expand Down

0 comments on commit 73575b3

Please sign in to comment.