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 Lifecycle Hook for CloneSet #1071

Merged
merged 2 commits into from
Nov 8, 2022
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
21 changes: 18 additions & 3 deletions apis/apps/pub/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,22 @@ const (
LifecycleStateKey = "lifecycle.apps.kruise.io/state"
LifecycleTimestampKey = "lifecycle.apps.kruise.io/timestamp"

LifecycleStateNormal LifecycleStateType = "Normal"
// LifecycleStatePreparingNormal means the Pod is created but unavailable.
// It will translate to Normal state if Lifecycle.PreNormal is hooked.
LifecycleStatePreparingNormal LifecycleStateType = "PreparingNormal"
veophi marked this conversation as resolved.
Show resolved Hide resolved
// LifecycleStateNormal is a necessary condition for Pod to be available.
LifecycleStateNormal LifecycleStateType = "Normal"
// LifecycleStatePreparingUpdate means pod is being prepared to update.
// It will translate to Updating state if Lifecycle.InPlaceUpdate is Not hooked.
LifecycleStatePreparingUpdate LifecycleStateType = "PreparingUpdate"
LifecycleStateUpdating LifecycleStateType = "Updating"
LifecycleStateUpdated LifecycleStateType = "Updated"
// LifecycleStateUpdating means the Pod is being updated.
// 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.
LifecycleStateUpdated LifecycleStateType = "Updated"
// LifecycleStatePreparingDelete means the Pod is prepared to delete.
// The Pod will be deleted by workload if Lifecycle.PreDelete is Not hooked.
LifecycleStatePreparingDelete LifecycleStateType = "PreparingDelete"
)

Expand All @@ -35,6 +47,8 @@ type Lifecycle struct {
PreDelete *LifecycleHook `json:"preDelete,omitempty"`
// InPlaceUpdate is the hook before Pod to update and after Pod has been updated.
InPlaceUpdate *LifecycleHook `json:"inPlaceUpdate,omitempty"`
// PreNormal is the hook after Pod to be created and ready to be Normal.
PreNormal *LifecycleHook `json:"preNormal,omitempty"`
}

