Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
feat: add useBeta strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlie17Li committed Sep 25, 2023
1 parent 68bd0dd commit 2c789cb
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"
"strconv"
"sync"
"time"

v1 "k8s.io/api/apps/v1"
Expand All @@ -30,7 +29,6 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/workqueue"
"k8s.io/utils/pointer"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -46,10 +44,7 @@ import (
// ModuleDeploymentReconciler reconciles a ModuleDeployment object
type ModuleDeploymentReconciler struct {
client.Client
Scheme *runtime.Scheme
DelayingQueue workqueue.DelayingInterface
Set map[string][]int32
mutex sync.Mutex
Scheme *runtime.Scheme
}

//+kubebuilder:rbac:groups=serverless.alipay.com,resources=moduledeployments,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -367,9 +362,15 @@ func (r *ModuleDeploymentReconciler) updateModuleReplicaSet(moduleDeployment *mo
return ctrl.Result{}, r.Status().Update(ctx, moduleDeployment)
}

replicas := curBatch * (moduleDeployment.Spec.Replicas / batchCount)
if curBatch == batchCount { // is the last batch
replicas := int32(0)
// use beta strategy
if batchCount != 1 && curBatch == 1 && moduleDeployment.Spec.OperationStrategy.UseBeta {
replicas = 1
} else if curBatch == batchCount { // if it's the last batch
replicas = expReplicas
} else {
// ceil: if moduleDeployment.Spec.Replicas = 5, batchCount = 3, then each batch is 2
replicas = curBatch * ((moduleDeployment.Spec.Replicas + batchCount - 1) / batchCount)
}

err := r.updateModuleReplicas(ctx, replicas, moduleDeployment, newRS, oldRSs)
Expand All @@ -380,8 +381,7 @@ func (r *ModuleDeploymentReconciler) updateModuleReplicaSet(moduleDeployment *mo
moduleDeployment.Status.ReleaseStatus.CurrentBatch += 1
moduleDeployment.Status.ReleaseStatus.LastTransitionTime = metav1.Now()

var grayTime = 0

var grayTime int
if moduleDeployment.Spec.OperationStrategy.NeedConfirm {
moduleDeployment.Status.ReleaseStatus.Progress = moduledeploymentv1alpha1.ModuleDeploymentReleaseProgressWaitingForConfirmation
} else if grayTime = int(moduleDeployment.Spec.OperationStrategy.GrayTimeBetweenBatchSeconds); grayTime != 0 {
Expand Down

0 comments on commit 2c789cb

Please sign in to comment.