Skip to content

Commit fcce5ad

Browse files
committed
ignore router get return 404 error
1 parent 14acfa2 commit fcce5ad

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

pkg/cloud/services/networking/network.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package networking
1919
import (
2020
"fmt"
2121
"sigs.k8s.io/cluster-api-provider-openstack/pkg/record"
22+
capierrors "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors"
2223

2324
"github.com/gophercloud/gophercloud"
2425
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags"
@@ -213,6 +214,9 @@ func (s *Service) existsNetwork(networkID string) (bool, error) {
213214
}
214215
network, err := networks.Get(s.client, networkID).Extract()
215216
if err != nil {
217+
if capierrors.IsNotFound(err) {
218+
return false, nil
219+
}
216220
return false, err
217221
}
218222
if network == nil {

pkg/cloud/services/networking/router.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
2222
"sigs.k8s.io/cluster-api-provider-openstack/pkg/record"
23+
"sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors"
2324

2425
"github.com/gophercloud/gophercloud"
2526
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags"
@@ -281,6 +282,9 @@ func (s *Service) existsRouter(routerID string) (bool, error) {
281282
}
282283
router, err := routers.Get(s.client, routerID).Extract()
283284
if err != nil {
285+
if errors.IsNotFound(err) {
286+
return false, nil
287+
}
284288
return false, err
285289
}
286290
if router == nil {

pkg/cloud/services/networking/securitygroups.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package networking
1818

1919
import (
2020
"fmt"
21+
2122
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups"
2223
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules"
2324
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha3"

pkg/utils/errors/errors.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package errors
18+
19+
import (
20+
"net/http"
21+
22+
"github.com/gophercloud/gophercloud"
23+
)
24+
25+
func IsNotFound(err error) bool {
26+
if _, ok := err.(gophercloud.ErrDefault404); ok {
27+
return true
28+
}
29+
30+
if _, ok := err.(gophercloud.ErrResourceNotFound); ok {
31+
return true
32+
}
33+
34+
if errCode, ok := err.(gophercloud.ErrUnexpectedResponseCode); ok {
35+
if errCode.Actual == http.StatusNotFound {
36+
return true
37+
}
38+
}
39+
40+
return false
41+
}
42+
43+
func IsInvalidError(err error) bool {
44+
if _, ok := err.(gophercloud.ErrDefault400); ok {
45+
return true
46+
}
47+
48+
if errCode, ok := err.(gophercloud.ErrUnexpectedResponseCode); ok {
49+
if errCode.Actual == http.StatusBadRequest {
50+
return true
51+
}
52+
}
53+
54+
return false
55+
}

0 commit comments

Comments
 (0)