type LifecycleHook struct {
Expand All @@ -43,6 +57,7 @@ type LifecycleHook struct {
// MarkPodNotReady = true means:
// - Pod will be set to 'NotReady' at preparingDelete/preparingUpdate state.
// - Pod will be restored to 'Ready' at Updated state if it was set to 'NotReady' at preparingUpdate state.
// Currently, MarkPodNotReady only takes effect on InPlaceUpdate & PreDelete hook.
// Default to false.
MarkPodNotReady bool `json:"markPodNotReady,omitempty"`
}
5 changes: 5 additions & 0 deletions apis/apps/pub/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apis/apps/v1alpha1/cloneset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type CloneSetSpec struct {
// Defaults to 0 (pod will be considered available as soon as it is ready)
MinReadySeconds int32 `json:"minReadySeconds,omitempty"`

// Lifecycle defines the lifecycle hooks for Pods pre-delete, in-place update.
// Lifecycle defines the lifecycle hooks for Pods pre-available(pre-normal), pre-delete, in-place update.
Lifecycle *appspub.Lifecycle `json:"lifecycle,omitempty"`
}

Expand Down
35 changes: 29 additions & 6 deletions config/crd/bases/apps.kruise.io_clonesets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ spec:
description: CloneSetSpec defines the desired state of CloneSet
properties:
lifecycle:
description: Lifecycle defines the lifecycle hooks for Pods pre-delete,
in-place update.
description: Lifecycle defines the lifecycle hooks for Pods pre-available(pre-normal),
pre-delete, in-place update.
properties:
inPlaceUpdate:
description: InPlaceUpdate is the hook before Pod to update and
Expand All @@ -101,8 +101,9 @@ spec:
description: 'MarkPodNotReady = true means: - Pod will be
set to ''NotReady'' at preparingDelete/preparingUpdate state.
- Pod will be restored to ''Ready'' at Updated state if
it was set to ''NotReady'' at preparingUpdate state. Default
to false.'
it was set to ''NotReady'' at preparingUpdate state. Currently,
MarkPodNotReady only takes effect on InPlaceUpdate & PreDelete
hook. Default to false.'
type: boolean
type: object
preDelete:
Expand All @@ -120,8 +121,30 @@ spec:
description: 'MarkPodNotReady = true means: - Pod will be
set to ''NotReady'' at preparingDelete/preparingUpdate state.
- Pod will be restored to ''Ready'' at Updated state if
it was set to ''NotReady'' at preparingUpdate state. Default
to false.'
it was set to ''NotReady'' at preparingUpdate state. Currently,
MarkPodNotReady only takes effect on InPlaceUpdate & PreDelete
hook. Default to false.'
type: boolean
type: object
preNormal:
description: PreNormal is the hook after Pod to be created and
ready to be Normal.
properties:
finalizersHandler:
items:
type: string
type: array
labelsHandler:
additionalProperties:
type: string
type: object
markPodNotReady:
description: 'MarkPodNotReady = true means: - Pod will be
set to ''NotReady'' at preparingDelete/preparingUpdate state.
- Pod will be restored to ''Ready'' at Updated state if
it was set to ''NotReady'' at preparingUpdate state. Currently,
MarkPodNotReady only takes effect on InPlaceUpdate & PreDelete
hook. Default to false.'
type: boolean
type: object
type: object
Expand Down
31 changes: 27 additions & 4 deletions config/crd/bases/apps.kruise.io_daemonsets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ spec:
description: 'MarkPodNotReady = true means: - Pod will be
set to ''NotReady'' at preparingDelete/preparingUpdate state.
- Pod will be restored to ''Ready'' at Updated state if
it was set to ''NotReady'' at preparingUpdate state. Default
to false.'
it was set to ''NotReady'' at preparingUpdate state. Currently,
MarkPodNotReady only takes effect on InPlaceUpdate & PreDelete
hook. Default to false.'
type: boolean
type: object
preDelete:
Expand All @@ -124,8 +125,30 @@ spec:
description: 'MarkPodNotReady = true means: - Pod will be
set to ''NotReady'' at preparingDelete/preparingUpdate state.
- Pod will be restored to ''Ready'' at Updated state if
it was set to ''NotReady'' at preparingUpdate state. Default
to false.'
it was set to ''NotReady'' at preparingUpdate state. Currently,
MarkPodNotReady only takes effect on InPlaceUpdate & PreDelete
hook. Default to false.'
type: boolean
type: object
preNormal:
description: PreNormal is the hook after Pod to be created and
ready to be Normal.
properties:
finalizersHandler:
items:
type: string
type: array
labelsHandler:
additionalProperties:
type: string
type: object
markPodNotReady:
description: 'MarkPodNotReady = true means: - Pod will be
set to ''NotReady'' at preparingDelete/preparingUpdate state.
- Pod will be restored to ''Ready'' at Updated state if
it was set to ''NotReady'' at preparingUpdate state. Currently,
MarkPodNotReady only takes effect on InPlaceUpdate & PreDelete
hook. Default to false.'
type: boolean
type: object
type: object
Expand Down
31 changes: 27 additions & 4 deletions config/crd/bases/apps.kruise.io_statefulsets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,9 @@ spec:
description: 'MarkPodNotReady = true means: - Pod will be
set to ''NotReady'' at preparingDelete/preparingUpdate state.
- Pod will be restored to ''Ready'' at Updated state if
it was set to ''NotReady'' at preparingUpdate state. Default
to false.'
it was set to ''NotReady'' at preparingUpdate state. Currently,
MarkPodNotReady only takes effect on InPlaceUpdate & PreDelete
hook. Default to false.'
type: boolean
type: object
preDelete:
Expand All @@ -537,8 +538,30 @@ spec:
description: 'MarkPodNotReady = true means: - Pod will be
set to ''NotReady'' at preparingDelete/preparingUpdate state.
- Pod will be restored to ''Ready'' at Updated state if
it was set to ''NotReady'' at preparingUpdate state. Default
to false.'
it was set to ''NotReady'' at preparingUpdate state. Currently,
MarkPodNotReady only takes effect on InPlaceUpdate & PreDelete
hook. Default to false.'
type: boolean
type: object
preNormal:
description: PreNormal is the hook after Pod to be created and
ready to be Normal.
properties:
finalizersHandler:
items:
type: string
type: array
labelsHandler:
additionalProperties:
type: string
type: object
markPodNotReady:
description: 'MarkPodNotReady = true means: - Pod will be
set to ''NotReady'' at preparingDelete/preparingUpdate state.
- Pod will be restored to ''Ready'' at Updated state if
it was set to ''NotReady'' at preparingUpdate state. Currently,
MarkPodNotReady only takes effect on InPlaceUpdate & PreDelete
hook. Default to false.'
type: boolean
type: object
type: object
Expand Down
63 changes: 58 additions & 5 deletions config/crd/bases/apps.kruise.io_uniteddeployments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ spec:
Pod will be set to ''NotReady'' at preparingDelete/preparingUpdate
state. - Pod will be restored to ''Ready'' at
Updated state if it was set to ''NotReady''
at preparingUpdate state. Default to false.'
at preparingUpdate state. Currently, MarkPodNotReady
only takes effect on InPlaceUpdate & PreDelete
hook. Default to false.'
type: boolean
type: object
preDelete:
Expand All @@ -170,7 +172,31 @@ spec:
Pod will be set to ''NotReady'' at preparingDelete/preparingUpdate
state. - Pod will be restored to ''Ready'' at
Updated state if it was set to ''NotReady''
at preparingUpdate state. Default to false.'
at preparingUpdate state. Currently, MarkPodNotReady
only takes effect on InPlaceUpdate & PreDelete
hook. Default to false.'
type: boolean
type: object
preNormal:
description: PreNormal is the hook after Pod to be
created and ready to be Normal.
properties:
finalizersHandler:
items:
type: string
type: array
labelsHandler:
additionalProperties:
type: string
type: object
markPodNotReady:
description: 'MarkPodNotReady = true means: -
Pod will be set to ''NotReady'' at preparingDelete/preparingUpdate
state. - Pod will be restored to ''Ready'' at
Updated state if it was set to ''NotReady''
at preparingUpdate state. Currently, MarkPodNotReady
only takes effect on InPlaceUpdate & PreDelete
hook. Default to false.'
type: boolean
type: object
type: object
Expand Down Expand Up @@ -546,7 +572,8 @@ spec:
properties:
lifecycle:
description: Lifecycle defines the lifecycle hooks for
Pods pre-delete, in-place update.
Pods pre-available(pre-normal), pre-delete, in-place
update.
properties:
inPlaceUpdate:
description: InPlaceUpdate is the hook before Pod
Expand All @@ -565,7 +592,9 @@ spec:
Pod will be set to ''NotReady'' at preparingDelete/preparingUpdate
state. - Pod will be restored to ''Ready'' at
Updated state if it was set to ''NotReady''
at preparingUpdate state. Default to false.'
at preparingUpdate state. Currently, MarkPodNotReady
only takes effect on InPlaceUpdate & PreDelete
hook. Default to false.'
type: boolean
type: object
preDelete:
Expand All @@ -585,7 +614,31 @@ spec:
Pod will be set to ''NotReady'' at preparingDelete/preparingUpdate
state. - Pod will be restored to ''Ready'' at
Updated state if it was set to ''NotReady''
at preparingUpdate state. Default to false.'
at preparingUpdate state. Currently, MarkPodNotReady
only takes effect on InPlaceUpdate & PreDelete
hook. Default to false.'
type: boolean
type: object
preNormal:
description: PreNormal is the hook after Pod to be
created and ready to be Normal.
properties:
finalizersHandler:
items:
type: string
type: array
labelsHandler:
additionalProperties:
type: string
type: object
markPodNotReady:
description: 'MarkPodNotReady = true means: -
Pod will be set to ''NotReady'' at preparingDelete/preparingUpdate
state. - Pod will be restored to ''Ready'' at
Updated state if it was set to ''NotReady''
at preparingUpdate state. Currently, MarkPodNotReady
only takes effect on InPlaceUpdate & PreDelete
hook. Default to false.'
type: boolean
type: object
type: object
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/cloneset/sync/cloneset_scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ func (r *realControl) managePreparingDelete(cs *appsv1alpha1.CloneSet, pods, pod
continue
}

klog.V(3).Infof("CloneSet %s patch pod %s lifecycle from PreparingDelete to Normal",
klog.V(3).Infof("CloneSet %s cancel deletion of pod %s, and patch lifecycle from PreparingDelete to PreparingNormal",
clonesetutils.GetControllerKey(cs), pod.Name)
if updated, gotPod, err := r.lifecycleControl.UpdatePodLifecycle(pod, appspub.LifecycleStateNormal, false); err != nil {
if updated, gotPod, err := r.lifecycleControl.UpdatePodLifecycle(pod, appspub.LifecycleStatePreparingNormal, false); err != nil {
return modified, err
} else if updated {
modified = true
Expand Down Expand Up @@ -214,7 +214,7 @@ func (r *realControl) createPods(
if clonesetutils.EqualToRevisionHash("", pod, currentRevision) {
cs = currentCS
}
lifecycle.SetPodLifecycle(appspub.LifecycleStateNormal)(pod)
lifecycle.SetPodLifecycle(appspub.LifecycleStatePreparingNormal)(pod)

var createErr error
if createErr = r.createOnePod(cs, pod, existingPVCNames); createErr != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/cloneset/sync/cloneset_scale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestCreatePods(t *testing.T) {
apps.ControllerRevisionHashLabelKey: "revision_abc",
apps.DefaultDeploymentUniqueLabelKey: "revision_abc",
"foo": "bar",
appspub.LifecycleStateKey: string(appspub.LifecycleStateNormal),
veophi marked this conversation as resolved.
Show resolved Hide resolved
appspub.LifecycleStateKey: string(appspub.LifecycleStatePreparingNormal),
},
OwnerReferences: []metav1.OwnerReference{
{
Expand Down Expand Up @@ -141,7 +141,7 @@ func TestCreatePods(t *testing.T) {
apps.ControllerRevisionHashLabelKey: "revision_xyz",
apps.DefaultDeploymentUniqueLabelKey: "revision_xyz",
"foo": "bar",
appspub.LifecycleStateKey: string(appspub.LifecycleStateNormal),
appspub.LifecycleStateKey: string(appspub.LifecycleStatePreparingNormal),
},
OwnerReferences: []metav1.OwnerReference{
{
Expand Down Expand Up @@ -199,7 +199,7 @@ func TestCreatePods(t *testing.T) {
apps.ControllerRevisionHashLabelKey: "revision_xyz",
apps.DefaultDeploymentUniqueLabelKey: "revision_xyz",
"foo": "bar",
appspub.LifecycleStateKey: string(appspub.LifecycleStateNormal),
appspub.LifecycleStateKey: string(appspub.LifecycleStatePreparingNormal),
},
OwnerReferences: []metav1.OwnerReference{
{
Expand Down
Loading