Skip to content

Commit

Permalink
Add custom type for resource not found error
Browse files Browse the repository at this point in the history
  • Loading branch information
Amulyam24 committed Apr 23, 2024
1 parent 910b331 commit 295f003
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
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
24 changes: 24 additions & 0 deletions cloud/scope/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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")
)

0 comments on commit 295f003

Please sign in to comment.