From cb76628bb5dbd693b57a589a9935c610dd1dd649 Mon Sep 17 00:00:00 2001 From: YachikaRalhan Date: Fri, 22 Sep 2023 18:51:18 +0530 Subject: [PATCH] fix(): fixed test cases Signed-off-by: YachikaRalhan --- .../controllers/vpnkeyrotation/reconciler.go | 8 ++++---- .../vpnkeyrotation/vpnrotation_ctrl_test.go | 5 ++++- .../vpnkeyrotation/vpnrotation_suite_test.go | 18 +++++++++++------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/pkg/hub/controllers/vpnkeyrotation/reconciler.go b/pkg/hub/controllers/vpnkeyrotation/reconciler.go index d2469b043..701e7f5d3 100644 --- a/pkg/hub/controllers/vpnkeyrotation/reconciler.go +++ b/pkg/hub/controllers/vpnkeyrotation/reconciler.go @@ -412,9 +412,7 @@ func (r *Reconciler) syncCurrentRotationState(ctx context.Context, } } if len(syncedRotationState) != len(vpnKeyRotation.Status.CurrentRotationState) || len(keysToDeleteFromStatus) > 0 { - log.Info("syncing current rotation state for the gateways", - "from", vpnKeyRotation.Status.CurrentRotationState, - "to", syncedRotationState) + // Merge the new syncedRotationState with the existing state for gw, obj := range syncedRotationState { currentRotationState[gw] = obj @@ -425,7 +423,9 @@ func (r *Reconciler) syncCurrentRotationState(ctx context.Context, delete(currentRotationState, key) } } - + log.Info("syncing current rotation state for the gateways", + "from", vpnKeyRotation.Status.CurrentRotationState, + "to", currentRotationState) vpnKeyRotation.Status.CurrentRotationState = currentRotationState requeue = true return r.Status().Update(ctx, vpnKeyRotation) diff --git a/pkg/hub/controllers/vpnkeyrotation/vpnrotation_ctrl_test.go b/pkg/hub/controllers/vpnkeyrotation/vpnrotation_ctrl_test.go index 5887882be..febd85290 100644 --- a/pkg/hub/controllers/vpnkeyrotation/vpnrotation_ctrl_test.go +++ b/pkg/hub/controllers/vpnkeyrotation/vpnrotation_ctrl_test.go @@ -75,7 +75,7 @@ var _ = Describe("Hub VPN Key Rotation", func() { ClusterGatewayMapping: map[string][]string{ CLUSTER_NAME: {gws[0]}, }, - Clusters: []string{"worker-1"}, + Clusters: []string{ClusterName}, CertificateCreationTime: &metav1.Time{Time: time.Now()}, }, } @@ -178,6 +178,7 @@ var _ = Describe("Hub VPN Key Rotation", func() { ClusterGatewayMapping: map[string][]string{ CLUSTER_NAME: gws, }, + Clusters: []string{ClusterName}, CertificateCreationTime: &metav1.Time{Time: time.Now()}, CertificateExpiryTime: &metav1.Time{Time: time.Now().AddDate(0, 0, 30)}, RotationInterval: 30, @@ -516,6 +517,7 @@ var _ = Describe("Hub VPN Key Rotation", func() { ClusterGatewayMapping: map[string][]string{ CLUSTER_NAME: {gws[0]}, }, + Clusters: []string{ClusterName}, CertificateCreationTime: &metav1.Time{Time: time.Now()}, CertificateExpiryTime: &metav1.Time{Time: time.Now().AddDate(0, 0, 30)}, RotationInterval: 30, @@ -743,6 +745,7 @@ var _ = Describe("Hub VPN Key Rotation", func() { ClusterGatewayMapping: map[string][]string{ "worker-1": gws, }, + Clusters: []string{ClusterName}, CertificateCreationTime: &metav1.Time{Time: time.Now()}, }, } diff --git a/pkg/hub/controllers/vpnkeyrotation/vpnrotation_suite_test.go b/pkg/hub/controllers/vpnkeyrotation/vpnrotation_suite_test.go index de8198ece..987030fc3 100644 --- a/pkg/hub/controllers/vpnkeyrotation/vpnrotation_suite_test.go +++ b/pkg/hub/controllers/vpnkeyrotation/vpnrotation_suite_test.go @@ -154,13 +154,7 @@ var _ = BeforeSuite(func() { ControllerManagedBy(k8sManager). For(&hubv1alpha1.VpnKeyRotation{}). WithEventFilter(predicate.NewPredicateFuncs(func(object client.Object) bool { - vpn := object.(*hubv1alpha1.VpnKeyRotation) - for _, v := range vpn.Spec.Clusters { - if v == CLUSTER_NAME { - return true - } - } - return false + return shouldProcessVpnKeyRotation(object) })). Complete(rotationReconciler) if err != nil { @@ -213,3 +207,13 @@ var _ = AfterSuite(func() { err := testEnv.Stop() Expect(err).NotTo(HaveOccurred()) }) + +func shouldProcessVpnKeyRotation(object client.Object) bool { + vpn := object.(*hubv1alpha1.VpnKeyRotation) + for _, v := range vpn.Spec.Clusters { + if v == ClusterName { + return true + } + } + return false +}