Skip to content

Commit f082f6f

Browse files
committed
Optimize the KeepWorkloadPausedOnRolloutDeletion logic to ensure workload configurations can be restored after rollout completion.
Signed-off-by: liheng.zms <liheng.zms@alibaba-inc.com>
1 parent 787bb9c commit f082f6f

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

api/v1beta1/batchrelease_plan_types.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ type FinalizingPolicyType string
7171
const (
7272
// WaitResumeFinalizingPolicyType will wait workload to be resumed, which means
7373
// controller will be hold at Finalizing phase until all pods of workload is upgraded.
74-
// WaitResumeFinalizingPolicyType only works in canary-style BatchRelease controller.
74+
// WaitResumeFinalizingPolicyType currently serves two purposes:
75+
// 1. In canary deployments, it determines whether to wait for the stable deployment to complete.
76+
// 2. It distinguishes between a normal deployment completion and a rollout cancellation during deployment.
77+
// Only a normal deployment completion will result in a WaitResume state.
7578
WaitResumeFinalizingPolicyType FinalizingPolicyType = "WaitResume"
7679
// ImmediateFinalizingPolicyType will not to wait workload to be resumed.
7780
ImmediateFinalizingPolicyType FinalizingPolicyType = "Immediate"

pkg/controller/batchrelease/control/partitionstyle/cloneset/control.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ func (rc *realController) Finalize(release *v1beta1.BatchRelease) error {
122122

123123
// if batchPartition == nil, workload should be promoted.
124124
if release.Spec.ReleasePlan.BatchPartition == nil {
125-
if utilfeature.DefaultMutableFeatureGate.Enabled(feature.KeepWorkloadPausedOnRolloutDeletion) {
125+
// This condition is only met when a rollout is canceled during the release process.
126+
if utilfeature.DefaultMutableFeatureGate.Enabled(feature.KeepWorkloadPausedOnRolloutDeletion) &&
127+
!control.ShouldWaitResume(release) {
126128
specBody = `,"spec":{"updateStrategy":{"paused":false}}`
127129
} else {
128130
specBody = `,"spec":{"updateStrategy":{"partition":null,"paused":false}}`

pkg/controller/batchrelease/control/partitionstyle/deployment/control.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ func (rc *realController) Finalize(release *v1beta1.BatchRelease) error {
144144
patchData := patch.NewDeploymentPatch()
145145
if release.Spec.ReleasePlan.BatchPartition == nil {
146146
strategy := util.GetDeploymentStrategy(rc.object)
147-
if !utilfeature.DefaultMutableFeatureGate.Enabled(feature.KeepWorkloadPausedOnRolloutDeletion) {
147+
// This condition is only met when a rollout is canceled during the release process.
148+
if utilfeature.DefaultMutableFeatureGate.Enabled(feature.KeepWorkloadPausedOnRolloutDeletion) &&
149+
!control.ShouldWaitResume(release) {
150+
patchData.UpdatePaused(true)
151+
} else {
148152
patchData.UpdatePaused(false)
149153
}
150154
if rc.object.Spec.Strategy.Type == apps.RecreateDeploymentStrategyType {

pkg/controller/batchrelease/control/partitionstyle/statefulset/control.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"fmt"
2222
"math"
2323

24+
"github.com/openkruise/rollouts/pkg/feature"
25+
utilfeature "github.com/openkruise/rollouts/pkg/util/feature"
2426
corev1 "k8s.io/api/core/v1"
2527
"k8s.io/apimachinery/pkg/runtime/schema"
2628
"k8s.io/apimachinery/pkg/types"
@@ -32,9 +34,7 @@ import (
3234
"github.com/openkruise/rollouts/pkg/controller/batchrelease/control"
3335
"github.com/openkruise/rollouts/pkg/controller/batchrelease/control/partitionstyle"
3436
"github.com/openkruise/rollouts/pkg/controller/batchrelease/labelpatch"
35-
"github.com/openkruise/rollouts/pkg/feature"
3637
"github.com/openkruise/rollouts/pkg/util"
37-
utilfeature "github.com/openkruise/rollouts/pkg/util/feature"
3838
)
3939

4040
type realController struct {
@@ -136,8 +136,11 @@ func (rc *realController) Finalize(release *v1beta1.BatchRelease) error {
136136

137137
var specBody string
138138
// If batchPartition == nil, workload should be promoted;
139-
if release.Spec.ReleasePlan.BatchPartition == nil && !utilfeature.DefaultMutableFeatureGate.Enabled(feature.KeepWorkloadPausedOnRolloutDeletion) {
140-
specBody = `,"spec":{"updateStrategy":{"rollingUpdate":{"partition":null}}}`
139+
if release.Spec.ReleasePlan.BatchPartition == nil {
140+
if !(utilfeature.DefaultMutableFeatureGate.Enabled(feature.KeepWorkloadPausedOnRolloutDeletion) &&
141+
!control.ShouldWaitResume(release)) {
142+
specBody = `,"spec":{"updateStrategy":{"rollingUpdate":{"partition":null}}}`
143+
}
141144
}
142145
body := fmt.Sprintf(`{"metadata":{"annotations":{"%s":null}}%s}`, util.BatchReleaseControlAnnotation, specBody)
143146
clone := util.GetEmptyObjectWithKey(rc.object)

0 commit comments

Comments
 (0)