Skip to content

Commit 0989cd0

Browse files
committed
refactor: simplify GetSubnet function
1 parent efd121a commit 0989cd0

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

internal/client/networking.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
networkingapi "github.com/nutanix/ntnx-api-golang-clients/networking-go-client/v4/models/networking/v4/config"
1616
networkingprismapi "github.com/nutanix/ntnx-api-golang-clients/networking-go-client/v4/models/prism/v4/config"
1717
"go4.org/netipx"
18-
kerrors "k8s.io/apimachinery/pkg/util/errors"
1918
"k8s.io/utils/ptr"
2019

2120
"github.com/nutanix-cloud-native/prism-go-client/utils"
@@ -421,25 +420,12 @@ func (n *networkingClient) GetSubnet(
421420
subnetExtIDOrName string,
422421
opts GetSubnetOpts,
423422
) (*Subnet, error) {
424-
var errs []error
425-
426423
subnetUUID, err := uuid.Parse(subnetExtIDOrName)
427424
if err == nil {
428-
subnet, errByExtID := n.getSubnetByExtID(subnetUUID)
429-
if errByExtID == nil {
430-
return subnet, nil
431-
}
432-
errs = append(errs, errByExtID)
433-
}
434-
435-
subnet, errByName := n.getSubnetByName(subnetExtIDOrName, opts)
436-
if errByName != nil {
437-
errs = append(errs, errByName)
438-
aggErr := kerrors.NewAggregate(errs)
439-
return nil, fmt.Errorf("failed to get subnet %q: %w", subnetExtIDOrName, aggErr)
425+
return n.getSubnetByExtID(subnetUUID)
440426
}
441427

442-
return subnet, nil
428+
return n.getSubnetByName(subnetExtIDOrName, opts)
443429
}
444430

445431
func (n *networkingClient) getSubnetByName(subnetName string, opts GetSubnetOpts) (*Subnet, error) {

0 commit comments

Comments
 (0)