Skip to content

Commit

Permalink
chore: ensure the observedGeneration and phase of the component remai…
Browse files Browse the repository at this point in the history
…n consistent (#8494)
  • Loading branch information
leon-inf authored Nov 22, 2024
1 parent e5893a4 commit 25360ba
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions controllers/apps/transformer_component_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 25360ba

Please sign in to comment.