Skip to content

Commit

Permalink
fix(): fixed test cases
Browse files Browse the repository at this point in the history
Signed-off-by: YachikaRalhan <[email protected]>
  • Loading branch information
YachikaRalhan committed Sep 22, 2023
1 parent 7dfa137 commit 165dd01
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
8 changes: 4 additions & 4 deletions pkg/hub/controllers/vpnkeyrotation/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion pkg/hub/controllers/vpnkeyrotation/vpnrotation_ctrl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()},
},
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()},
},
}
Expand Down
18 changes: 11 additions & 7 deletions pkg/hub/controllers/vpnkeyrotation/vpnrotation_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

0 comments on commit 165dd01

Please sign in to comment.