Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preNormal hook for Advanced StatefulSet #1277

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions pkg/controller/statefulset/stateful_set_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
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 @@ -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
}
Expand Down