Skip to content

Commit

Permalink
Set up LastTransitionTime in case that it is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
alvneiayu committed Nov 10, 2023
1 parent 5b0c26e commit 7fc38b1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,9 @@ func updateSealedSecretsStatusConditions(st *ssv1alpha1.SealedSecretStatus, unse

// Status has changed, update the transition time and signal that an update is required
if cond.Status != status {
cond.LastTransitionTime = cond.LastUpdateTime
if !cond.LastUpdateTime.IsZero() {
cond.LastTransitionTime = cond.LastUpdateTime
}
cond.Status = status
cond.LastUpdateTime = metav1.Now()
updateRequired = true
Expand Down
18 changes: 14 additions & 4 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,26 @@ func TestEmptyStatusSendsUpdate(t *testing.T) {
}

func TestStatusUpdateSendsUpdate(t *testing.T) {
updateRequired := updateSealedSecretsStatusConditions(&ssv1alpha1.SealedSecretStatus{
status := &ssv1alpha1.SealedSecretStatus{
Conditions: []ssv1alpha1.SealedSecretCondition{{
Status: "False",
Type: ssv1alpha1.SealedSecretSynced,
Status: "False",
Type: ssv1alpha1.SealedSecretSynced,
LastUpdateTime: metav1.Now(),
}},
}, nil)
}
updateRequired := updateSealedSecretsStatusConditions(status, nil)

if !updateRequired {
t.Fatalf("expected status update, but no update was send")
}

if status.Conditions[0].LastTransitionTime.IsZero() {
t.Fatalf("expected LastTransitionTime is not empty")
}

if status.Conditions[0].LastUpdateTime.IsZero() {
t.Fatalf("expected LastUpdateTime is not empty")
}
}

func TestSameStatusNoUpdate(t *testing.T) {
Expand Down

0 comments on commit 7fc38b1

Please sign in to comment.