Skip to content
This repository was archived by the owner on Mar 22, 2018. It is now read-only.

Commit ad8c228

Browse files
committed
Don't fail fast if LoadBalancer section is missing
We should allow scenarios where cinder can be used even if the operator does not want to use the openstack load balancer. So let's warn in the beginning if subnet-id is missing but fail only if they try to use the load balancer
1 parent 244515a commit ad8c228

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

pkg/cloudprovider/providers/openstack/openstack.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ func checkOpenStackOpts(openstackOpts *OpenStack) error {
222222

223223
// subnet-id is required
224224
if len(lbOpts.SubnetId) == 0 {
225-
return fmt.Errorf("subnet-id not set in cloud provider config")
225+
glog.Warningf("subnet-id not set in cloud provider config. " +
226+
"OpenStack Load balancer will not work.")
226227
}
227228

228229
// if need to create health monitor for Neutron LB,

pkg/cloudprovider/providers/openstack/openstack_loadbalancer.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,10 @@ func nodeAddressForLB(node *v1.Node) (string, error) {
589589
func (lbaas *LbaasV2) EnsureLoadBalancer(clusterName string, apiService *v1.Service, nodes []*v1.Node) (*v1.LoadBalancerStatus, error) {
590590
glog.V(4).Infof("EnsureLoadBalancer(%v, %v, %v, %v, %v, %v, %v)", clusterName, apiService.Namespace, apiService.Name, apiService.Spec.LoadBalancerIP, apiService.Spec.Ports, nodes, apiService.Annotations)
591591

592+
if len(lbaas.opts.SubnetId) == 0 {
593+
return nil, fmt.Errorf("subnet-id not set in cloud provider config")
594+
}
595+
592596
ports := apiService.Spec.Ports
593597
if len(ports) == 0 {
594598
return nil, fmt.Errorf("no ports provided to openstack load balancer")
@@ -950,6 +954,10 @@ func (lbaas *LbaasV2) UpdateLoadBalancer(clusterName string, service *v1.Service
950954
loadBalancerName := cloudprovider.GetLoadBalancerName(service)
951955
glog.V(4).Infof("UpdateLoadBalancer(%v, %v, %v)", clusterName, loadBalancerName, nodes)
952956

957+
if len(lbaas.opts.SubnetId) == 0 {
958+
return fmt.Errorf("subnet-id not set in cloud provider config")
959+
}
960+
953961
ports := service.Spec.Ports
954962
if len(ports) == 0 {
955963
return fmt.Errorf("no ports provided to openstack load balancer")
@@ -1225,6 +1233,10 @@ func (lb *LbaasV1) GetLoadBalancer(clusterName string, service *v1.Service) (*v1
12251233
func (lb *LbaasV1) EnsureLoadBalancer(clusterName string, apiService *v1.Service, nodes []*v1.Node) (*v1.LoadBalancerStatus, error) {
12261234
glog.V(4).Infof("EnsureLoadBalancer(%v, %v, %v, %v, %v, %v, %v)", clusterName, apiService.Namespace, apiService.Name, apiService.Spec.LoadBalancerIP, apiService.Spec.Ports, nodes, apiService.Annotations)
12271235

1236+
if len(lb.opts.SubnetId) == 0 {
1237+
return nil, fmt.Errorf("subnet-id not set in cloud provider config")
1238+
}
1239+
12281240
ports := apiService.Spec.Ports
12291241
if len(ports) > 1 {
12301242
return nil, fmt.Errorf("multiple ports are not supported in openstack v1 load balancers")

pkg/cloudprovider/providers/openstack/openstack_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func TestCheckOpenStackOpts(t *testing.T) {
188188
NodeSecurityGroupID: "b41d28c2-d02f-4e1e-8ffb-23b8e4f5c144",
189189
},
190190
},
191-
expectedError: fmt.Errorf("subnet-id not set in cloud provider config"),
191+
expectedError: nil,
192192
},
193193
{
194194
name: "test3",

0 commit comments

Comments
 (0)