diff --git a/go.mod b/go.mod index 86605e3..6fb4dcc 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( k8s.io/klog/v2 v2.130.1 k8s.io/kubernetes v1.22.2 k8s.io/utils v0.0.0-20241210054802-24370beab758 - kusionstack.io/kube-api v0.7.4-0.20250922083401-278352ec5aab + kusionstack.io/kube-api v0.7.4-0.20251013070018-4c09604521e4 kusionstack.io/kube-utils v0.2.1-0.20250613035327-11e9cdaec9d6 kusionstack.io/resourceconsist v0.0.4 sigs.k8s.io/controller-runtime v0.21.0 diff --git a/go.sum b/go.sum index c3e71b3..6b8fac2 100644 --- a/go.sum +++ b/go.sum @@ -1021,8 +1021,8 @@ k8s.io/sample-apiserver v0.22.2/go.mod h1:h+/DIV5EmuNq4vfPr5TSXy9mIBVXXlPAKQMPbj k8s.io/system-validators v1.5.0/go.mod h1:bPldcLgkIUK22ALflnsXk8pvkTEndYdNuaHH6gRrl0Q= k8s.io/utils v0.0.0-20240102154912-e7106e64919e h1:eQ/4ljkx21sObifjzXwlPKpdGLrCfRziVtos3ofG/sQ= k8s.io/utils v0.0.0-20240102154912-e7106e64919e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -kusionstack.io/kube-api v0.7.4-0.20250922083401-278352ec5aab h1:7l7Y3YezVPBP65JtlH57IwH9XsJdV2QhZcJEcTEg3cQ= -kusionstack.io/kube-api v0.7.4-0.20250922083401-278352ec5aab/go.mod h1:e1jtrQH2LK5fD2nTyfIXG6nYrYbU8VXShRxTRwVPaLk= +kusionstack.io/kube-api v0.7.4-0.20251013070018-4c09604521e4 h1:VQS8BsRs7jXTY+wwtRjOIfSxDq/Mu7ZIaFZ9CxRIe6U= +kusionstack.io/kube-api v0.7.4-0.20251013070018-4c09604521e4/go.mod h1:e1jtrQH2LK5fD2nTyfIXG6nYrYbU8VXShRxTRwVPaLk= kusionstack.io/kube-utils v0.2.1-0.20250613035327-11e9cdaec9d6 h1:HYE6Wa8EzSlA6UmaTLtNKUgkB2mmasp6Ul69d3/SpK0= kusionstack.io/kube-utils v0.2.1-0.20250613035327-11e9cdaec9d6/go.mod h1:5Uy3GCJ1JEGqZw/Sp/uVnHBJN1t9wjY6USPSZ9s4idk= kusionstack.io/resourceconsist v0.0.4 h1:wRqLJuNh8O4TT6p0uOklFpHUKiRdRxcAH71Sw/q9LhE= diff --git a/pkg/controllers/rolloutrun/executor/alias.go b/pkg/controllers/rolloutrun/executor/alias.go index 0a017de..e6fec0a 100644 --- a/pkg/controllers/rolloutrun/executor/alias.go +++ b/pkg/controllers/rolloutrun/executor/alias.go @@ -28,4 +28,5 @@ const ( StepPostBatchStepHook = rolloutv1alpha1.RolloutStepPostBatchStepHook StepSucceeded = rolloutv1alpha1.RolloutStepSucceeded StepResourceRecycling = rolloutv1alpha1.RolloutStepResourceRecycling + StepSkipped = rolloutv1alpha1.RolloutStepSkipped ) diff --git a/pkg/controllers/rolloutrun/executor/do_command.go b/pkg/controllers/rolloutrun/executor/do_command.go index a2bad55..08a4123 100644 --- a/pkg/controllers/rolloutrun/executor/do_command.go +++ b/pkg/controllers/rolloutrun/executor/do_command.go @@ -14,10 +14,7 @@ func (r *Executor) doCommand(ctx *ExecutorContext) ctrl.Result { logger.Info("processing manual command", "command", cmd) newStatus := ctx.NewStatus - newBatchStatus := ctx.NewStatus.BatchStatus - batchError := newStatus.Error - currentBatchIndex := newBatchStatus.CurrentBatchIndex switch cmd { case rolloutapis.AnnoManualCommandPause: newStatus.Phase = rolloutv1alpha1.RolloutRunPhasePausing @@ -31,30 +28,27 @@ func (r *Executor) doCommand(ctx *ExecutorContext) ctrl.Result { } case rolloutapis.AnnoManualCommandSkip: if batchError != nil { - newStatus.Error = nil - - if int(currentBatchIndex) < (len(rolloutRun.Spec.Batch.Batches) - 1) { - currentBatchIndex++ - newBatchStatus.CurrentBatchIndex = currentBatchIndex - newBatchStatus.CurrentBatchState = StepNone - } else { - newStatus.Phase = rolloutv1alpha1.RolloutRunPhasePostRollout - } + handleBatchStatusWhenSkipped(newStatus, len(rolloutRun.Spec.Batch.Batches)) } case rolloutapis.AnnoManualCommandCancel: newStatus.Phase = rolloutv1alpha1.RolloutRunPhaseCanceling case rolloutapis.AnnoManualCommandForceSkipCurrentBatch: - if batchError != nil { - newStatus.Error = nil - } - if int(currentBatchIndex) < (len(rolloutRun.Spec.Batch.Batches) - 1) { - currentBatchIndex++ - newBatchStatus.CurrentBatchIndex = currentBatchIndex - newBatchStatus.CurrentBatchState = StepNone - } else { - newBatchStatus.CurrentBatchState = StepPostBatchStepHook - } + handleBatchStatusWhenSkipped(newStatus, len(rolloutRun.Spec.Batch.Batches)) } return ctrl.Result{Requeue: true} } + +func handleBatchStatusWhenSkipped(newStatus *rolloutv1alpha1.RolloutRunStatus, batchSize int) { + currentBatchIndex := newStatus.BatchStatus.CurrentBatchIndex + if newStatus.Error != nil { + newStatus.Error = nil + } + + // only skip when current batch is not the last batch + if int(currentBatchIndex) < (batchSize - 1) { + newStatus.BatchStatus.Records[currentBatchIndex].State = StepSkipped + newStatus.BatchStatus.CurrentBatchIndex = currentBatchIndex + 1 + newStatus.BatchStatus.CurrentBatchState = StepNone + } +}