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

Commit 9debf30

Browse files
committed
Fix non-interface type ErrResourceNotFound on left
Related to #58145 The gophercloud.ErrResourceNotFound is not a interface, so should use reflect to get its type then do a check.
1 parent c302324 commit 9debf30

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

pkg/cloudprovider/providers/openstack/openstack_loadbalancer.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package openstack
1919
import (
2020
"fmt"
2121
"net"
22+
"reflect"
2223
"strings"
2324
"time"
2425

@@ -568,6 +569,21 @@ func getNodeSecurityGroupIDForLB(compute *gophercloud.ServiceClient, nodes []*v1
568569
return nodeSecurityGroupIDs.List(), nil
569570
}
570571

572+
// isSecurityGroupNotFound return true while 'err' is object of gophercloud.ErrResourceNotFound
573+
func isSecurityGroupNotFound(err error) bool {
574+
errType := reflect.TypeOf(err).String()
575+
errTypeSlice := strings.Split(errType, ".")
576+
errTypeValue := ""
577+
if len(errTypeSlice) != 0 {
578+
errTypeValue = errTypeSlice[len(errTypeSlice)-1]
579+
}
580+
if errTypeValue == "ErrResourceNotFound" {
581+
return true
582+
}
583+
584+
return false
585+
}
586+
571587
// getFloatingNetworkIdForLB returns a floating-network-id for cluster.
572588
func getFloatingNetworkIdForLB(client *gophercloud.ServiceClient) (string, error) {
573589
var floatingNetworkIds []string
@@ -993,10 +1009,8 @@ func (lbaas *LbaasV2) ensureSecurityGroup(clusterName string, apiService *v1.Ser
9931009
lbSecGroupName := getSecurityGroupName(apiService)
9941010
lbSecGroupID, err := groups.IDFromName(lbaas.network, lbSecGroupName)
9951011
if err != nil {
996-
// check whether security group does not exist
997-
_, ok := err.(*gophercloud.ErrResourceNotFound)
998-
if ok {
999-
// create it later
1012+
// If the security group of LB not exist, create it later
1013+
if isSecurityGroupNotFound(err) {
10001014
lbSecGroupID = ""
10011015
} else {
10021016
return fmt.Errorf("error occurred finding security group: %s: %v", lbSecGroupName, err)
@@ -1495,9 +1509,7 @@ func (lbaas *LbaasV2) EnsureSecurityGroupDeleted(clusterName string, service *v1
14951509
lbSecGroupName := getSecurityGroupName(service)
14961510
lbSecGroupID, err := groups.IDFromName(lbaas.network, lbSecGroupName)
14971511
if err != nil {
1498-
// check whether security group does not exist
1499-
_, ok := err.(*gophercloud.ErrResourceNotFound)
1500-
if ok {
1512+
if isSecurityGroupNotFound(err) {
15011513
// It is OK when the security group has been deleted by others.
15021514
return nil
15031515
} else {

0 commit comments

Comments
 (0)