Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom type for resource not found error #1739

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions cloud/scope/powervs_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,7 @@ func (s *PowerVSClusterScope) DeleteLoadBalancer() (bool, error) {
})

if err != nil {
if strings.Contains(err.Error(), "cannot be found") {
if strings.Contains(err.Error(), string(VPCLoadBalancerNotFound)) {
s.Info("VPC load balancer successfully deleted")
return false, nil
}
Expand Down Expand Up @@ -1862,7 +1862,7 @@ func (s *PowerVSClusterScope) DeleteVPCSubnet() (bool, error) {
})

if err != nil {
if strings.Contains(err.Error(), "Subnet not found") {
if strings.Contains(err.Error(), string(VPCSubnetNotFound)) {
s.Info("VPC subnet successfully deleted")
return false, nil
}
Expand Down Expand Up @@ -1898,7 +1898,7 @@ func (s *PowerVSClusterScope) DeleteVPC() (bool, error) {
})

if err != nil {
if strings.Contains(err.Error(), "VPC not found") {
if strings.Contains(err.Error(), string(VPCNotFound)) {
s.Info("VPC successfully deleted")
return false, nil
}
Expand Down Expand Up @@ -1932,7 +1932,7 @@ func (s *PowerVSClusterScope) DeleteTransitGateway() (bool, error) {
})

if err != nil {
if strings.Contains(err.Error(), "gateway was not found") {
if strings.Contains(err.Error(), string(TransitGatewayNotFound)) {
s.Info("Transit gateway successfully deleted")
return false, nil
}
Expand Down Expand Up @@ -1998,7 +1998,7 @@ func (s *PowerVSClusterScope) DeleteDHCPServer() error {

server, err := s.IBMPowerVSClient.GetDHCPServer(*s.IBMPowerVSCluster.Status.DHCPServer.ID)
if err != nil {
if strings.Contains(err.Error(), "dhcp server does not exist") {
if strings.Contains(err.Error(), string(DHCPServerNotFound)) {
s.Info("DHCP server successfully deleted")
return nil
}
Expand Down Expand Up @@ -2067,7 +2067,7 @@ func (s *PowerVSClusterScope) DeleteCOSInstance() error {
ID: s.IBMPowerVSCluster.Status.COSInstance.ID,
})
if err != nil {
if strings.Contains(err.Error(), "COS instance unavailable") {
if strings.Contains(err.Error(), string(COSInstanceNotFound)) {
return nil
}
return fmt.Errorf("error fetching COS service instance: %w", err)
Expand Down
40 changes: 40 additions & 0 deletions cloud/scope/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright 2024 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package scope

// ResourceNotFound is the string representing an error when a resource is not found in IBM Cloud.
type ResourceNotFound string

var (
// VPCLoadBalancerNotFound is the error returned when a VPC load balancer is not found.
VPCLoadBalancerNotFound = ResourceNotFound("cannot be found")

// VPCSubnetNotFound is the error returned when a VPC subnet is not found.
VPCSubnetNotFound = ResourceNotFound("Subnet not found")

// VPCNotFound is the error returned when a VPC is not found.
VPCNotFound = ResourceNotFound("VPC not found")

// TransitGatewayNotFound is the error returned when a transit gateway is not found.
TransitGatewayNotFound = ResourceNotFound("gateway was not found")

// DHCPServerNotFound is the error returned when a DHCP server is not found.
DHCPServerNotFound = ResourceNotFound("dhcp server does not exist")

// COSInstanceNotFound is the error returned when a COS service instance is not found.
COSInstanceNotFound = ResourceNotFound("COS instance unavailable")
)