mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -568,6 +569,21 @@ func getNodeSecurityGroupIDForLB(compute *gophercloud.ServiceClient, nodes []*v1
|
|||||||
return nodeSecurityGroupIDs.List(), nil
|
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.
|
// getFloatingNetworkIdForLB returns a floating-network-id for cluster.
|
||||||
func getFloatingNetworkIdForLB(client *gophercloud.ServiceClient) (string, error) {
|
func getFloatingNetworkIdForLB(client *gophercloud.ServiceClient) (string, error) {
|
||||||
var floatingNetworkIds []string
|
var floatingNetworkIds []string
|
||||||
@ -993,10 +1009,8 @@ func (lbaas *LbaasV2) ensureSecurityGroup(clusterName string, apiService *v1.Ser
|
|||||||
lbSecGroupName := getSecurityGroupName(apiService)
|
lbSecGroupName := getSecurityGroupName(apiService)
|
||||||
lbSecGroupID, err := groups.IDFromName(lbaas.network, lbSecGroupName)
|
lbSecGroupID, err := groups.IDFromName(lbaas.network, lbSecGroupName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// check whether security group does not exist
|
// If the security group of LB not exist, create it later
|
||||||
_, ok := err.(*gophercloud.ErrResourceNotFound)
|
if isSecurityGroupNotFound(err) {
|
||||||
if ok {
|
|
||||||
// create it later
|
|
||||||
lbSecGroupID = ""
|
lbSecGroupID = ""
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("error occurred finding security group: %s: %v", lbSecGroupName, err)
|
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)
|
lbSecGroupName := getSecurityGroupName(service)
|
||||||
lbSecGroupID, err := groups.IDFromName(lbaas.network, lbSecGroupName)
|
lbSecGroupID, err := groups.IDFromName(lbaas.network, lbSecGroupName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// check whether security group does not exist
|
if isSecurityGroupNotFound(err) {
|
||||||
_, ok := err.(*gophercloud.ErrResourceNotFound)
|
|
||||||
if ok {
|
|
||||||
// It is OK when the security group has been deleted by others.
|
// It is OK when the security group has been deleted by others.
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user