diff --git a/api/leaderworkerset/v1/leaderworkerset_types.go b/api/leaderworkerset/v1/leaderworkerset_types.go index 639f5e35..27282852 100644 --- a/api/leaderworkerset/v1/leaderworkerset_types.go +++ b/api/leaderworkerset/v1/leaderworkerset_types.go @@ -257,11 +257,11 @@ const ( type RestartPolicyType string const ( - // DefaultRestartPolicy will recreate all the pods in the group if + // RecreateGroupOnPodRestart will recreate all the pods in the group if // 1. Any individual pod in the group is recreated; 2. Any containers/init-containers // in a pod is restarted. This is to ensure all pods/containers in the group will be // started in the same time. - DefaultRestartPolicy RestartPolicyType = "RecreateGroupOnPodRestart" + RecreateGroupOnPodRestart RestartPolicyType = "RecreateGroupOnPodRestart" // Default will follow the same behavior as the StatefulSet where only the failed pod // will be restarted on failure and other pods in the group will not be impacted. diff --git a/config/crd/bases/leaderworkerset.x-k8s.io_leaderworkersets.yaml b/config/crd/bases/leaderworkerset.x-k8s.io_leaderworkersets.yaml index 30391812..066e21d9 100644 --- a/config/crd/bases/leaderworkerset.x-k8s.io_leaderworkersets.yaml +++ b/config/crd/bases/leaderworkerset.x-k8s.io_leaderworkersets.yaml @@ -8066,8 +8066,8 @@ spec: default: RecreateGroupOnPodRestart description: |- RestartPolicy defines the restart policy when pod failures happen. - The Default policy is deprecated, will be removed in the future, replace - with None for the same behavior. + The former named Default policy is deprecated, will be removed in the future, + replace with None policy for the same behavior. enum: - Default - RecreateGroupOnPodRestart diff --git a/pkg/controllers/leaderworkerset_controller_test.go b/pkg/controllers/leaderworkerset_controller_test.go index 0d8d0c00..84082843 100644 --- a/pkg/controllers/leaderworkerset_controller_test.go +++ b/pkg/controllers/leaderworkerset_controller_test.go @@ -58,7 +58,7 @@ func TestLeaderStatefulSetApplyConfig(t *testing.T) { }). WorkerTemplateSpec(testutils.MakeWorkerPodSpec()). Size(1). - RestartPolicy(leaderworkerset.DefaultRestartPolicy).Obj(), + RestartPolicy(leaderworkerset.RecreateGroupOnPodRestart).Obj(), wantApplyConfig: &appsapplyv1.StatefulSetApplyConfiguration{ TypeMetaApplyConfiguration: metaapplyv1.TypeMetaApplyConfiguration{ Kind: ptr.To[string]("StatefulSet"), @@ -125,7 +125,7 @@ func TestLeaderStatefulSetApplyConfig(t *testing.T) { }). WorkerTemplateSpec(testutils.MakeWorkerPodSpec()). Size(2). - RestartPolicy(leaderworkerset.DefaultRestartPolicy).Obj(), + RestartPolicy(leaderworkerset.RecreateGroupOnPodRestart).Obj(), wantApplyConfig: &appsapplyv1.StatefulSetApplyConfiguration{ TypeMetaApplyConfiguration: metaapplyv1.TypeMetaApplyConfiguration{ Kind: ptr.To[string]("StatefulSet"), @@ -193,7 +193,7 @@ func TestLeaderStatefulSetApplyConfig(t *testing.T) { WorkerTemplateSpec(testutils.MakeWorkerPodSpec()). LeaderTemplateSpec(testutils.MakeLeaderPodSpec()). Size(2). - RestartPolicy(leaderworkerset.DefaultRestartPolicy).Obj(), + RestartPolicy(leaderworkerset.RecreateGroupOnPodRestart).Obj(), wantApplyConfig: &appsapplyv1.StatefulSetApplyConfiguration{ TypeMetaApplyConfiguration: metaapplyv1.TypeMetaApplyConfiguration{ Kind: ptr.To[string]("StatefulSet"), @@ -259,7 +259,7 @@ func TestLeaderStatefulSetApplyConfig(t *testing.T) { }). WorkerTemplateSpec(testutils.MakeWorkerPodSpec()). Size(1). - RestartPolicy(leaderworkerset.DefaultRestartPolicy).Obj(), + RestartPolicy(leaderworkerset.RecreateGroupOnPodRestart).Obj(), wantApplyConfig: &appsapplyv1.StatefulSetApplyConfiguration{ TypeMetaApplyConfiguration: metaapplyv1.TypeMetaApplyConfiguration{ Kind: ptr.To[string]("StatefulSet"), @@ -326,7 +326,7 @@ func TestLeaderStatefulSetApplyConfig(t *testing.T) { WorkerTemplateSpec(testutils.MakeWorkerPodSpec()). LeaderTemplateSpec(testutils.MakeLeaderPodSpec()). Size(2). - RestartPolicy(leaderworkerset.DefaultRestartPolicy).Obj(), + RestartPolicy(leaderworkerset.RecreateGroupOnPodRestart).Obj(), wantApplyConfig: &appsapplyv1.StatefulSetApplyConfiguration{ TypeMetaApplyConfiguration: metaapplyv1.TypeMetaApplyConfiguration{ Kind: ptr.To[string]("StatefulSet"), diff --git a/pkg/controllers/pod_controller.go b/pkg/controllers/pod_controller.go index 910be46c..1a7c6ad2 100644 --- a/pkg/controllers/pod_controller.go +++ b/pkg/controllers/pod_controller.go @@ -165,7 +165,7 @@ func (r *PodReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R } func (r *PodReconciler) handleRestartPolicy(ctx context.Context, pod corev1.Pod, leaderWorkerSet leaderworkerset.LeaderWorkerSet) (bool, error) { - if leaderWorkerSet.Spec.LeaderWorkerTemplate.RestartPolicy != leaderworkerset.DefaultRestartPolicy { + if leaderWorkerSet.Spec.LeaderWorkerTemplate.RestartPolicy != leaderworkerset.RecreateGroupOnPodRestart { return false, nil } // the leader pod will be deleted if the worker pod is deleted or any containes were restarted diff --git a/pkg/webhooks/leaderworkerset_webhook.go b/pkg/webhooks/leaderworkerset_webhook.go index 4c4e5718..dca0e597 100644 --- a/pkg/webhooks/leaderworkerset_webhook.go +++ b/pkg/webhooks/leaderworkerset_webhook.go @@ -54,7 +54,7 @@ var _ webhook.CustomDefaulter = &LeaderWorkerSetWebhook{} func (r *LeaderWorkerSetWebhook) Default(ctx context.Context, obj runtime.Object) error { lws := obj.(*v1.LeaderWorkerSet) if lws.Spec.LeaderWorkerTemplate.RestartPolicy == "" { - lws.Spec.LeaderWorkerTemplate.RestartPolicy = v1.DefaultRestartPolicy + lws.Spec.LeaderWorkerTemplate.RestartPolicy = v1.RecreateGroupOnPodRestart } if lws.Spec.LeaderWorkerTemplate.RestartPolicy == v1.DeprecatedDefaultRestartPolicy { diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 75a93f07..ea7b1170 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -92,7 +92,7 @@ var _ = ginkgo.Describe("leaderWorkerSet e2e tests", func() { }) ginkgo.It("Can create/update a lws with size=1", func() { - lws = testing.BuildLeaderWorkerSet(ns.Name).Replica(4).MaxSurge(1).Size(1).RestartPolicy(v1.DefaultRestartPolicy).Obj() + lws = testing.BuildLeaderWorkerSet(ns.Name).Replica(4).MaxSurge(1).Size(1).RestartPolicy(v1.RecreateGroupOnPodRestart).Obj() testing.MustCreateLws(ctx, k8sClient, lws) testing.ExpectValidLeaderStatefulSet(ctx, k8sClient, lws, 4) @@ -262,8 +262,8 @@ var _ = ginkgo.Describe("leaderWorkerSet e2e tests", func() { } }) - ginkgo.It("Pod restart will delete the pod group when restart policy is DefaultRestartPolicy", func() { - lws = testing.BuildLeaderWorkerSet(ns.Name).Replica(1).Size(3).RestartPolicy(v1.DefaultRestartPolicy).Obj() + ginkgo.It("Pod restart will delete the pod group when restart policy is RecreateGroupOnPodRestart", func() { + lws = testing.BuildLeaderWorkerSet(ns.Name).Replica(1).Size(3).RestartPolicy(v1.RecreateGroupOnPodRestart).Obj() testing.MustCreateLws(ctx, k8sClient, lws) testing.ExpectLeaderWorkerSetAvailable(ctx, k8sClient, lws, "All replicas are ready") diff --git a/test/integration/controllers/leaderworkerset_test.go b/test/integration/controllers/leaderworkerset_test.go index d6ef944b..186b6c08 100644 --- a/test/integration/controllers/leaderworkerset_test.go +++ b/test/integration/controllers/leaderworkerset_test.go @@ -420,9 +420,9 @@ var _ = ginkgo.Describe("LeaderWorkerSet controller", func() { }, }, }), - ginkgo.Entry("Pod restart will delete the pod group when restart policy is DefaultRestartPolicy", &testCase{ + ginkgo.Entry("Pod restart will delete the pod group when restart policy is RecreateGroupOnPodRestart", &testCase{ makeLeaderWorkerSet: func(nsName string) *testing.LeaderWorkerSetWrapper { - return testing.BuildLeaderWorkerSet(nsName).RestartPolicy(leaderworkerset.DefaultRestartPolicy).Replica(1).Size(3) + return testing.BuildLeaderWorkerSet(nsName).RestartPolicy(leaderworkerset.RecreateGroupOnPodRestart).Replica(1).Size(3) }, updates: []*update{ { diff --git a/test/integration/webhooks/leaderworkerset_test.go b/test/integration/webhooks/leaderworkerset_test.go index f3b4dd3c..dcf99316 100644 --- a/test/integration/webhooks/leaderworkerset_test.go +++ b/test/integration/webhooks/leaderworkerset_test.go @@ -71,7 +71,7 @@ var _ = ginkgo.Describe("leaderworkerset defaulting, creation and update", func( return lwsWrapper }, getExpectedLWS: func(lws *leaderworkerset.LeaderWorkerSet) *testutils.LeaderWorkerSetWrapper { - return testutils.BuildLeaderWorkerSet(ns.Name).Replica(1).RestartPolicy(leaderworkerset.DefaultRestartPolicy) + return testutils.BuildLeaderWorkerSet(ns.Name).Replica(1).RestartPolicy(leaderworkerset.RecreateGroupOnPodRestart) }, }), ginkgo.Entry("apply defaulting logic for size", &testDefaultingCase{ @@ -81,7 +81,7 @@ var _ = ginkgo.Describe("leaderworkerset defaulting, creation and update", func( return lwsWrapper }, getExpectedLWS: func(lws *leaderworkerset.LeaderWorkerSet) *testutils.LeaderWorkerSetWrapper { - return testutils.BuildLeaderWorkerSet(ns.Name).Size(1).RestartPolicy(leaderworkerset.DefaultRestartPolicy) + return testutils.BuildLeaderWorkerSet(ns.Name).Size(1).RestartPolicy(leaderworkerset.RecreateGroupOnPodRestart) }, }), ginkgo.Entry("defaulting logic won't apply when shouldn't", &testDefaultingCase{ @@ -89,7 +89,7 @@ var _ = ginkgo.Describe("leaderworkerset defaulting, creation and update", func( return testutils.BuildLeaderWorkerSet(ns.Name).Replica(2).Size(2) }, getExpectedLWS: func(lws *leaderworkerset.LeaderWorkerSet) *testutils.LeaderWorkerSetWrapper { - return testutils.BuildLeaderWorkerSet(ns.Name).Replica(2).Size(2).LeaderTemplateSpec(testutils.MakeLeaderPodSpec()).WorkerTemplateSpec(testutils.MakeWorkerPodSpec()).RestartPolicy(leaderworkerset.DefaultRestartPolicy) + return testutils.BuildLeaderWorkerSet(ns.Name).Replica(2).Size(2).LeaderTemplateSpec(testutils.MakeLeaderPodSpec()).WorkerTemplateSpec(testutils.MakeWorkerPodSpec()).RestartPolicy(leaderworkerset.RecreateGroupOnPodRestart) }, }), ginkgo.Entry("defaulting logic applies when leaderworkertemplate.restartpolicy is not set", &testDefaultingCase{ @@ -97,7 +97,7 @@ var _ = ginkgo.Describe("leaderworkerset defaulting, creation and update", func( return testutils.BuildLeaderWorkerSet(ns.Name).Replica(2).Size(2).RestartPolicy("") }, getExpectedLWS: func(lws *leaderworkerset.LeaderWorkerSet) *testutils.LeaderWorkerSetWrapper { - return testutils.BuildLeaderWorkerSet(ns.Name).Replica(2).Size(2).RestartPolicy(leaderworkerset.DefaultRestartPolicy) + return testutils.BuildLeaderWorkerSet(ns.Name).Replica(2).Size(2).RestartPolicy(leaderworkerset.RecreateGroupOnPodRestart) }, }), ginkgo.Entry("defaulting logic won't apply when leaderworkertemplate.restartpolicy is set", &testDefaultingCase{ @@ -147,7 +147,7 @@ var _ = ginkgo.Describe("leaderworkerset defaulting, creation and update", func( return testutils.BuildLeaderWorkerSet(ns.Name).RolloutStrategy(leaderworkerset.RolloutStrategy{}) // unset rollout strategy }, getExpectedLWS: func(lws *leaderworkerset.LeaderWorkerSet) *testutils.LeaderWorkerSetWrapper { - return testutils.BuildLeaderWorkerSet(ns.Name).RestartPolicy(leaderworkerset.DefaultRestartPolicy).RolloutStrategy(leaderworkerset.RolloutStrategy{ + return testutils.BuildLeaderWorkerSet(ns.Name).RestartPolicy(leaderworkerset.RecreateGroupOnPodRestart).RolloutStrategy(leaderworkerset.RolloutStrategy{ Type: leaderworkerset.RollingUpdateStrategyType, RollingUpdateConfiguration: &leaderworkerset.RollingUpdateConfiguration{ MaxUnavailable: intstr.FromInt32(1), @@ -167,7 +167,7 @@ var _ = ginkgo.Describe("leaderworkerset defaulting, creation and update", func( }, getExpectedLWS: func(lws *leaderworkerset.LeaderWorkerSet) *testutils.LeaderWorkerSetWrapper { return testutils.BuildLeaderWorkerSet(ns.Name). - RestartPolicy(leaderworkerset.DefaultRestartPolicy). + RestartPolicy(leaderworkerset.RecreateGroupOnPodRestart). RolloutStrategy(leaderworkerset.RolloutStrategy{ Type: leaderworkerset.RollingUpdateStrategyType, RollingUpdateConfiguration: &leaderworkerset.RollingUpdateConfiguration{ diff --git a/test/testutils/wrappers.go b/test/testutils/wrappers.go index 3679ae05..c23e5c95 100644 --- a/test/testutils/wrappers.go +++ b/test/testutils/wrappers.go @@ -136,7 +136,7 @@ func BuildLeaderWorkerSet(nsName string) *LeaderWorkerSetWrapper { lws.Namespace = nsName lws.Spec = leaderworkerset.LeaderWorkerSetSpec{} lws.Spec.Replicas = ptr.To[int32](2) - lws.Spec.LeaderWorkerTemplate = leaderworkerset.LeaderWorkerTemplate{RestartPolicy: leaderworkerset.DefaultRestartPolicy} + lws.Spec.LeaderWorkerTemplate = leaderworkerset.LeaderWorkerTemplate{RestartPolicy: leaderworkerset.RecreateGroupOnPodRestart} lws.Spec.LeaderWorkerTemplate.Size = ptr.To[int32](2) lws.Spec.LeaderWorkerTemplate.LeaderTemplate = &corev1.PodTemplateSpec{} lws.Spec.LeaderWorkerTemplate.LeaderTemplate.Spec = MakeLeaderPodSpec()