Skip to content

Commit

Permalink
add test case for peering id removal and verify status update
Browse files Browse the repository at this point in the history
  • Loading branch information
ushabelgur committed Apr 26, 2024
1 parent 4da0420 commit d42d42c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
21 changes: 21 additions & 0 deletions controllers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,27 @@ var _ = Describe("Network Controller", Label("network"), Ordered, func() {
State: metalnetv1alpha1.NetworkPeeringStateReady,
}))))

By("Removing peeredIDs")
// Update the k8s network object
baseNetwork := network.DeepCopy()
network.Spec.PeeredIDs = []int32{}
Expect(k8sClient.Patch(ctx, network, client.MergeFrom(baseNetwork))).To(Succeed())

// Update the k8s network object
baseNetwork2 := network2.DeepCopy()
network2.Spec.PeeredIDs = []int32{}
Expect(k8sClient.Patch(ctx, network2, client.MergeFrom(baseNetwork2))).To(Succeed())

Expect(networkReconcile(ctx, *network)).To(Succeed())
Expect(networkReconcile(ctx, *network2)).To(Succeed())

By("Verifying peering information removed from status")
Eventually(Object(network)).Should(SatisfyAll(
HaveField("Status.Peerings", BeEmpty())))

Eventually(Object(network2)).Should(SatisfyAll(
HaveField("Status.Peerings", BeEmpty())))

// Deletes the k8s network object after spec is completed
DeferCleanup(func(ctx SpecContext) {
Expect(k8sClient.Delete(ctx, networkInterface)).To(Succeed())
Expand Down
8 changes: 4 additions & 4 deletions controllers/network_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,16 @@ func (r *NetworkReconciler) reconcilePeeredVNIs(ctx context.Context, log logr.Lo
continue
}
} else if peeredVniAvail.Spec.InUse && ownVniAvail {
if err := r.MetalnetMBClient.CleanupNotPeeredRoutes(vni); err != nil {
if err := r.MetalnetMBClient.CleanupNotPeeredRoutes(ctx, vni); err != nil {
errs = append(errs, err)
continue
}
if err := r.MetalnetMBClient.CleanupNotPeeredRoutes(peeredVNI); err != nil {
if err := r.MetalnetMBClient.CleanupNotPeeredRoutes(ctx, peeredVNI); err != nil {
errs = append(errs, err)
continue
}
} else {
if err := r.MetalnetMBClient.CleanupNotPeeredRoutes(vni); err != nil {
if err := r.MetalnetMBClient.CleanupNotPeeredRoutes(ctx, vni); err != nil {
errs = append(errs, err)
continue
}
Expand Down Expand Up @@ -452,7 +452,7 @@ func (r *NetworkReconciler) deletePeeredVNIs(ctx context.Context, log logr.Logge
return err
}
} else {
if err := r.MetalnetMBClient.CleanupNotPeeredRoutes(peeredVNI); err != nil {
if err := r.MetalnetMBClient.CleanupNotPeeredRoutes(ctx, peeredVNI); err != nil {
return err
}
}
Expand Down
4 changes: 1 addition & 3 deletions metalbond/metalbond_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,7 @@ func (c *MetalnetClient) RemoveRoute(vni mb.VNI, dest mb.Destination, hop mb.Nex
return nil
}

func (c *MetalnetClient) CleanupNotPeeredRoutes(vni uint32) error {
ctx := context.TODO()

func (c *MetalnetClient) CleanupNotPeeredRoutes(ctx context.Context, vni uint32) error {
routes, err := c.dpdk.ListRoutes(ctx, vni)
if err != nil {
return fmt.Errorf("error listing dpdk routes for vni %d: %w", vni, err)
Expand Down

0 comments on commit d42d42c

Please sign in to comment.