Skip to content
Open
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ 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.20250727122744-2399b387a919
kusionstack.io/kube-api v0.7.4-0.20250902122009-5447303fc5ee
kusionstack.io/kube-utils v0.2.1-0.20250613035327-11e9cdaec9d6
kusionstack.io/resourceconsist v0.0.2
kusionstack.io/resourceconsist v0.0.4
sigs.k8s.io/controller-runtime v0.21.0
)

Expand Down
48 changes: 30 additions & 18 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1021,28 +1021,40 @@ 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.6.7-0.20250719054959-1cbe2be851f6 h1:ZXP+K55y4j9SKmLr8TMTgza5w1Zeu5Fmevk4MrTvFSQ=
kusionstack.io/kube-api v0.6.7-0.20250719054959-1cbe2be851f6/go.mod h1:ZrLpR6T7HzZp5UGSTXxzNCRizCC66mn2oGJWfL3VONc=
kusionstack.io/kube-api v0.6.7-0.20250720104212-3e44585627a1 h1:j/yoU/mjITbd5cQc7IaJGiEnVD9S36PsXbWkJcwYLKo=
kusionstack.io/kube-api v0.6.7-0.20250720104212-3e44585627a1/go.mod h1:ZrLpR6T7HzZp5UGSTXxzNCRizCC66mn2oGJWfL3VONc=
kusionstack.io/kube-api v0.6.7-0.20250720165902-a400661d33a0 h1:bgna3I0Xi0XGvdU+hwLc6ZFuNKPeTgZOAgUZaVW2ICQ=
kusionstack.io/kube-api v0.6.7-0.20250720165902-a400661d33a0/go.mod h1:ZrLpR6T7HzZp5UGSTXxzNCRizCC66mn2oGJWfL3VONc=
kusionstack.io/kube-api v0.6.7-0.20250721072644-0af27496d542 h1:JM7CsrsbwBK//eF8WkPlvw0IIj4sHT5SN3xHMryZSmM=
kusionstack.io/kube-api v0.6.7-0.20250721072644-0af27496d542/go.mod h1:e1jtrQH2LK5fD2nTyfIXG6nYrYbU8VXShRxTRwVPaLk=
kusionstack.io/kube-api v0.7.0 h1:jYjNq9LbpqVCNPU4cQZJI17G5gwZGJbhgAYi0BaTe7g=
kusionstack.io/kube-api v0.7.0/go.mod h1:e1jtrQH2LK5fD2nTyfIXG6nYrYbU8VXShRxTRwVPaLk=
kusionstack.io/kube-api v0.7.1 h1:m67X6mI1kOAvMPjiAYQRmjlugt25hN7jyd4nJn7LkPY=
kusionstack.io/kube-api v0.7.1/go.mod h1:e1jtrQH2LK5fD2nTyfIXG6nYrYbU8VXShRxTRwVPaLk=
kusionstack.io/kube-api v0.7.2 h1:qVrOnvGaqi4iZn6BZP0dQd/buLKLyDvY4PjkUCLVoZY=
kusionstack.io/kube-api v0.7.2/go.mod h1:e1jtrQH2LK5fD2nTyfIXG6nYrYbU8VXShRxTRwVPaLk=
kusionstack.io/kube-api v0.7.3 h1:Fxj/E+aixUuCB0VekEvEx6ss24Jke7MvcbRwAXwVYBo=
kusionstack.io/kube-api v0.7.3/go.mod h1:e1jtrQH2LK5fD2nTyfIXG6nYrYbU8VXShRxTRwVPaLk=
kusionstack.io/kube-api v0.7.4-0.20250727122744-2399b387a919 h1:EMcsFMNMZO3oW7pqGOZd1nJC6YyQSt2RrcGdpC1J1gU=
kusionstack.io/kube-api v0.7.4-0.20250727122744-2399b387a919/go.mod h1:e1jtrQH2LK5fD2nTyfIXG6nYrYbU8VXShRxTRwVPaLk=
kusionstack.io/kube-api v0.7.4-0.20250825051758-ecb7ab4bd47e h1:VK9EoO8P+ugxQE8sgCjUsTdVI90HsLJq8xAneSzhl7E=
kusionstack.io/kube-api v0.7.4-0.20250825051758-ecb7ab4bd47e/go.mod h1:e1jtrQH2LK5fD2nTyfIXG6nYrYbU8VXShRxTRwVPaLk=
kusionstack.io/kube-api v0.7.4-0.20250825063046-b78dd5a27a1d h1:eW004SEhcfGC/oGz2MQrZa88oDEMEES5Di9uP24Wp/g=
kusionstack.io/kube-api v0.7.4-0.20250825063046-b78dd5a27a1d/go.mod h1:e1jtrQH2LK5fD2nTyfIXG6nYrYbU8VXShRxTRwVPaLk=
kusionstack.io/kube-api v0.7.4-0.20250825073953-1db5a342fb25 h1:tjRlORACDHvIMudOp4ixEuz9MUzk+7Im4VDA5gE3mCc=
kusionstack.io/kube-api v0.7.4-0.20250825073953-1db5a342fb25/go.mod h1:e1jtrQH2LK5fD2nTyfIXG6nYrYbU8VXShRxTRwVPaLk=
kusionstack.io/kube-api v0.7.4-0.20250825080129-95c4ef2f91f2 h1:tiS+ABL0do2ccK+8tu/LuAf1p9Wt+Nvh+SAscUg5yKs=
kusionstack.io/kube-api v0.7.4-0.20250825080129-95c4ef2f91f2/go.mod h1:e1jtrQH2LK5fD2nTyfIXG6nYrYbU8VXShRxTRwVPaLk=
kusionstack.io/kube-api v0.7.4-0.20250825084555-df5d951e621b h1:EPM4aBdfXpIVexIO5F7mpmoRzJZVkRPaa1WlvmajSTU=
kusionstack.io/kube-api v0.7.4-0.20250825084555-df5d951e621b/go.mod h1:e1jtrQH2LK5fD2nTyfIXG6nYrYbU8VXShRxTRwVPaLk=
kusionstack.io/kube-api v0.7.4-0.20250825085826-67aefdbf9caa h1:8g+NRdhR04R2RE1hBCyGNyNqHOu60nX59nHSRnO6wR0=
kusionstack.io/kube-api v0.7.4-0.20250825085826-67aefdbf9caa/go.mod h1:e1jtrQH2LK5fD2nTyfIXG6nYrYbU8VXShRxTRwVPaLk=
kusionstack.io/kube-api v0.7.4-0.20250826035958-c1b30201ed5c h1:2165AAx76Vr1xDFgaHTzPVyvW83mPeB2TIh/AjVcIZU=
kusionstack.io/kube-api v0.7.4-0.20250826035958-c1b30201ed5c/go.mod h1:e1jtrQH2LK5fD2nTyfIXG6nYrYbU8VXShRxTRwVPaLk=
kusionstack.io/kube-api v0.7.4-0.20250826112948-7aeb5f5204de h1:c7L4xDVkHjGgzAkYYh1k4LCQD3j77pUxwo6buUCPIq0=
kusionstack.io/kube-api v0.7.4-0.20250826112948-7aeb5f5204de/go.mod h1:e1jtrQH2LK5fD2nTyfIXG6nYrYbU8VXShRxTRwVPaLk=
kusionstack.io/kube-api v0.7.4-0.20250828082633-8a73d98e9bf8 h1:1ARYh14b7ksYh1Ci3liyT9jhV2rV1Lyuvnxy8a5WQZU=
kusionstack.io/kube-api v0.7.4-0.20250828082633-8a73d98e9bf8/go.mod h1:e1jtrQH2LK5fD2nTyfIXG6nYrYbU8VXShRxTRwVPaLk=
kusionstack.io/kube-api v0.7.4-0.20250902063249-7e329edd6ea1 h1:o56pmV/Ip0EcYgxNablcaw/5Cy+nXbcOz5hlvt7Nyyk=
kusionstack.io/kube-api v0.7.4-0.20250902063249-7e329edd6ea1/go.mod h1:e1jtrQH2LK5fD2nTyfIXG6nYrYbU8VXShRxTRwVPaLk=
kusionstack.io/kube-api v0.7.4-0.20250902064055-250905b1fce5 h1:1s8FDyAlDet4qOjGts9GEiWC9Eya//z8rSNR0fLV9M4=
kusionstack.io/kube-api v0.7.4-0.20250902064055-250905b1fce5/go.mod h1:e1jtrQH2LK5fD2nTyfIXG6nYrYbU8VXShRxTRwVPaLk=
kusionstack.io/kube-api v0.7.4-0.20250902065440-03af2146e073 h1:Kel/+qk5fFf9QQsqTJo7KP6PfL1FZNMRINpvjNRGRho=
kusionstack.io/kube-api v0.7.4-0.20250902065440-03af2146e073/go.mod h1:e1jtrQH2LK5fD2nTyfIXG6nYrYbU8VXShRxTRwVPaLk=
kusionstack.io/kube-api v0.7.4-0.20250902100032-7b62d7607345 h1:SBfFLyJR2qRh19/qlC45iGZlMnnTAkKWmXtHrIlJFc8=
kusionstack.io/kube-api v0.7.4-0.20250902100032-7b62d7607345/go.mod h1:e1jtrQH2LK5fD2nTyfIXG6nYrYbU8VXShRxTRwVPaLk=
kusionstack.io/kube-api v0.7.4-0.20250902122009-5447303fc5ee h1:s1X/0d8ryRzr6AQ1WwSZ1TKCrXsZzqYZSjEmwMRVju0=
kusionstack.io/kube-api v0.7.4-0.20250902122009-5447303fc5ee/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.2 h1:gf+c/LOMsiKoVR+GLzOomw8qcUbZbPckQLczZllNdVM=
kusionstack.io/resourceconsist v0.0.2/go.mod h1:4KKqnyCzTlUUQgAx7BlazLe+erMkAthTnspZOnc632M=
kusionstack.io/resourceconsist v0.0.4 h1:wRqLJuNh8O4TT6p0uOklFpHUKiRdRxcAH71Sw/q9LhE=
kusionstack.io/resourceconsist v0.0.4/go.mod h1:/mZWzD30euHSfEVx7WhzJO94+yONnqEwwYwV2EA8c0s=
modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw=
modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk=
modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k=
Expand Down
86 changes: 86 additions & 0 deletions pkg/controllers/rolloutrun/control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,92 @@ func (c *CanaryReleaseControl) applyCanaryDefaults(canaryObj client.Object) {
})
}

