Skip to content

Commit 347acbe

Browse files
fix(controller): move a ModelConfig condition's transition time only on a status change (#3340)
## Problem The ModelConfig status writer moves a condition's `lastTransitionTime` whenever its reason, message or observedGeneration changes. Agent conditions, and SandboxTemplate through `apimeta.SetStatusCondition`, move it only when the status changes, as the API conventions define it. A ModelConfig that stays `False` therefore reports a new transition time every time its error text or generation changes. ## Change Agent and ModelConfig share one helper that keeps the transition time while a condition's status holds. A new test covers a changed reason, message and generation under an unchanged status, and a status change. This PR previously wrote Harness `Ready`/`Booted` conditions; #3454 removed `Harness.status`, so it is reduced to the transition-time rule that part shared with Agent and ModelConfig. Signed-off-by: QuentinBisson <[email protected]>
1 parent 2114654 commit 347acbe

2 files changed

Lines changed: 32 additions & 16 deletions

File tree

‎go/core/internal/controller/reconciler.go‎

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -540,26 +540,24 @@ func (r *Reconciler) reconcileModelConfigStatus(ctx context.Context, key string)
540540
}
541541

542542
func statusWithTransitionTimes(desired, current kagentv1alpha3.AgentStatus) kagentv1alpha3.AgentStatus {
543-
desired.Conditions = append([]metav1.Condition(nil), desired.Conditions...)
544-
for i := range desired.Conditions {
545-
condition := &desired.Conditions[i]
546-
previous := apimeta.FindStatusCondition(current.Conditions, condition.Type)
547-
if previous != nil && previous.Status == condition.Status {
548-
condition.LastTransitionTime = previous.LastTransitionTime
549-
} else {
550-
condition.LastTransitionTime = metav1.Now()
551-
}
552-
}
543+
desired.Conditions = conditionsWithTransitionTimes(desired.Conditions, current.Conditions)
553544
return desired
554545
}
555546

556547
func modelConfigStatusWithTransitionTimes(desired, current kagentv1alpha3.ModelConfigStatus) kagentv1alpha3.ModelConfigStatus {
557-
desired.Conditions = append([]metav1.Condition(nil), desired.Conditions...)
558-
for conditionIndex := range desired.Conditions {
559-
condition := &desired.Conditions[conditionIndex]
560-
if previous := apimeta.FindStatusCondition(current.Conditions, condition.Type); previous != nil &&
561-
previous.Status == condition.Status && previous.Reason == condition.Reason &&
562-
previous.Message == condition.Message && previous.ObservedGeneration == condition.ObservedGeneration {
548+
desired.Conditions = conditionsWithTransitionTimes(desired.Conditions, current.Conditions)
549+
return desired
550+
}
551+
552+
// conditionsWithTransitionTimes keeps the transition time a condition's
553+
// status holds and stamps the current time when the status changes, as
554+
// apimeta.SetStatusCondition does; a new reason or message alone is no
555+
// transition.
556+
func conditionsWithTransitionTimes(desired, current []metav1.Condition) []metav1.Condition {
557+
desired = append([]metav1.Condition(nil), desired...)
558+
for conditionIndex := range desired {
559+
condition := &desired[conditionIndex]
560+
if previous := apimeta.FindStatusCondition(current, condition.Type); previous != nil && previous.Status == condition.Status {
563561
condition.LastTransitionTime = previous.LastTransitionTime
564562
continue
565563
}

‎go/core/internal/controller/reconciler_test.go‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,3 +613,21 @@ func reconciliationTestCard(name string) *a2apb.AgentCard {
613613
SupportedInterfaces: []*a2apb.AgentInterface{{Url: "http://127.0.0.1:80", ProtocolBinding: "GRPC", ProtocolVersion: "1.0"}},
614614
}
615615
}
616+
617+
func TestModelConfigConditionTransitionTimesMoveOnlyOnStatusChange(t *testing.T) {
618+
then := metav1.NewTime(time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC))
619+
current := kagentv1alpha3.ModelConfigStatus{Conditions: []metav1.Condition{
620+
{Type: "Accepted", Status: metav1.ConditionFalse, Reason: "SecretNotFound", Message: "secret team-a/a not found", ObservedGeneration: 1, LastTransitionTime: then},
621+
{Type: "Ready", Status: metav1.ConditionTrue, Reason: "Resolved", ObservedGeneration: 1, LastTransitionTime: then},
622+
}}
623+
desired := kagentv1alpha3.ModelConfigStatus{Conditions: []metav1.Condition{
624+
{Type: "Accepted", Status: metav1.ConditionFalse, Reason: "SecretKeyNotFound", Message: "key missing in secret team-a/b", ObservedGeneration: 2},
625+
{Type: "Ready", Status: metav1.ConditionFalse, Reason: "Unresolved", ObservedGeneration: 2},
626+
}}
627+
628+
got := modelConfigStatusWithTransitionTimes(desired, current)
629+
630+
require.Equal(t, then, got.Conditions[0].LastTransitionTime, "a new reason, message or generation alone is no transition")
631+
require.True(t, got.Conditions[1].LastTransitionTime.After(then.Time), "a status change stamps a new transition time")
632+
require.True(t, desired.Conditions[0].LastTransitionTime.IsZero(), "the desired conditions are not mutated")
633+
}

0 commit comments

Comments
 (0)