From 5bc62d56b103c7a761bbf47c0cfbaec653b43322 Mon Sep 17 00:00:00 2001 From: "mingzhou.swx" Date: Mon, 8 May 2023 15:22:26 +0800 Subject: [PATCH] add pre-normal hook for asts Signed-off-by: mingzhou.swx --- .../statefulset/stateful_set_control.go | 22 +++++++++++-------- .../statefulset/stateful_set_utils.go | 3 +++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/pkg/controller/statefulset/stateful_set_control.go b/pkg/controller/statefulset/stateful_set_control.go index 426af6bff8..f1d766b353 100644 --- a/pkg/controller/statefulset/stateful_set_control.go +++ b/pkg/controller/statefulset/stateful_set_control.go @@ -527,7 +527,7 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet( } } - lifecycle.SetPodLifecycle(appspub.LifecycleStateNormal)(replicas[i]) + lifecycle.SetPodLifecycle(appspub.LifecycleStatePreparingNormal)(replicas[i]) if err := ssc.podControl.CreateStatefulPod(set, replicas[i]); err != nil { msg := fmt.Sprintf("StatefulPodControl failed to create Pod error: %s", err) condition := NewStatefulsetCondition(appsv1beta1.FailedCreatePod, v1.ConditionTrue, "", msg) @@ -572,13 +572,11 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet( replicas[i].Name) break } - // Update InPlaceUpdateReady condition for pod - if res := ssc.inplaceControl.Refresh(replicas[i], nil); res.RefreshErr != nil { - klog.Errorf("StatefulSet %s/%s failed to update pod %s condition for inplace: %v", - set.Namespace, set.Name, replicas[i].Name, res.RefreshErr) - return &status, res.RefreshErr - } else if res.DelayDuration > 0 { - durationStore.Push(getStatefulSetKey(set), res.DelayDuration) + modified, duration, err := ssc.refreshPodState(set, replicas[i], updateRevision.Name) + if err != nil || modified { + return &status, err + } else if duration > 0 { + durationStore.Push(getStatefulSetKey(set), duration) } // If we have a Pod that has been created but is not running and available we can not make progress. // We must ensure that all for each Pod, when we create it, all of its predecessors, with respect to its @@ -857,6 +855,12 @@ func (ssc *defaultStatefulSetControl) refreshPodState(set *appsv1beta1.StatefulS var state appspub.LifecycleStateType switch lifecycle.GetPodLifecycleState(pod) { + case appspub.LifecycleStatePreparingNormal: + if set.Spec.Lifecycle == nil || + set.Spec.Lifecycle.PreNormal == nil || + lifecycle.IsPodHooked(set.Spec.Lifecycle.PreNormal, pod) { + state = appspub.LifecycleStateNormal + } case appspub.LifecycleStatePreparingUpdate: // when pod updated to PreparingUpdate state to wait lifecycle blocker to remove, // then rollback, do not need update pod inplace since it is the update revision, @@ -929,7 +933,7 @@ func (ssc *defaultStatefulSetControl) inPlaceUpdatePod( if ssc.inplaceControl.CanUpdateInPlace(oldRevision, updateRevision, opts) { state := lifecycle.GetPodLifecycleState(pod) switch state { - case "", appspub.LifecycleStateNormal: + case "", appspub.LifecycleStatePreparingNormal, appspub.LifecycleStateNormal: var err error var updated bool if set.Spec.Lifecycle != nil && lifecycle.IsPodHooked(set.Spec.Lifecycle.InPlaceUpdate, pod) { diff --git a/pkg/controller/statefulset/stateful_set_utils.go b/pkg/controller/statefulset/stateful_set_utils.go index d8ea3d97c8..b27e9987f1 100644 --- a/pkg/controller/statefulset/stateful_set_utils.go +++ b/pkg/controller/statefulset/stateful_set_utils.go @@ -365,6 +365,9 @@ func updateIdentity(set *appsv1beta1.StatefulSet, pod *v1.Pod) { // return false with zero means it's not ready // return false with a positive value means it's not available and should recheck with that time func isRunningAndAvailable(pod *v1.Pod, minReadySeconds int32) (bool, time.Duration) { + if lifecycle.GetPodLifecycleState(pod) != appspub.LifecycleStateNormal { + return false, 0 + } if pod.Status.Phase != v1.PodRunning || !podutil.IsPodReady(pod) { return false, 0 }