type RollbackReleaseControl struct {
workload workload.Accessor
control workload.RollbackReleaseControl
client client.Client
}

func NewRollbackReleaseControl(impl workload.Accessor, c client.Client) *RollbackReleaseControl {
return &RollbackReleaseControl{
workload: impl,
control: impl.(workload.RollbackReleaseControl),
client: c,
}
}

func (c *RollbackReleaseControl) Initialize(ctx context.Context, info *workload.Info, ownerKind, ownerName, rolloutRun string, batchIndex int32) error {
// pre-check
if !c.control.Rollbackable() {
return fmt.Errorf("workload is not support rollback")
}

if err := c.control.RollbackPreCheck(info.Object); err != nil {
return TerminalError(err)
}

// add progressing annotation
pInfo := rolloutv1alpha1.ProgressingInfo{
Kind: ownerKind,
RolloutName: ownerName,
RolloutID: rolloutRun,
Rollback: &rolloutv1alpha1.BatchProgressingInfo{
CurrentBatchIndex: batchIndex,
},
}
progress, _ := json.Marshal(pInfo)

_, err := info.UpdateOnConflict(ctx, c.client, func(obj client.Object) error {
utils.MutateAnnotations(obj, func(annotations map[string]string) {
annotations[rolloutapi.AnnoRolloutProgressingInfo] = string(progress)
})
return nil
})

return err
}

