diff --git a/controllers/controller_test.go b/controllers/controller_test.go index 6e38dfb..56692fc 100644 --- a/controllers/controller_test.go +++ b/controllers/controller_test.go @@ -640,8 +640,7 @@ var _ = Describe("Network Interface and LoadBalancer Controller", func() { Expect(updatedIface.Spec.FirewallRules[0].DestinationPrefix.String()).To(Equal("10.0.0.10/32")) Expect(updatedIface.Status.State).To(Equal(metalnetv1alpha1.NetworkInterfaceStateReady)) - // TODO parameters in GetFwRule currently not in correct oreder, they need to be swapped when it is fixed in library - fw1, err := dpdkClient.GetFirewallRule(ctx, string(fr1.FirewallRuleID), string(updatedIface.UID)) + fw1, err := dpdkClient.GetFirewallRule(ctx, string(updatedIface.UID), string(fr1.FirewallRuleID)) Expect(err).NotTo(HaveOccurred()) Expect(fw1.Spec.FirewallAction).To(Equal("Accept")) Expect(fw1.Spec.TrafficDirection).To(Equal("Ingress")) @@ -687,8 +686,7 @@ var _ = Describe("Network Interface and LoadBalancer Controller", func() { Expect(updatedIface.Spec.FirewallRules).To(BeEmpty()) Expect(updatedIface.Status.State).To(Equal(metalnetv1alpha1.NetworkInterfaceStateReady)) - // TODO parameters in GetFwRule currently not in correct oreder, they need to be swapped when it is fixed in library - fw1, err = dpdkClient.GetFirewallRule(ctx, string(fr1.FirewallRuleID), string(updatedIface.UID)) + fw1, err = dpdkClient.GetFirewallRule(ctx, string(updatedIface.UID), string(fr1.FirewallRuleID)) Expect(err).To(HaveOccurred()) Expect(fw1.Status.Code).To(Equal(int32(dpdkerrors.NOT_FOUND))) }) diff --git a/controllers/loadbalancer_controller.go b/controllers/loadbalancer_controller.go index f3c709e..39ee4ba 100644 --- a/controllers/loadbalancer_controller.go +++ b/controllers/loadbalancer_controller.go @@ -152,7 +152,11 @@ func (r *LoadBalancerReconciler) deleteLoadBalancer( log.V(1).Info("Removed loadbalancer route if existed") log.V(1).Info("Deleting dpdk loadbalancer if exists") - if _, err := r.DPDK.DeleteLoadBalancer(ctx, string(lb.UID)); dpdkerrors.IgnoreStatusErrorCode(err, dpdkerrors.NOT_FOUND) != nil { + if _, err := r.DPDK.DeleteLoadBalancer( + ctx, + string(lb.UID), + dpdkerrors.Ignore(dpdkerrors.NOT_FOUND), + ); err != nil { return fmt.Errorf("error deleting loadbalancer: %w", err) } diff --git a/controllers/network_controller.go b/controllers/network_controller.go index 0aa83da..737fe2e 100644 --- a/controllers/network_controller.go +++ b/controllers/network_controller.go @@ -196,7 +196,9 @@ func (r *NetworkReconciler) createDefaultRouteIfNotExists(ctx context.Context, v IP: &r.RouterAddress, }, }, - }); dpdkerrors.IgnoreStatusErrorCode(err, dpdkerrors.ROUTE_EXISTS) != nil { + }, + dpdkerrors.Ignore(dpdkerrors.ROUTE_EXISTS), + ); err != nil { return fmt.Errorf("error creating route: %w", err) } return nil @@ -204,7 +206,12 @@ func (r *NetworkReconciler) createDefaultRouteIfNotExists(ctx context.Context, v func (r *NetworkReconciler) deleteDefaultRouteIfExists(ctx context.Context, vni uint32) error { defaultRoutePrefix := netip.MustParsePrefix("0.0.0.0/0") - if _, err := r.DPDK.DeleteRoute(ctx, vni, &defaultRoutePrefix); dpdkerrors.IgnoreStatusErrorCode(err, dpdkerrors.NO_VNI, dpdkerrors.ROUTE_NOT_FOUND) != nil { + if _, err := r.DPDK.DeleteRoute( + ctx, + vni, + &defaultRoutePrefix, + dpdkerrors.Ignore(dpdkerrors.NO_VNI, dpdkerrors.ROUTE_NOT_FOUND), + ); err != nil { return fmt.Errorf("error deleting route: %w", err) } return nil diff --git a/controllers/networkinterface_controller.go b/controllers/networkinterface_controller.go index 0fc601d..ae5e41a 100644 --- a/controllers/networkinterface_controller.go +++ b/controllers/networkinterface_controller.go @@ -167,7 +167,11 @@ func (r *NetworkInterfaceReconciler) releaseNetFnIfClaimExists(uid types.UID) er } func (r *NetworkInterfaceReconciler) deleteDPDKVirtualIPIfExists(ctx context.Context, nic *metalnetv1alpha1.NetworkInterface) error { - if _, err := r.DPDK.DeleteVirtualIP(ctx, string(nic.UID)); dpdkerrors.IgnoreStatusErrorCode(err, dpdkerrors.NO_VM) != nil { + if _, err := r.DPDK.DeleteVirtualIP( + ctx, + string(nic.UID), + dpdkerrors.Ignore(dpdkerrors.NO_VM), + ); err != nil { return fmt.Errorf("error deleting dpdk virtual ip: %w", err) } return nil @@ -411,28 +415,47 @@ func (r *NetworkInterfaceReconciler) createDPDKFwRule(ctx context.Context, nic * } func (r *NetworkInterfaceReconciler) deleteDPDKfwRuleIDIfExists(ctx context.Context, nicUID string, ruleUID string) error { - if _, err := r.DPDK.DeleteFirewallRule(ctx, nicUID, ruleUID); dpdkerrors.IgnoreStatusErrorCode(err, dpdkerrors.NO_VM, dpdkerrors.NOT_FOUND) != nil { + if _, err := r.DPDK.DeleteFirewallRule( + ctx, + nicUID, + ruleUID, + dpdkerrors.Ignore(dpdkerrors.NO_VM, dpdkerrors.NOT_FOUND), + ); err != nil { return fmt.Errorf("error deleting firewall rule: %w", err) } return nil } func (r *NetworkInterfaceReconciler) deleteDPDKLBTargetIfExists(ctx context.Context, nicUID types.UID, prefix netip.Prefix) error { - if _, err := r.DPDK.DeleteLoadBalancerPrefix(ctx, string(nicUID), &prefix); dpdkerrors.IgnoreStatusErrorCode(err, dpdkerrors.NO_VM, dpdkerrors.NOT_FOUND) != nil { + if _, err := r.DPDK.DeleteLoadBalancerPrefix( + ctx, + string(nicUID), + &prefix, + dpdkerrors.Ignore(dpdkerrors.NO_VM, dpdkerrors.NOT_FOUND), + ); err != nil { return fmt.Errorf("error deleting lb prefix: %w", err) } return nil } func (r *NetworkInterfaceReconciler) deleteDPDKPrefixIfExists(ctx context.Context, nicUID types.UID, prefix netip.Prefix) error { - if _, err := r.DPDK.DeletePrefix(ctx, string(nicUID), &prefix); dpdkerrors.IgnoreStatusErrorCode(err, dpdkerrors.NO_VM, dpdkerrors.NOT_FOUND) != nil { + if _, err := r.DPDK.DeletePrefix( + ctx, + string(nicUID), + &prefix, + dpdkerrors.Ignore(dpdkerrors.NO_VM, dpdkerrors.NOT_FOUND), + ); err != nil { return fmt.Errorf("error deleting prefix: %w", err) } return nil } func (r *NetworkInterfaceReconciler) deleteDPDKInterfaceIfExists(ctx context.Context, uid types.UID) error { - if _, err := r.DPDK.DeleteInterface(ctx, string(uid)); dpdkerrors.IgnoreStatusErrorCode(err, dpdkerrors.NOT_FOUND) != nil { + if _, err := r.DPDK.DeleteInterface( + ctx, + string(uid), + dpdkerrors.Ignore(dpdkerrors.NOT_FOUND), + ); err != nil { return fmt.Errorf("error deleting interface: %w", err) } return nil @@ -543,7 +566,11 @@ func (r *NetworkInterfaceReconciler) deleteExistingNATIP(ctx context.Context, lo } func (r *NetworkInterfaceReconciler) deleteDPDKNATIPIfExists(ctx context.Context, nic *metalnetv1alpha1.NetworkInterface) error { - if _, err := r.DPDK.DeleteNat(ctx, string(nic.UID)); dpdkerrors.IgnoreStatusErrorCode(err, dpdkerrors.NO_VM) != nil { + if _, err := r.DPDK.DeleteNat( + ctx, + string(nic.UID), + dpdkerrors.Ignore(dpdkerrors.NO_VM), + ); err != nil { return fmt.Errorf("error deleting dpdk nat ip: %w", err) } return nil diff --git a/dpdkmetalbond/dpdkmetalbond.go b/dpdkmetalbond/dpdkmetalbond.go index b800b65..a3b786c 100644 --- a/dpdkmetalbond/dpdkmetalbond.go +++ b/dpdkmetalbond/dpdkmetalbond.go @@ -173,7 +173,8 @@ func (c *Client) addLocalRoute(destVni mb.VNI, vni mb.VNI, dest mb.Destination, Spec: dpdk.LoadBalancerTargetSpec{ TargetIP: &hop.TargetAddress, }, - }); dpdkerrors.IgnoreStatusErrorCode(err, dpdkerrors.ALREADY_EXISTS) != nil { + }, dpdkerrors.Ignore(dpdkerrors.ALREADY_EXISTS), + ); err != nil { return fmt.Errorf("error creating lb target: %w", err) } return nil @@ -191,7 +192,8 @@ func (c *Client) addLocalRoute(destVni mb.VNI, vni mb.VNI, dest mb.Destination, MaxPort: uint32(hop.NATPortRangeTo), UnderlayRoute: &hop.TargetAddress, }, - }); dpdkerrors.IgnoreStatusErrorCode(err, dpdkerrors.ALREADY_EXISTS) != nil { + }, dpdkerrors.Ignore(dpdkerrors.ALREADY_EXISTS), + ); err != nil { return fmt.Errorf("error nat route: %w", err) } return nil @@ -208,7 +210,8 @@ func (c *Client) addLocalRoute(destVni mb.VNI, vni mb.VNI, dest mb.Destination, IP: &hop.TargetAddress, }, }, - }); dpdkerrors.IgnoreStatusErrorCode(err, dpdkerrors.ROUTE_EXISTS) != nil { + }, dpdkerrors.Ignore(dpdkerrors.ROUTE_EXISTS), + ); err != nil { return fmt.Errorf("error creating route: %w", err) } return nil @@ -232,7 +235,8 @@ func (c *Client) removeLocalRoute(destVni mb.VNI, vni mb.VNI, dest mb.Destinatio ctx, string(c.lbServerMap[uint32(vni)][ip]), &hop.TargetAddress, - ); dpdkerrors.IgnoreStatusErrorCode(err, dpdkerrors.NOT_FOUND, dpdkerrors.NO_BACKIP, dpdkerrors.NO_LB) != nil { + dpdkerrors.Ignore(dpdkerrors.NOT_FOUND, dpdkerrors.NO_BACKIP, dpdkerrors.NO_LB), + ); err != nil { return fmt.Errorf("error deleting lb target: %w", err) } return nil @@ -250,7 +254,8 @@ func (c *Client) removeLocalRoute(destVni mb.VNI, vni mb.VNI, dest mb.Destinatio MaxPort: uint32(hop.NATPortRangeTo), UnderlayRoute: &hop.TargetAddress, }, - }); dpdkerrors.IgnoreStatusErrorCode(err, dpdkerrors.NOT_FOUND) != nil { + }, dpdkerrors.Ignore(dpdkerrors.NOT_FOUND), + ); err != nil { return fmt.Errorf("error deleting nat route: %w", err) } return nil @@ -260,7 +265,8 @@ func (c *Client) removeLocalRoute(destVni mb.VNI, vni mb.VNI, dest mb.Destinatio ctx, uint32(vni), &dest.Prefix, - ); dpdkerrors.IgnoreStatusErrorCode(err, dpdkerrors.NO_VNI, dpdkerrors.ROUTE_NOT_FOUND) != nil { + dpdkerrors.Ignore(dpdkerrors.NO_VNI, dpdkerrors.ROUTE_NOT_FOUND), + ); err != nil { return fmt.Errorf("error deleting route: %w", err) } return nil @@ -349,7 +355,12 @@ func (c *Client) CleanupNotPeeredRoutes(vni uint32) error { for _, route := range routes.Items { // only delete route if it is not the local vni and not peered if route.Spec.NextHop.VNI != vni && (ok && !set.Has(route.Spec.NextHop.VNI)) { - if _, err := c.dpdk.DeleteRoute(ctx, vni, route.Spec.Prefix); dpdkerrors.IgnoreStatusErrorCode(err, dpdkerrors.NO_VNI, dpdkerrors.ROUTE_NOT_FOUND) != nil { + if _, err := c.dpdk.DeleteRoute( + ctx, + vni, + route.Spec.Prefix, + dpdkerrors.Ignore(dpdkerrors.NO_VNI, dpdkerrors.ROUTE_NOT_FOUND), + ); err != nil { return fmt.Errorf("error deleting route: %w", err) } } diff --git a/go.mod b/go.mod index 0e66250..24bbd4f 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/jaypipes/ghw v0.12.0 github.com/onmetal/controller-utils v0.7.0 github.com/onmetal/metalbond v0.3.2 - github.com/onmetal/net-dpservice-go v0.1.16 + github.com/onmetal/net-dpservice-go v0.1.18 github.com/onmetal/onmetal-api v0.1.1 github.com/onsi/ginkgo/v2 v2.11.0 github.com/onsi/gomega v1.27.10 diff --git a/go.sum b/go.sum index c841b2d..0c241a0 100644 --- a/go.sum +++ b/go.sum @@ -237,10 +237,8 @@ github.com/onmetal/controller-utils v0.7.0 h1:EHLPb/XimNas1VkeZZLP4g31aSz+ipiwvw github.com/onmetal/controller-utils v0.7.0/go.mod h1:91KV/s0VaB8PC+hqsxo6OBsAhi3ICFgIFLv/36V0ng8= github.com/onmetal/metalbond v0.3.2 h1:nepZHUJqcDnjFq0LXHjcExXtRwa34P/BOY1i9HDhfwQ= github.com/onmetal/metalbond v0.3.2/go.mod h1:eAMo2+Ph4nQo1RJSV8813Hoafwpdk8E/uZAHhAXbIkg= -github.com/onmetal/net-dpservice-go v0.1.16-0.20230802071336-f93fbd271e1d h1:fqyhdP8KXluENyoq5sKoiqs/OMyxH6nr1gBDQRtpeNQ= -github.com/onmetal/net-dpservice-go v0.1.16-0.20230802071336-f93fbd271e1d/go.mod h1:M7dg98Xx54qZqWMCWS5LUra3z0x459Pg4/l3F5He4Jk= -github.com/onmetal/net-dpservice-go v0.1.16 h1:Bkq6o7xv439p85tbD0nD62wshrPRUX30unxd8he7LSw= -github.com/onmetal/net-dpservice-go v0.1.16/go.mod h1:M7dg98Xx54qZqWMCWS5LUra3z0x459Pg4/l3F5He4Jk= +github.com/onmetal/net-dpservice-go v0.1.18 h1:c4yFXzSa6i3L1JQHH18fmUv2S+mSL/guFNSGt65s2Yc= +github.com/onmetal/net-dpservice-go v0.1.18/go.mod h1:M7dg98Xx54qZqWMCWS5LUra3z0x459Pg4/l3F5He4Jk= github.com/onmetal/onmetal-api v0.1.1 h1:8YEtQBsxQzb+MKvbFypuYp/x8AZ96mN4NCx8bRxHvFA= github.com/onmetal/onmetal-api v0.1.1/go.mod h1:mql3gEgyCDeqkQbeM62C/FRuCwXSfBVsvg/FiBczN6M= github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU=