From 668201a339ea517345a50c15a9d33fe74fff059a Mon Sep 17 00:00:00 2001 From: Valeriy Khorunzhin Date: Thu, 28 Nov 2024 20:44:28 +0300 Subject: [PATCH] fix(api): do not update condition transition time if status not changed (#544) Do not update condition last transition time if status not changed. --------- Signed-off-by: Valeriy Khorunzhin --- .../pkg/controller/conditions/builder.go | 1 - .../pkg/controller/conditions/manager.go | 19 +++++-------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/images/virtualization-artifact/pkg/controller/conditions/builder.go b/images/virtualization-artifact/pkg/controller/conditions/builder.go index 500833f29..ea23639b8 100644 --- a/images/virtualization-artifact/pkg/controller/conditions/builder.go +++ b/images/virtualization-artifact/pkg/controller/conditions/builder.go @@ -70,7 +70,6 @@ func (c *ConditionBuilder) Condition() metav1.Condition { Type: c.conditionType.String(), Status: c.status, Reason: c.reason, - LastTransitionTime: metav1.Now(), Message: c.message, ObservedGeneration: c.generation, } diff --git a/images/virtualization-artifact/pkg/controller/conditions/manager.go b/images/virtualization-artifact/pkg/controller/conditions/manager.go index 3fa04b85a..66b5d576d 100644 --- a/images/virtualization-artifact/pkg/controller/conditions/manager.go +++ b/images/virtualization-artifact/pkg/controller/conditions/manager.go @@ -25,31 +25,22 @@ import ( // Deprecated: use direct SetCondition instead. type Manager struct { - conds []metav1.Condition - indexConds map[string]int + conds []metav1.Condition } // Deprecated: use direct SetCondition instead. func NewManager(conditions []metav1.Condition) *Manager { - conds := make([]metav1.Condition, len(conditions)) - indexConds := make(map[string]int, len(conds)) - for i, c := range conditions { - conds[i] = c - indexConds[c.Type] = i - } return &Manager{ - conds: conds, - indexConds: indexConds, + conds: slices.Clone(conditions), } } func (m *Manager) Add(c metav1.Condition) (addedCondition bool) { - if _, found := m.indexConds[c.Type]; found { + findCond := meta.FindStatusCondition(m.conds, c.Type) + if findCond != nil { return false } - m.conds = append(m.conds, c) - m.indexConds[c.Type] = len(m.conds) - 1 - return true + return meta.SetStatusCondition(&m.conds, c) } func (m *Manager) Update(c metav1.Condition) {