func (c *RollbackReleaseControl) Revert(ctx context.Context, info *workload.Info) error {
// pre-check
if !c.control.Rollbackable() {
return fmt.Errorf("workload is not support rollback")
}

if err := c.control.RollbackPreCheck(info.Object); err != nil {
return TerminalError(err)
}

_, err := info.UpdateOnConflict(ctx, c.client, func(obj client.Object) error {
return c.control.RevertRevision(ctx, c.client, obj)
})

return err
}

func (c *RollbackReleaseControl) UpdatePartition(ctx context.Context, info *workload.Info, expectedUpdated int32) (bool, error) {
ctx = clusterinfo.WithCluster(ctx, info.ClusterName)
obj := info.Object
return utils.UpdateOnConflict(ctx, c.client, c.client, obj, func() error {
return c.control.ApplyPartition(obj, expectedUpdated)
})
}

func (c *RollbackReleaseControl) Finalize(ctx context.Context, info *workload.Info) error {
// delete progressing annotation
changed, err := info.UpdateOnConflict(ctx, c.client, func(obj client.Object) error {
utils.MutateAnnotations(obj, func(annotations map[string]string) {
delete(annotations, rolloutapi.AnnoRolloutProgressingInfo)
})
return nil
})

if changed {
logger := logr.FromContextOrDiscard(ctx)
logger.Info("delete progressing info on workload", "name", info.Name, "gvk", info.GroupVersionKind.String())
}
return err
}

