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

Change in handling of ignored errors #99

Merged
merged 6 commits into from
Sep 27, 2023
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
6 changes: 2 additions & 4 deletions controllers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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)))
})
Expand Down
6 changes: 5 additions & 1 deletion controllers/loadbalancer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
11 changes: 9 additions & 2 deletions controllers/network_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,22 @@ 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
}

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
Expand Down
39 changes: 33 additions & 6 deletions controllers/networkinterface_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
25 changes: 18 additions & 7 deletions dpdkmetalbond/dpdkmetalbond.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
Loading