Skip to content

Commit

Permalink
enhance pod scaling efficiency (#81)
Browse files Browse the repository at this point in the history
Signed-off-by: ChrisLiu <[email protected]>
  • Loading branch information
chrisliu1995 authored Jul 12, 2023
1 parent 2be1717 commit 0e6708d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/controllers/gameserverset/gameserverset_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ func (manager *GameServerSetManager) IsNeedToScale() bool {
gss := manager.gameServerSet
asts := manager.asts

// workload is reconciling its replicas, don't interrupt
if asts.Status.Replicas != *asts.Spec.Replicas {
return false
}

// no need to scale
return !(*gss.Spec.Replicas == *asts.Spec.Replicas &&
util.IsSliceEqual(util.StringToIntSlice(gss.GetAnnotations()[gameKruiseV1alpha1.GameServerSetReserveIdsKey], ","), gss.Spec.ReserveGameServerIds))
Expand All @@ -93,11 +88,16 @@ func (manager *GameServerSetManager) IsNeedToScale() bool {
func (manager *GameServerSetManager) GameServerScale() error {
gss := manager.gameServerSet
asts := manager.asts
gsList := manager.podList
c := manager.client
ctx := context.Background()
var podList []corev1.Pod
for _, pod := range manager.podList {
if pod.GetDeletionTimestamp() == nil {
podList = append(podList, pod)
}
}

currentReplicas := len(gsList)
currentReplicas := len(podList)
expectedReplicas := int(*gss.Spec.Replicas)
as := gss.GetAnnotations()
reserveIds := util.StringToIntSlice(as[gameKruiseV1alpha1.GameServerSetReserveIdsKey], ",")
Expand All @@ -107,7 +107,7 @@ func (manager *GameServerSetManager) GameServerScale() error {
klog.Infof("GameServers %s/%s already has %d replicas, expect to have %d replicas.", gss.GetNamespace(), gss.GetName(), currentReplicas, expectedReplicas)
manager.eventRecorder.Eventf(gss, corev1.EventTypeNormal, ScaleReason, "scale from %d to %d", currentReplicas, expectedReplicas)

newReserveIds := computeToScaleGs(gssReserveIds, reserveIds, notExistIds, expectedReplicas, gsList, gss.Spec.ScaleStrategy.ScaleDownStrategyType)
newReserveIds := computeToScaleGs(gssReserveIds, reserveIds, notExistIds, expectedReplicas, podList, gss.Spec.ScaleStrategy.ScaleDownStrategyType)
asts.Spec.ReserveOrdinals = newReserveIds
asts.Spec.Replicas = gss.Spec.Replicas
asts.Spec.ScaleStrategy = &kruiseV1beta1.StatefulSetScaleStrategy{
Expand Down

0 comments on commit 0e6708d

Please sign in to comment.