Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add maxAvailable param for external scaler #190

Merged
merged 1 commit into from
Jan 7, 2025
Merged
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
19 changes: 16 additions & 3 deletions pkg/externalscaler/externalscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

const (
NoneGameServerMinNumberKey = "minAvailable"
NoneGameServerMaxNumberKey = "maxAvailable"
)

type ExternalScaler struct {
Expand Down Expand Up @@ -99,7 +100,7 @@ func (e *ExternalScaler) GetMetrics(ctx context.Context, metricRequest *GetMetri
}, nil
}

// scale up those GameServers with WaitToBeDeleted opsState
// scale down those GameServers with WaitToBeDeleted opsState
isWaitToDelete, _ := labels.NewRequirement(gamekruiseiov1alpha1.GameServerOpsStateKey, selection.Equals, []string{string(gamekruiseiov1alpha1.WaitToDelete)})
notDeleting, _ := labels.NewRequirement(gamekruiseiov1alpha1.GameServerStateKey, selection.NotEquals, []string{string(gamekruiseiov1alpha1.Deleting)})
podList = &corev1.PodList{}
Expand All @@ -118,12 +119,24 @@ func (e *ExternalScaler) GetMetrics(ctx context.Context, metricRequest *GetMetri

desireReplicas := int(*gss.Spec.Replicas)
numWaitToBeDeleted := len(podList.Items)
if numWaitToBeDeleted != 0 {
desireReplicas = desireReplicas - numWaitToBeDeleted
} else {
// scale down when number of GameServers with None opsState more than maxAvailable defined by user
maxNum, err := strconv.ParseInt(metricRequest.ScaledObjectRef.GetScalerMetadata()[NoneGameServerMaxNumberKey], 10, 32)
if err != nil {
klog.Errorf("maxAvailable should be integer type, err: %s", err.Error())
}
if err == nil && noneNum > int(maxNum) {
desireReplicas = (desireReplicas) + int(maxNum) - (noneNum)
}
}

klog.Infof("GameServerSet %s/%s desire replicas is %d", ns, name, desireReplicas-numWaitToBeDeleted)
klog.Infof("GameServerSet %s/%s desire replicas is %d", ns, name, desireReplicas)
return &GetMetricsResponse{
MetricValues: []*MetricValue{{
MetricName: "gssReplicas",
MetricValue: int64(desireReplicas - numWaitToBeDeleted),
MetricValue: int64(desireReplicas),
}},
}, nil
}
Expand Down
Loading