Skip to content

Commit e5a59d5

Browse files
authored
Modify LastUpdateTime when the Sealed Secrets is being updated (#1475)
**Description of the change** 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. **Benefits** LastUpdateTime is working properly **Applicable issues** <!-- Enter any applicable Issues here (You can reference an issue using #) --> - fixes #1470 Signed-off-by: Alvaro Neira Ayuso <[email protected]>
1 parent 5fd7424 commit e5a59d5

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

integration/controller_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ func getSecretImmutable(s *v1.Secret) bool {
7777
return *s.Immutable
7878
}
7979

80+
func compareLastTimes(ss *ssv1alpha1.SealedSecret) bool {
81+
for i := range ss.Status.Conditions {
82+
if ss.Status.Conditions[i].Type == ssv1alpha1.SealedSecretSynced {
83+
return ss.Status.Conditions[i].LastTransitionTime == ss.Status.Conditions[i].LastUpdateTime
84+
}
85+
}
86+
return false
87+
}
88+
8089
func fetchKeys(ctx context.Context, c corev1.SecretsGetter) (map[string]*rsa.PrivateKey, []*x509.Certificate, error) {
8190
list, err := c.Secrets(*controllerNs).List(ctx, metav1.ListOptions{
8291
LabelSelector: keySelector,
@@ -207,6 +216,9 @@ var _ = Describe("create", func() {
207216
Eventually(func() (*ssv1alpha1.SealedSecret, error) {
208217
return ssc.BitnamiV1alpha1().SealedSecrets(ns).Get(context.Background(), secretName, metav1.GetOptions{})
209218
}, Timeout, PollingInterval).ShouldNot(WithTransform(getStatus, BeNil()))
219+
Eventually(func() (*ssv1alpha1.SealedSecret, error) {
220+
return ssc.BitnamiV1alpha1().SealedSecrets(ns).Get(context.Background(), secretName, metav1.GetOptions{})
221+
}, Timeout, PollingInterval).Should(WithTransform(compareLastTimes, Equal(true)))
210222
Eventually(func() (*v1.EventList, error) {
211223
return c.Events(ns).Search(scheme.Scheme, ss)
212224
}, Timeout, PollingInterval).Should(
@@ -233,6 +245,7 @@ var _ = Describe("create", func() {
233245
Expect(err).NotTo(HaveOccurred())
234246
ss.ResourceVersion = resVer
235247

248+
time.Sleep(1 * time.Second)
236249
fmt.Fprintf(GinkgoWriter, "Updating to SealedSecret: %#v\n", ss)
237250
ss, err = ssc.BitnamiV1alpha1().SealedSecrets(ss.Namespace).Update(context.Background(), ss, metav1.UpdateOptions{})
238251
Expect(err).NotTo(HaveOccurred())
@@ -251,6 +264,9 @@ var _ = Describe("create", func() {
251264
Eventually(func() (*ssv1alpha1.SealedSecret, error) {
252265
return ssc.BitnamiV1alpha1().SealedSecrets(ns).Get(context.Background(), secretName, metav1.GetOptions{})
253266
}, Timeout, PollingInterval).Should(WithTransform(getObservedGeneration, Equal(int64(2))))
267+
Eventually(func() (*ssv1alpha1.SealedSecret, error) {
268+
return ssc.BitnamiV1alpha1().SealedSecrets(ns).Get(context.Background(), secretName, metav1.GetOptions{})
269+
}, Timeout, PollingInterval).Should(WithTransform(compareLastTimes, Equal(false)))
254270
})
255271
})
256272

pkg/controller/controller.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -467,15 +467,11 @@ func updateSealedSecretsStatusConditions(st *ssv1alpha1.SealedSecretStatus, unse
467467
cond.Message = unsealError.Error()
468468
}
469469

470+
cond.LastUpdateTime = metav1.Now()
470471
// Status has changed, update the transition time and signal that an update is required
471472
if cond.Status != status {
472-
if !cond.LastUpdateTime.IsZero() {
473-
cond.LastTransitionTime = cond.LastUpdateTime
474-
} else {
475-
cond.LastTransitionTime = metav1.Now()
476-
}
473+
cond.LastTransitionTime = cond.LastUpdateTime
477474
cond.Status = status
478-
cond.LastUpdateTime = metav1.Now()
479475
updateRequired = true
480476
}
481477

0 commit comments

Comments
 (0)