Skip to content

Commit

Permalink
fix preparingupdate hang when rollback before update
Browse files Browse the repository at this point in the history
Signed-off-by: shiyan2016 <shiyan20160606@gmail.com>
  • Loading branch information
shiyan2016 committed Feb 7, 2023
1 parent bab1a31 commit d765df7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
15 changes: 13 additions & 2 deletions pkg/controller/cloneset/sync/cloneset_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (c *realControl) Update(cs *appsv1alpha1.CloneSet,
// 1. refresh states for all pods
var modified bool
for _, pod := range pods {
patchedState, duration, err := c.refreshPodState(cs, coreControl, pod)
patchedState, duration, err := c.refreshPodState(cs, coreControl, pod, updateRevision.Name)
if err != nil {
return err
} else if duration > 0 {
Expand Down Expand Up @@ -155,7 +155,7 @@ func (c *realControl) Update(cs *appsv1alpha1.CloneSet,
return nil
}

func (c *realControl) refreshPodState(cs *appsv1alpha1.CloneSet, coreControl clonesetcore.Control, pod *v1.Pod) (bool, time.Duration, error) {
func (c *realControl) refreshPodState(cs *appsv1alpha1.CloneSet, coreControl clonesetcore.Control, pod *v1.Pod, updateRevision string) (bool, time.Duration, error) {
opts := coreControl.GetUpdateOptions()
opts = inplaceupdate.SetOptionsDefaults(opts)

Expand All @@ -174,6 +174,17 @@ func (c *realControl) refreshPodState(cs *appsv1alpha1.CloneSet, coreControl clo
lifecycle.IsPodAllHooked(cs.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,
// so just update pod lifecycle state. ref: https://github.com/openkruise/kruise/issues/1156
if clonesetutils.EqualToRevisionHash("", pod, updateRevision) {
if cs.Spec.Lifecycle != nil && !lifecycle.IsPodAllHooked(cs.Spec.Lifecycle.InPlaceUpdate, pod) {
state = appspub.LifecycleStateUpdated
} else {
state = appspub.LifecycleStateNormal
}
}
case appspub.LifecycleStateUpdating:
if opts.CheckPodUpdateCompleted(pod) == nil {
if cs.Spec.Lifecycle != nil && !lifecycle.IsPodAllHooked(cs.Spec.Lifecycle.InPlaceUpdate, pod) {
Expand Down
15 changes: 13 additions & 2 deletions pkg/controller/statefulset/stateful_set_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet(
// refresh states for all pods
var modified bool
for _, pod := range pods {
refreshed, duration, err := ssc.refreshPodState(set, pod)
refreshed, duration, err := ssc.refreshPodState(set, pod, updateRevision.Name)
if err != nil {
return &status, err
} else if duration > 0 {
Expand Down Expand Up @@ -838,7 +838,7 @@ func (ssc *defaultStatefulSetControl) deletePod(set *appsv1beta1.StatefulSet, po
return true, nil
}

func (ssc *defaultStatefulSetControl) refreshPodState(set *appsv1beta1.StatefulSet, pod *v1.Pod) (bool, time.Duration, error) {
func (ssc *defaultStatefulSetControl) refreshPodState(set *appsv1beta1.StatefulSet, pod *v1.Pod, updateRevision string) (bool, time.Duration, error) {
if set.Spec.UpdateStrategy.RollingUpdate == nil {
return false, 0, nil
}
Expand All @@ -857,6 +857,17 @@ func (ssc *defaultStatefulSetControl) refreshPodState(set *appsv1beta1.StatefulS

var state appspub.LifecycleStateType
switch lifecycle.GetPodLifecycleState(pod) {
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,
// so just update pod lifecycle state. ref: https://github.com/openkruise/kruise/issues/1156
if getPodRevision(pod) == updateRevision {
if set.Spec.Lifecycle != nil && !lifecycle.IsPodAllHooked(set.Spec.Lifecycle.InPlaceUpdate, pod) {
state = appspub.LifecycleStateUpdated
} else {
state = appspub.LifecycleStateNormal
}
}
case appspub.LifecycleStateUpdating:
if opts.CheckPodUpdateCompleted(pod) == nil {
if set.Spec.Lifecycle != nil && !lifecycle.IsPodAllHooked(set.Spec.Lifecycle.InPlaceUpdate, pod) {
Expand Down

0 comments on commit d765df7

Please sign in to comment.