From 25360ba2e5c4f871824816d4f593740eb4a4a7a1 Mon Sep 17 00:00:00 2001 From: Leon Date: Fri, 22 Nov 2024 12:06:02 +0800 Subject: [PATCH] chore: ensure the observedGeneration and phase of the component remain consistent (#8494) --- .../apps/transformer_component_status.go | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/controllers/apps/transformer_component_status.go b/controllers/apps/transformer_component_status.go index ea31b56d8d2..800567be441 100644 --- a/controllers/apps/transformer_component_status.go +++ b/controllers/apps/transformer_component_status.go @@ -82,14 +82,17 @@ func (t *componentStatusTransformer) Transform(ctx graph.TransformContext, dag * t.init(transCtx, dag) - switch { - case model.IsObjectUpdating(transCtx.ComponentOrig): - transCtx.Logger.Info(fmt.Sprintf("update status after applying new spec, generation: %d", comp.Generation)) - comp.Status.ObservedGeneration = comp.Generation - case model.IsObjectStatusUpdating(transCtx.ComponentOrig): - if err := t.reconcileStatus(transCtx); err != nil { + workloadGeneration, err := t.workloadGeneration() + if err != nil { + return err + } + if workloadGeneration == nil || *workloadGeneration >= comp.Status.ObservedGeneration { + if err = t.reconcileStatus(transCtx); err != nil { return err } + if workloadGeneration != nil { + comp.Status.ObservedGeneration = *workloadGeneration + } } graphCli, _ := transCtx.Client.(model.GraphClient) @@ -184,6 +187,21 @@ func (t *componentStatusTransformer) reconcileStatus(transCtx *componentTransfor return t.reconcileStatusCondition(transCtx) } +func (t *componentStatusTransformer) workloadGeneration() (*int64, error) { + if t.runningITS == nil { + return nil, nil + } + generation, ok := t.runningITS.GetAnnotations()[constant.KubeBlocksGenerationKey] + if !ok { + return nil, nil + } + val, err := strconv.ParseInt(generation, 10, 64) + if err != nil { + return nil, err + } + return &val, nil +} + func (t *componentStatusTransformer) isWorkloadUpdated() bool { if t.comp == nil || t.runningITS == nil { return false