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

Commit 7b7891a

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request #58560 from FengyunPan/fix-ErrResourceNotFound
Automatic merge from submit-queue. 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>. 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. **Release note**: ```release-note NONE ```
2 parents 6ec588e + 9debf30 commit 7b7891a

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)