Skip to content

Commit

Permalink
add pre-normal hook for asts
Browse files Browse the repository at this point in the history
Signed-off-by: mingzhou.swx <mingzhou.swx@alibaba-inc.com>
  • Loading branch information
mingzhou.swx authored and furykerry committed Dec 25, 2024
1 parent d25416f commit b9da21a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
21 changes: 14 additions & 7 deletions pkg/controller/statefulset/stateful_set_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,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,
Expand Down Expand Up @@ -859,7 +865,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) {
Expand Down Expand Up @@ -1112,7 +1118,7 @@ func (ssc *defaultStatefulSetControl) processReplica(
return true, false, err
}
}
lifecycle.SetPodLifecycle(appspub.LifecycleStateNormal)(replicas[i])
lifecycle.SetPodLifecycle(appspub.LifecycleStatePreparingNormal)(replicas[i])
if err := ssc.podControl.CreateStatefulPod(ctx, set, replicas[i]); err != nil {
msg := fmt.Sprintf("StatefulPodControl failed to create Pod error: %s", err)
condition := NewStatefulsetCondition(appsv1beta1.FailedCreatePod, v1.ConditionTrue, "", msg)
Expand Down Expand Up @@ -1156,12 +1162,13 @@ func (ssc *defaultStatefulSetControl) processReplica(
}

// Update InPlaceUpdateReady condition for pod
if res := ssc.inplaceControl.Refresh(replicas[i], nil); res.RefreshErr != nil {
logger.Error(res.RefreshErr, "StatefulSet failed to update pod condition for inplace",
modified, duration, err := ssc.refreshPodState(set, replicas[i], status.UpdateRevision)
if err != nil || modified {
logger.Error(err, "StatefulSet failed to update pod condition for inplace",
"statefulSet", klog.KObj(set), "pod", klog.KObj(replicas[i]))
return true, false, res.RefreshErr
} else if res.DelayDuration > 0 {
durationStore.Push(getStatefulSetKey(set), res.DelayDuration)
return true, false, 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.
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/statefulset/stateful_set_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,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
}
Expand Down

0 comments on commit b9da21a

Please sign in to comment.