From b0b74d610a39cf6fd79b3e4ff14e4d3b2c007a22 Mon Sep 17 00:00:00 2001 From: Kajol Asabe Date: Mon, 23 Sep 2024 13:17:06 +0530 Subject: [PATCH] use equality.semantics.DeepEqual() wherever possible --- apinetlet/controllers/network_controller.go | 10 ++++++---- metalnetlet/controllers/network_controller.go | 8 ++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/apinetlet/controllers/network_controller.go b/apinetlet/controllers/network_controller.go index 5135057..aa5f810 100644 --- a/apinetlet/controllers/network_controller.go +++ b/apinetlet/controllers/network_controller.go @@ -12,6 +12,7 @@ import ( "github.com/go-logr/logr" apinetv1alpha1 "github.com/ironcore-dev/ironcore-net/api/core/v1alpha1" + "github.com/ironcore-dev/ironcore-net/apimachinery/equality" apinetletclient "github.com/ironcore-dev/ironcore-net/apinetlet/client" "github.com/ironcore-dev/ironcore-net/apinetlet/handler" "github.com/ironcore-dev/ironcore-net/apinetlet/provider" @@ -116,7 +117,7 @@ func (r *NetworkReconciler) delete(ctx context.Context, log logr.Logger, network } log.V(1).Info("Target APINet network is not yet gone, requeueing") - return ctrl.Result{}, nil + return ctrl.Result{Requeue: true}, nil } func (r *NetworkReconciler) updateNetworkStatus(ctx context.Context, log logr.Logger, network *networkingv1alpha1.Network, apiNetNetwork *apinetv1alpha1.Network, state networkingv1alpha1.NetworkState) error { @@ -144,7 +145,7 @@ func (r *NetworkReconciler) reconcile(ctx context.Context, log logr.Logger, netw } if modified { log.V(1).Info("Added finalizer, requeueing") - return ctrl.Result{}, nil + return ctrl.Result{Requeue: true}, nil } apiNetNetwork, err := r.applyAPINetNetwork(ctx, log, network) @@ -166,7 +167,7 @@ func (r *NetworkReconciler) reconcile(ctx context.Context, log logr.Logger, netw } log.V(1).Info("Set network provider id, requeueing") - return ctrl.Result{}, nil + return ctrl.Result{Requeue: true}, nil } log.V(1).Info("Updating network status") @@ -214,6 +215,7 @@ func (r *NetworkReconciler) applyAPINetNetwork(ctx context.Context, log logr.Log } } } else { + log.V(1).Info("APINet network already exists") isNetworkExist = true } @@ -250,7 +252,7 @@ func (r *NetworkReconciler) applyAPINetNetwork(ctx context.Context, log logr.Log log.V(1).Info("APINet network spec peerings", "old", apiNetNetwork.Spec.Peerings, "new", peerings) log.V(1).Info("APINet network status", "old", apiNetNetwork.Status.Peerings) - isPeeringsEqual := reflect.DeepEqual(apiNetNetwork.Spec.Peerings, peerings) + isPeeringsEqual := equality.Semantic.DeepEqual(apiNetNetwork.Spec.Peerings, peerings) if !isNetworkExist || !isPeeringsEqual { log.V(1).Info("Applying APINet network") diff --git a/metalnetlet/controllers/network_controller.go b/metalnetlet/controllers/network_controller.go index 27b9b3a..d4a6120 100644 --- a/metalnetlet/controllers/network_controller.go +++ b/metalnetlet/controllers/network_controller.go @@ -7,12 +7,12 @@ import ( "context" "fmt" "reflect" - "slices" "github.com/go-logr/logr" "github.com/ironcore-dev/controller-utils/clientutils" apinetv1alpha1 "github.com/ironcore-dev/ironcore-net/api/core/v1alpha1" "github.com/ironcore-dev/ironcore-net/apimachinery/api/net" + "github.com/ironcore-dev/ironcore-net/apimachinery/equality" metalnetletclient "github.com/ironcore-dev/ironcore-net/metalnetlet/client" metalnetlethandler "github.com/ironcore-dev/ironcore-net/metalnetlet/handler" "github.com/ironcore-dev/ironcore-net/networkid" @@ -116,7 +116,7 @@ func (r *NetworkReconciler) delete(ctx context.Context, log logr.Logger, network func (r *NetworkReconciler) updateApinetNetworkStatus(ctx context.Context, log logr.Logger, network *apinetv1alpha1.Network, metalnetNetwork *metalnetv1alpha1.Network) error { newStatusPeerings := metalnetNetworkPeeringsStatusToNetworkPeeringsStatus(metalnetNetwork.Status.Peerings) log.V(1).Info("apinet status", "old", network.Status.Peerings, "new", newStatusPeerings) - if !slices.Equal(network.Status.Peerings, newStatusPeerings) { + if !equality.Semantic.DeepEqual(network.Status.Peerings, newStatusPeerings) { log.V(1).Info("Patching apinet network status", "status", newStatusPeerings) networkBase := network.DeepCopy() network.Status.Peerings = newStatusPeerings @@ -144,7 +144,7 @@ func (r *NetworkReconciler) reconcile(ctx context.Context, log logr.Logger, netw } if modified { log.V(1).Info("Added finalizer") - return ctrl.Result{}, nil + return ctrl.Result{Requeue: true}, nil } log.V(1).Info("Finalizer is present") @@ -195,7 +195,7 @@ func (r *NetworkReconciler) reconcile(ctx context.Context, log logr.Logger, netw } } // metalnetNetwork.Spec.PeeredPrefixes = peeredPrefixes - isPeeredIDsEqual := slices.Equal(metalnetNetwork.Spec.PeeredIDs, peeredIDs) + isPeeredIDsEqual := equality.Semantic.DeepEqual(metalnetNetwork.Spec.PeeredIDs, peeredIDs) isPeeredPrefixesEqual := reflect.DeepEqual(metalnetNetwork.Spec.PeeredPrefixes, peeredPrefixes) log.V(1).Info("Peered IDs", "old", metalnetNetwork.Spec.PeeredIDs, "new", peeredIDs)