Skip to content

Commit

Permalink
the CloneSet pod lifecycle can be transformed to Normal only if Conta…
Browse files Browse the repository at this point in the history
…inerReady is true
  • Loading branch information
chenpeicheng committed Jan 21, 2024
1 parent 7b1a4fa commit 3ccb6a2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion apis/apps/pub/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
// It will translate to Updated state if the in-place update of the Pod is done.
LifecycleStateUpdating LifecycleStateType = "Updating"
// LifecycleStateUpdated means the Pod is updated, but unavailable.
// It will translate to Normal state if Lifecycle.InPlaceUpdate is hooked.
// It will translate to Normal state if Lifecycle.InPlaceUpdate is hooked and pod condition ContainerReady is true.
LifecycleStateUpdated LifecycleStateType = "Updated"
// LifecycleStatePreparingDelete means the Pod is prepared to delete.
// The Pod will be deleted by workload if Lifecycle.PreDelete is Not hooked.
Expand Down
16 changes: 7 additions & 9 deletions pkg/controller/cloneset/sync/cloneset_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,24 +183,22 @@ func (c *realControl) refreshPodState(cs *appsv1alpha1.CloneSet, coreControl clo
// 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 {
if util.IsRunningAndContainerReady(pod) && lifecycle.IsInPlaceUpdateHookNilOrAllHooked(cs.Spec.Lifecycle, pod) {

Check warning on line 186 in pkg/controller/cloneset/sync/cloneset_update.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/cloneset/sync/cloneset_update.go#L186

Added line #L186 was not covered by tests
state = appspub.LifecycleStateNormal
} else {
state = appspub.LifecycleStateUpdated

Check warning on line 189 in pkg/controller/cloneset/sync/cloneset_update.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/cloneset/sync/cloneset_update.go#L188-L189

Added lines #L188 - L189 were not covered by tests
}
}
case appspub.LifecycleStateUpdating:
if opts.CheckPodUpdateCompleted(pod) == nil {
if cs.Spec.Lifecycle != nil && !lifecycle.IsPodAllHooked(cs.Spec.Lifecycle.InPlaceUpdate, pod) {
state = appspub.LifecycleStateUpdated
} else {
if util.IsRunningAndContainerReady(pod) && lifecycle.IsInPlaceUpdateHookNilOrAllHooked(cs.Spec.Lifecycle, pod) {

Check warning on line 194 in pkg/controller/cloneset/sync/cloneset_update.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/cloneset/sync/cloneset_update.go#L194

Added line #L194 was not covered by tests
state = appspub.LifecycleStateNormal
} else {
state = appspub.LifecycleStateUpdated

Check warning on line 197 in pkg/controller/cloneset/sync/cloneset_update.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/cloneset/sync/cloneset_update.go#L196-L197

Added lines #L196 - L197 were not covered by tests
}
}
case appspub.LifecycleStateUpdated:
if cs.Spec.Lifecycle == nil ||
cs.Spec.Lifecycle.InPlaceUpdate == nil ||
lifecycle.IsPodAllHooked(cs.Spec.Lifecycle.InPlaceUpdate, pod) {
if util.IsRunningAndContainerReady(pod) && lifecycle.IsInPlaceUpdateHookNilOrAllHooked(cs.Spec.Lifecycle, pod) {

Check warning on line 201 in pkg/controller/cloneset/sync/cloneset_update.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/cloneset/sync/cloneset_update.go#L201

Added line #L201 was not covered by tests
state = appspub.LifecycleStateNormal
}
}
Expand Down

0 comments on commit 3ccb6a2

Please sign in to comment.