mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
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 ```
This commit is contained in:
commit
ce719592fb
@ -19,6 +19,7 @@ package openstack
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -568,6 +569,21 @@ func getNodeSecurityGroupIDForLB(compute *gophercloud.ServiceClient, nodes []*v1
|
||||
return nodeSecurityGroupIDs.List(), nil
|
||||
}
|
||||
|
||||
// isSecurityGroupNotFound return true while 'err' is object of gophercloud.ErrResourceNotFound
|
||||
func isSecurityGroupNotFound(err error) bool {
|
||||
errType := reflect.TypeOf(err).String()
|
||||
errTypeSlice := strings.Split(errType, ".")
|
||||
errTypeValue := ""
|
||||
if len(errTypeSlice) != 0 {
|
||||
errTypeValue = errTypeSlice[len(errTypeSlice)-1]
|
||||
}
|
||||
if errTypeValue == "ErrResourceNotFound" {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// getFloatingNetworkIdForLB returns a floating-network-id for cluster.
|
||||
func getFloatingNetworkIdForLB(client *gophercloud.ServiceClient) (string, error) {
|
||||
var floatingNetworkIds []string
|
||||
@ -993,10 +1009,8 @@ func (lbaas *LbaasV2) ensureSecurityGroup(clusterName string, apiService *v1.Ser
|
||||
lbSecGroupName := getSecurityGroupName(apiService)
|
||||
lbSecGroupID, err := groups.IDFromName(lbaas.network, lbSecGroupName)
|
||||
if err != nil {
|
||||
// check whether security group does not exist
|
||||
_, ok := err.(*gophercloud.ErrResourceNotFound)
|
||||
if ok {
|
||||
// create it later
|
||||
// If the security group of LB not exist, create it later
|
||||
if isSecurityGroupNotFound(err) {
|
||||
lbSecGroupID = ""
|
||||
} else {
|
||||
return fmt.Errorf("error occurred finding security group: %s: %v", lbSecGroupName, err)
|
||||
@ -1495,9 +1509,7 @@ func (lbaas *LbaasV2) EnsureSecurityGroupDeleted(clusterName string, service *v1
|
||||
lbSecGroupName := getSecurityGroupName(service)
|
||||
lbSecGroupID, err := groups.IDFromName(lbaas.network, lbSecGroupName)
|
||||
if err != nil {
|
||||
// check whether security group does not exist
|
||||
_, ok := err.(*gophercloud.ErrResourceNotFound)
|
||||
if ok {
|
||||
if isSecurityGroupNotFound(err) {
|
||||
// It is OK when the security group has been deleted by others.
|
||||
return nil
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user