diff --git a/cluster-autoscaler/expander/grpcplugin/grpc_client.go b/cluster-autoscaler/expander/grpcplugin/grpc_client.go index b31de9fa4020..ddb6243b0986 100644 --- a/cluster-autoscaler/expander/grpcplugin/grpc_client.go +++ b/cluster-autoscaler/expander/grpcplugin/grpc_client.go @@ -96,6 +96,10 @@ func (g *grpcclientstrategy) BestOptions(expansionOptions []expander.Option, nod klog.V(4).Info("GRPC returned nil bestOptions, no options filtered") return expansionOptions } + if len(bestOptionsResponse.Options) == 0 { + // best options is intentionally empty + return nil + } // Transform back options slice options := transformAndSanitizeOptionsFromGRPC(bestOptionsResponse.Options, nodeGroupIDOptionMap) if options == nil { diff --git a/cluster-autoscaler/expander/grpcplugin/grpc_client_test.go b/cluster-autoscaler/expander/grpcplugin/grpc_client_test.go index 65b94a17d54b..5c0c800c4de6 100644 --- a/cluster-autoscaler/expander/grpcplugin/grpc_client_test.go +++ b/cluster-autoscaler/expander/grpcplugin/grpc_client_test.go @@ -197,6 +197,31 @@ func TestBestOptionsValid(t *testing.T) { assert.Equal(t, resp, []expander.Option{eoT3Large}) } +func TestBestOptionsEmpty(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + mockClient := mocks.NewMockExpanderClient(ctrl) + g := &grpcclientstrategy{mockClient} + + nodeInfos := makeFakeNodeInfos() + grpcNodeInfoMap := make(map[string]*v1.Node) + for i, opt := range options { + grpcNodeInfoMap[opt.NodeGroup.Id()] = nodes[i] + } + expectedBestOptionsReq := &protos.BestOptionsRequest{ + Options: []*protos.Option{&grpcEoT2Micro, &grpcEoT2Large, &grpcEoT3Large, &grpcEoM44XLarge}, + NodeMap: grpcNodeInfoMap, + } + + mockClient.EXPECT().BestOptions( + gomock.Any(), gomock.Eq(expectedBestOptionsReq), + ).Return(&protos.BestOptionsResponse{Options: []*protos.Option{}}, nil) + + resp := g.BestOptions(options, nodeInfos) + + assert.Empty(t, resp) +} + // All test cases should error, and no options should be filtered func TestBestOptionsErrors(t *testing.T) { ctrl := gomock.NewController(t)