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

fix pod hang in PreparingUpdate state when rollback before update hook #1157

Merged
merged 1 commit into from
Feb 7, 2023
Merged
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
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz add some annotations to explain these codes.

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