Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up LastTransitionTime in case that it is empty #1370

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,11 @@ 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
} else {
cond.LastTransitionTime = metav1.Now()
}
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