Unverified Commit 7a8ee6b6 authored by Olaf Klischat's avatar Olaf Klischat Committed by Davanum Srinivas

BUGFIX: must use ID, not name, of the node security group when adding rules to it

parent 1a1c0bab
...@@ -547,14 +547,14 @@ func getSubnetIDForLB(compute *gophercloud.ServiceClient, node v1.Node) (string, ...@@ -547,14 +547,14 @@ func getSubnetIDForLB(compute *gophercloud.ServiceClient, node v1.Node) (string,
} }
// getNodeSecurityGroupIDForLB lists node-security-groups for specific nodes // getNodeSecurityGroupIDForLB lists node-security-groups for specific nodes
func getNodeSecurityGroupIDForLB(compute *gophercloud.ServiceClient, nodes []*v1.Node) ([]string, error) { func getNodeSecurityGroupIDForLB(compute *gophercloud.ServiceClient, network *gophercloud.ServiceClient, nodes []*v1.Node) ([]string, error) {
nodeSecurityGroupIDs := sets.NewString() secGroupNames := sets.NewString()
for _, node := range nodes { for _, node := range nodes {
nodeName := types.NodeName(node.Name) nodeName := types.NodeName(node.Name)
srv, err := getServerByName(compute, nodeName, true) srv, err := getServerByName(compute, nodeName, true)
if err != nil { if err != nil {
return nodeSecurityGroupIDs.List(), err return []string{}, err
} }
// use the first node-security-groups // use the first node-security-groups
...@@ -562,11 +562,19 @@ func getNodeSecurityGroupIDForLB(compute *gophercloud.ServiceClient, nodes []*v1 ...@@ -562,11 +562,19 @@ func getNodeSecurityGroupIDForLB(compute *gophercloud.ServiceClient, nodes []*v1
// case 1: node1:SG1 node2:SG2 return SG1,SG2 // case 1: node1:SG1 node2:SG2 return SG1,SG2
// case 2: node1:SG1,SG2 node2:SG3,SG4 return SG1,SG3 // case 2: node1:SG1,SG2 node2:SG3,SG4 return SG1,SG3
// case 3: node1:SG1,SG2 node2:SG2,SG3 return SG1,SG2 // case 3: node1:SG1,SG2 node2:SG2,SG3 return SG1,SG2
securityGroupName := srv.SecurityGroups[0]["name"] secGroupNames.Insert(srv.SecurityGroups[0]["name"].(string))
nodeSecurityGroupIDs.Insert(securityGroupName.(string))
} }
return nodeSecurityGroupIDs.List(), nil secGroupIDs := make([]string, secGroupNames.Len())
for i, name := range secGroupNames.List() {
secGroupID, err := groups.IDFromName(network, name)
if err != nil {
return []string{}, err
}
secGroupIDs[i] = secGroupID
}
return secGroupIDs, nil
} }
// isSecurityGroupNotFound return true while 'err' is object of gophercloud.ErrResourceNotFound // isSecurityGroupNotFound return true while 'err' is object of gophercloud.ErrResourceNotFound
...@@ -987,7 +995,7 @@ func (lbaas *LbaasV2) ensureSecurityGroup(clusterName string, apiService *v1.Ser ...@@ -987,7 +995,7 @@ func (lbaas *LbaasV2) ensureSecurityGroup(clusterName string, apiService *v1.Ser
// find node-security-group for service // find node-security-group for service
var err error var err error
if len(lbaas.opts.NodeSecurityGroupIDs) == 0 { if len(lbaas.opts.NodeSecurityGroupIDs) == 0 {
lbaas.opts.NodeSecurityGroupIDs, err = getNodeSecurityGroupIDForLB(lbaas.compute, nodes) lbaas.opts.NodeSecurityGroupIDs, err = getNodeSecurityGroupIDForLB(lbaas.compute, lbaas.network, nodes)
if err != nil { if err != nil {
return fmt.Errorf("failed to find node-security-group for loadbalancer service %s/%s: %v", apiService.Namespace, apiService.Name, err) return fmt.Errorf("failed to find node-security-group for loadbalancer service %s/%s: %v", apiService.Namespace, apiService.Name, err)
} }
...@@ -1299,7 +1307,7 @@ func (lbaas *LbaasV2) updateSecurityGroup(clusterName string, apiService *v1.Ser ...@@ -1299,7 +1307,7 @@ func (lbaas *LbaasV2) updateSecurityGroup(clusterName string, apiService *v1.Ser
originalNodeSecurityGroupIDs := lbaas.opts.NodeSecurityGroupIDs originalNodeSecurityGroupIDs := lbaas.opts.NodeSecurityGroupIDs
var err error var err error
lbaas.opts.NodeSecurityGroupIDs, err = getNodeSecurityGroupIDForLB(lbaas.compute, nodes) lbaas.opts.NodeSecurityGroupIDs, err = getNodeSecurityGroupIDForLB(lbaas.compute, lbaas.network, nodes)
if err != nil { if err != nil {
return fmt.Errorf("failed to find node-security-group for loadbalancer service %s/%s: %v", apiService.Namespace, apiService.Name, err) return fmt.Errorf("failed to find node-security-group for loadbalancer service %s/%s: %v", apiService.Namespace, apiService.Name, err)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment