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

Commit b1a9813

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request #53197 from FengyunPan/node-0
Automatic merge from submit-queue (batch tested with PRs 53567, 53197, 52944, 49593). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. [OpenStack]Add codes to check the count of nodes(members) After merging this PR(#53146), if there is no available nodes for the loadbalancer service, UpdateLoadBalancer() will run panic. **Release note**: ```release-note NONE ```
2 parents 7c5429f + 0c46bff commit b1a9813

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

pkg/cloudprovider/providers/openstack/openstack_loadbalancer.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,10 @@ func getSubnetIDForLB(compute *gophercloud.ServiceClient, node v1.Node) (string,
623623
func (lbaas *LbaasV2) EnsureLoadBalancer(clusterName string, apiService *v1.Service, nodes []*v1.Node) (*v1.LoadBalancerStatus, error) {
624624
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)
625625

626+
if len(nodes) == 0 {
627+
return nil, fmt.Errorf("There are no available nodes for LoadBalancer service %s/%s", apiService.Namespace, apiService.Name)
628+
}
629+
626630
if len(lbaas.opts.SubnetId) == 0 {
627631
// Get SubnetId automatically.
628632
// The LB needs to be configured with instance addresses on the same subnet, so get SubnetId by one node.
@@ -1024,7 +1028,7 @@ func (lbaas *LbaasV2) UpdateLoadBalancer(clusterName string, service *v1.Service
10241028
loadBalancerName := cloudprovider.GetLoadBalancerName(service)
10251029
glog.V(4).Infof("UpdateLoadBalancer(%v, %v, %v)", clusterName, loadBalancerName, nodes)
10261030

1027-
if len(lbaas.opts.SubnetId) == 0 {
1031+
if len(lbaas.opts.SubnetId) == 0 && len(nodes) > 0 {
10281032
// Get SubnetId automatically.
10291033
// The LB needs to be configured with instance addresses on the same subnet, so get SubnetId by one node.
10301034
subnetID, err := getSubnetIDForLB(lbaas.compute, *nodes[0])
@@ -1322,6 +1326,10 @@ func (lb *LbaasV1) GetLoadBalancer(clusterName string, service *v1.Service) (*v1
13221326
func (lb *LbaasV1) EnsureLoadBalancer(clusterName string, apiService *v1.Service, nodes []*v1.Node) (*v1.LoadBalancerStatus, error) {
13231327
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)
13241328

1329+
if len(nodes) == 0 {
1330+
return nil, fmt.Errorf("There are no available nodes for LoadBalancer service %s/%s", apiService.Namespace, apiService.Name)
1331+
}
1332+
13251333
if len(lb.opts.SubnetId) == 0 {
13261334
// Get SubnetId automatically.
13271335
// The LB needs to be configured with instance addresses on the same subnet, so get SubnetId by one node.

0 commit comments

Comments
 (0)