// TerminalError is an error that will not be retried but still be logged
// and recorded in metrics.
//
Expand Down
20 changes: 11 additions & 9 deletions pkg/controllers/rolloutrun/executor/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ package executor
import rolloutv1alpha1 "kusionstack.io/kube-api/rollout/v1alpha1"

const (
StepNone = rolloutv1alpha1.RolloutStepNone
StepPending = rolloutv1alpha1.RolloutStepPending
StepPreCanaryStepHook = rolloutv1alpha1.RolloutStepPreCanaryStepHook
StepPreBatchStepHook = rolloutv1alpha1.RolloutStepPreBatchStepHook
StepRunning = rolloutv1alpha1.RolloutStepRunning
StepPostCanaryStepHook = rolloutv1alpha1.RolloutStepPostCanaryStepHook
StepPostBatchStepHook = rolloutv1alpha1.RolloutStepPostBatchStepHook
StepSucceeded = rolloutv1alpha1.RolloutStepSucceeded
StepResourceRecycling = rolloutv1alpha1.RolloutStepResourceRecycling
StepNone = rolloutv1alpha1.RolloutStepNone
StepPending = rolloutv1alpha1.RolloutStepPending
StepPreCanaryStepHook = rolloutv1alpha1.RolloutStepPreCanaryStepHook
StepPreBatchStepHook = rolloutv1alpha1.RolloutStepPreBatchStepHook
StepPreRollbackStepHook = rolloutv1alpha1.RolloutStepPreRollbackStepHook
StepRunning = rolloutv1alpha1.RolloutStepRunning
StepPostCanaryStepHook = rolloutv1alpha1.RolloutStepPostCanaryStepHook
StepPostBatchStepHook = rolloutv1alpha1.RolloutStepPostBatchStepHook
StepPostRollbackStepHook = rolloutv1alpha1.RolloutStepPostRollbackStepHook
StepSucceeded = rolloutv1alpha1.RolloutStepSucceeded
StepResourceRecycling = rolloutv1alpha1.RolloutStepResourceRecycling
)
4 changes: 2 additions & 2 deletions pkg/controllers/rolloutrun/executor/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (e *batchExecutor) doBatchUpgrading(ctx *ExecutorContext) (bool, time.Durat
allWorkloadReady = false
logger.V(3).Info("still waiting for target to be ready", "target", item.CrossClusterObjectNameReference)

expectedReplicas, err := e.calculateExpectedReplicasBySlidingWindow(status, currentBatchExpectedReplicas, item.ReplicaSlidingWindow)
expectedReplicas, err := calculateExpectedReplicasBySlidingWindow(status, currentBatchExpectedReplicas, item.ReplicaSlidingWindow)
if err != nil {
return false, retryStop, err
}
Expand Down Expand Up @@ -250,7 +250,7 @@ func (e *batchExecutor) doBatchUpgrading(ctx *ExecutorContext) (bool, time.Durat
// calculateExpectedReplicasBySlidingWindow calculate expected replicas by sliding window
// if window is nil, return currentBatchExpectedReplicas
// if window is not nil, return min(currentBatchExpectedReplicas, updatedAvailableReplicas + increment)
func (e *batchExecutor) calculateExpectedReplicasBySlidingWindow(status rolloutv1alpha1.RolloutWorkloadStatus, currentBatchExpectedReplicas int32, window *intstr.IntOrString) (int32, error) {
func calculateExpectedReplicasBySlidingWindow(status rolloutv1alpha1.RolloutWorkloadStatus, currentBatchExpectedReplicas int32, window *intstr.IntOrString) (int32, error) {
if window == nil {
return currentBatchExpectedReplicas, nil
}
Expand Down
126 changes: 120 additions & 6 deletions pkg/controllers/rolloutrun/executor/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,28 @@ func (c *ExecutorContext) Initialize() {
newStatus.BatchStatus.Records = newStatus.BatchStatus.Records[:specBatchSize]
}
}

// init RollbackStatus
if c.RolloutRun.Spec.Rollback != nil {
if newStatus.RollbackStatus == nil {
newStatus.RollbackStatus = &rolloutv1alpha1.RolloutRunBatchStatus{}
}
// resize records
specBatchSize := len(c.RolloutRun.Spec.Rollback.Batches)
statusBatchSize := len(newStatus.RollbackStatus.Records)
if specBatchSize > statusBatchSize {
for i := 0; i < specBatchSize-statusBatchSize; i++ {
newStatus.RollbackStatus.Records = append(newStatus.RollbackStatus.Records,
rolloutv1alpha1.RolloutRunStepStatus{
Index: ptr.To(int32(statusBatchSize + i)),
State: StepNone,
},
)
}
} else if specBatchSize < statusBatchSize {
newStatus.RollbackStatus.Records = newStatus.RollbackStatus.Records[:specBatchSize]
}
}
})
}

