Skip to content

Commit

Permalink
Merge pull request #41 from telekom/fix/infoblox-error-handling
Browse files Browse the repository at this point in the history
fix incorrect type in infoblox error handling
  • Loading branch information
schrej authored Aug 12, 2024
2 parents 9ab6ad1 + 90b1773 commit 5cf9b82
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions internal/controllers/ipaddressclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ package controllers

import (
"context"
"errors"
"fmt"
"net/netip"
"strconv"
"strings"

ibclient "github.com/infobloxopen/infoblox-go-client/v2"
"github.com/pkg/errors"
"github.com/telekom/cluster-api-ipam-provider-infoblox/api/v1alpha1"
"github.com/telekom/cluster-api-ipam-provider-infoblox/internal/hostname"
"github.com/telekom/cluster-api-ipam-provider-infoblox/pkg/infoblox"
Expand Down Expand Up @@ -119,7 +119,7 @@ func (h *InfobloxClaimHandler) FetchPool(ctx context.Context) (client.Object, *c

h.pool = &v1alpha1.InfobloxIPPool{}
if err = h.Client.Get(ctx, types.NamespacedName{Namespace: h.claim.Namespace, Name: h.claim.Spec.PoolRef.Name}, h.pool); err != nil && !apierrors.IsNotFound(err) {
return nil, nil, errors.Wrap(err, "failed to fetch pool")
return nil, nil, fmt.Errorf("failed to fetch pool: %w", err)
}

if h.pool == nil {
Expand Down Expand Up @@ -228,7 +228,8 @@ func (h *InfobloxClaimHandler) ReleaseAddress(ctx context.Context) (*ctrl.Result

err = h.ibclient.ReleaseAddress(h.pool.Spec.NetworkView, subnet, hostName)
if err != nil {
if errors.As(err, &ibclient.NotFoundError{}) {
// since ibclient.NotFoundError has a pointer receiver on it's Error() method, we can't use errors.As() here.
if _, ok := err.(*ibclient.NotFoundError); !ok {
logger.Error(err, "failed to release address for host", "hostname", hostName)
}
continue
Expand All @@ -238,7 +239,8 @@ func (h *InfobloxClaimHandler) ReleaseAddress(ctx context.Context) (*ctrl.Result
}

if err != nil {
if errors.As(err, &ibclient.NotFoundError{}) {
// since ibclient.NotFoundError has a pointer receiver on it's Error() method, we can't use errors.As() here.
if _, ok := err.(*ibclient.NotFoundError); !ok {
return nil, fmt.Errorf("unable to release address: %w", err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/infoblox/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func (c *client) getOrNewHostRecord(view, hostname, zone string) (*ibclient.Host
// [Issue] For some reason Infoblox does not assign view to the host record. Empty netview and dnsview is a workaround to find host.
hostRecord, err := c.objMgr.GetHostRecord("", "", hostname, "", "")
if err != nil {
var notFoundError *ibclient.NotFoundError
if !errors.As(err, &notFoundError) {
// since ibclient.NotFoundError has a pointer receiver on it's Error() method, we can't use errors.As() here.
if _, ok := err.(*ibclient.NotFoundError); !ok {
return nil, err
}
}
Expand Down

0 comments on commit 5cf9b82

Please sign in to comment.