Skip to content

Commit

Permalink
Modify LastUpdateTime when the Sealed Secrets is being updated
Browse files Browse the repository at this point in the history
This PR modify the way that we are setting up the LastUpdateTime.
We are going to modify the LastUpdateTime always that we are updating
the Sealed Secrets and the LastTransitionTime only when the status has
changed.

Integration tests included.

Signed-off-by: Alvaro Neira Ayuso <alvaro.neira@broadcom.com>
  • Loading branch information
alvneiayu committed Feb 29, 2024
1 parent 5fd7424 commit 732d011
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
15 changes: 15 additions & 0 deletions integration/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ func getSecretImmutable(s *v1.Secret) bool {
return *s.Immutable
}

func compareLastTimes(ss *ssv1alpha1.SealedSecret) bool {
for i := range ss.Status.Conditions {
if ss.Status.Conditions[i].Type == ssv1alpha1.SealedSecretSynced {
return ss.Status.Conditions[i].LastTransitionTime == ss.Status.Conditions[i].LastUpdateTime
}
}
return false
}

func fetchKeys(ctx context.Context, c corev1.SecretsGetter) (map[string]*rsa.PrivateKey, []*x509.Certificate, error) {
list, err := c.Secrets(*controllerNs).List(ctx, metav1.ListOptions{
LabelSelector: keySelector,
Expand Down Expand Up @@ -207,6 +216,9 @@ var _ = Describe("create", func() {
Eventually(func() (*ssv1alpha1.SealedSecret, error) {
return ssc.BitnamiV1alpha1().SealedSecrets(ns).Get(context.Background(), secretName, metav1.GetOptions{})
}, Timeout, PollingInterval).ShouldNot(WithTransform(getStatus, BeNil()))
Eventually(func() (*ssv1alpha1.SealedSecret, error) {
return ssc.BitnamiV1alpha1().SealedSecrets(ns).Get(context.Background(), secretName, metav1.GetOptions{})
}, Timeout, PollingInterval).Should(WithTransform(compareLastTimes, Equal(true)))
Eventually(func() (*v1.EventList, error) {
return c.Events(ns).Search(scheme.Scheme, ss)
}, Timeout, PollingInterval).Should(
Expand Down Expand Up @@ -251,6 +263,9 @@ var _ = Describe("create", func() {
Eventually(func() (*ssv1alpha1.SealedSecret, error) {
return ssc.BitnamiV1alpha1().SealedSecrets(ns).Get(context.Background(), secretName, metav1.GetOptions{})
}, Timeout, PollingInterval).Should(WithTransform(getObservedGeneration, Equal(int64(2))))
Eventually(func() (*ssv1alpha1.SealedSecret, error) {
return ssc.BitnamiV1alpha1().SealedSecrets(ns).Get(context.Background(), secretName, metav1.GetOptions{})
}, Timeout, PollingInterval).Should(WithTransform(compareLastTimes, Equal(false)))
})
})

Expand Down
8 changes: 2 additions & 6 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,11 @@ func updateSealedSecretsStatusConditions(st *ssv1alpha1.SealedSecretStatus, unse
cond.Message = unsealError.Error()
}

cond.LastUpdateTime = metav1.Now()
// Status has changed, update the transition time and signal that an update is required
if cond.Status != status {
if !cond.LastUpdateTime.IsZero() {
cond.LastTransitionTime = cond.LastUpdateTime
} else {
cond.LastTransitionTime = metav1.Now()
}
cond.LastTransitionTime = cond.LastUpdateTime
cond.Status = status
cond.LastUpdateTime = metav1.Now()
updateRequired = true
}

Expand Down

0 comments on commit 732d011

Please sign in to comment.