Expand All @@ -107,7 +129,10 @@ func (c *ExecutorContext) GetWebhooksAndLatestStatusBy(hookType rolloutv1alpha1.
return nil, nil
}
var webhookStatuses []rolloutv1alpha1.RolloutWebhookStatus
if c.inCanary() {
if c.inRollback() {
index := newStatus.RollbackStatus.CurrentBatchIndex
webhookStatuses = newStatus.RollbackStatus.Records[index].Webhooks
} else if c.inCanary() {
webhookStatuses = newStatus.CanaryStatus.Webhooks
} else {
index := newStatus.BatchStatus.CurrentBatchIndex
Expand All @@ -127,7 +152,10 @@ func (c *ExecutorContext) SetWebhookStatus(status rolloutv1alpha1.RolloutWebhook
c.Initialize()

newStatus := c.NewStatus
if c.inCanary() {
if c.inRollback() {
index := newStatus.RollbackStatus.CurrentBatchIndex
newStatus.RollbackStatus.Records[index].Webhooks = appendWebhookStatus(newStatus.RollbackStatus.Records[index].Webhooks, status)
} else if c.inCanary() {
newStatus.CanaryStatus.Webhooks = appendWebhookStatus(newStatus.CanaryStatus.Webhooks, status)
} else {
index := newStatus.BatchStatus.CurrentBatchIndex
Expand All @@ -140,7 +168,9 @@ func isFinalStepState(state rolloutv1alpha1.RolloutStepState) bool {
}

func (c *ExecutorContext) GetCurrentState() (string, rolloutv1alpha1.RolloutStepState) {
if c.inCanary() {
if c.inRollback() {
return "rollback", c.NewStatus.RollbackStatus.CurrentBatchState
} else if c.inCanary() {
return "canary", c.NewStatus.CanaryStatus.State
} else {
return "batch", c.NewStatus.BatchStatus.CurrentBatchState
Expand All @@ -151,7 +181,16 @@ func (c *ExecutorContext) MoveToNextState(nextState rolloutv1alpha1.RolloutStepS
c.Initialize()

newStatus := c.NewStatus
if c.inCanary() {
if c.inRollback() {
index := newStatus.RollbackStatus.CurrentBatchIndex
newStatus.RollbackStatus.CurrentBatchState = nextState
newStatus.RollbackStatus.Records[index].State = nextState
if nextState == StepPreRollbackStepHook {
newStatus.RollbackStatus.Records[index].StartTime = ptr.To(metav1.Now())
} else if isFinalStepState(nextState) {
newStatus.RollbackStatus.Records[index].FinishTime = ptr.To(metav1.Now())
}
} else if c.inCanary() {
newStatus.CanaryStatus.State = nextState
if nextState == StepPreCanaryStepHook {
newStatus.CanaryStatus.StartTime = ptr.To(metav1.Now())
Expand All @@ -174,7 +213,22 @@ func (c *ExecutorContext) SkipCurrentRelease() {
c.Initialize()

newStatus := c.NewStatus
if c.inCanary() {
if c.inRollback() {
newStatus.RollbackStatus.CurrentBatchIndex = int32(len(c.RolloutRun.Spec.Rollback.Batches) - 1)
newStatus.RollbackStatus.CurrentBatchState = StepSucceeded
for i := range newStatus.RollbackStatus.Records {
if newStatus.RollbackStatus.Records[i].State == StepNone ||
newStatus.RollbackStatus.Records[i].State == StepPending {
newStatus.RollbackStatus.Records[i].State = StepSucceeded
}
if newStatus.RollbackStatus.Records[i].StartTime == nil {
newStatus.RollbackStatus.Records[i].StartTime = ptr.To(metav1.Now())
}
if newStatus.RollbackStatus.Records[i].FinishTime == nil {
newStatus.RollbackStatus.Records[i].FinishTime = ptr.To(metav1.Now())
}
}
} else if c.inCanary() {
newStatus.CanaryStatus.State = StepSucceeded
if newStatus.CanaryStatus.StartTime == nil {
newStatus.CanaryStatus.StartTime = ptr.To(metav1.Now())
Expand Down Expand Up @@ -258,6 +312,51 @@ func (r *ExecutorContext) inCanary() bool {
return false
}

func (r *ExecutorContext) inBatchGray() bool {
// todo: need to consider case of every batch gray
r.Initialize()
run := r.RolloutRun
newStatus := r.NewStatus
if newStatus.BatchStatus == nil {
return false
}

currentBatchIndex := newStatus.BatchStatus.CurrentBatchIndex
currentBatch := run.Spec.Batch.Batches[currentBatchIndex]
if currentBatch.Traffic == nil || int(currentBatchIndex+1) == len(run.Spec.Batch.Batches) {
return false
}

currentBatchState := newStatus.BatchStatus.CurrentBatchState
if !isFinalStepState(currentBatchState) {
return true
}

if int(currentBatchIndex+1) < len(run.Spec.Batch.Batches) {
nextBatch := run.Spec.Batch.Batches[currentBatchIndex+1]
if nextBatch.Traffic != nil {
return true
}
}

return false
}

func (r *ExecutorContext) inRollback() bool {
r.Initialize()
run := r.RolloutRun
newStatus := r.NewStatus
if newStatus.RollbackStatus == nil {
return false
}
if run.Spec.Rollback != nil && len(run.Spec.Rollback.Batches) > 0 {
if newStatus.Phase != rolloutv1alpha1.RolloutRunPhaseRollbacked {
return true
}
}
return false
}

func (r *ExecutorContext) makeRolloutWebhookReview(hookType rolloutv1alpha1.HookType, webhook rolloutv1alpha1.RolloutWebhook) rolloutv1alpha1.RolloutWebhookReview {
r.Initialize()

Expand All @@ -279,7 +378,13 @@ func (r *ExecutorContext) makeRolloutWebhookReview(hookType rolloutv1alpha1.Hook
},
}

if r.inCanary() {
if r.inRollback() {
review.Spec.Rollback = &rolloutv1alpha1.RolloutWebhookReviewBatch{
BatchIndex: newStatus.RollbackStatus.CurrentBatchIndex,
Targets: rolloutRun.Spec.Rollback.Batches[newStatus.RollbackStatus.CurrentBatchIndex].Targets,
Properties: rolloutRun.Spec.Rollback.Batches[newStatus.RollbackStatus.CurrentBatchIndex].Properties,
}
} else if r.inCanary() {
review.Spec.Canary = &rolloutv1alpha1.RolloutWebhookReviewCanary{
Targets: rolloutRun.Spec.Canary.Targets,
Properties: rolloutRun.Spec.Canary.Properties,
Expand Down Expand Up @@ -322,3 +427,12 @@ func (e *ExecutorContext) GetBatchLogger() logr.Logger {
func (e *ExecutorContext) GetCanaryLogger() logr.Logger {
return e.GetLogger().WithValues("step", "canary")
}

func (e *ExecutorContext) GetRollbackLogger() logr.Logger {
e.Initialize()
l := e.GetLogger().WithValues("step", "rollback")
if e.NewStatus != nil && e.NewStatus.RollbackStatus != nil {
l = l.WithValues("rollbackIndex", e.NewStatus.RollbackStatus.CurrentBatchIndex)
}
return l
}
Loading