Fix the issue of unable to complete scaling down from 1 to 0.

This commit is contained in:
smartwang 2023-05-29 17:13:56 +08:00 committed by GitHub
parent 543e02a413
commit 66598607c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 4 deletions

View File

@ -16,10 +16,24 @@ type ExternalScaler struct {
func (e *ExternalScaler) mustEmbedUnimplementedExternalScalerServer() {
}
func (e *ExternalScaler) IsActive(ctx context.Context, scaledObject *ScaledObjectRef) (*IsActiveResponse, error) {
return &IsActiveResponse{
Result: true,
}, nil
func (e *ExternalScaler) IsActive(ctx context.Context, scaledObjectRef *ScaledObjectRef) (*IsActiveResponse, error) {
name := scaledObjectRef.GetName()
ns := scaledObjectRef.GetNamespace()
gss := &gamekruiseiov1alpha1.GameServerSet{}
err := e.client.Get(ctx, types.NamespacedName{Namespace: ns, Name: name}, gss)
if err != nil {
klog.Error(err)
return nil, err
}
currentReplicas := gss.Status.CurrentReplicas
numWaitToBeDeleted := gss.Status.WaitToBeDeletedReplicas
if numWaitToBeDeleted == nil {
return nil, fmt.Errorf("GameServerSet %s/%s has not inited", ns, name)
}
desireReplicas := currentReplicas - *numWaitToBeDeleted
return &IsActiveResponse{
Result: desireReplicas > 0,
}, nil
}
func (e *ExternalScaler) StreamIsActive(scaledObject *ScaledObjectRef, epsServer ExternalScaler_StreamIsActiveServer) error {