Skip to content

Commit 7b69964

Browse files
authored
Merge pull request #7973 from jincong8973/master
feat: add ignoreDaemonSetsUtilization and zeroOrMaxNodeScaling to NodeGroupAutoscalingOptions
2 parents 2ca5b44 + e713b51 commit 7b69964

File tree

7 files changed

+565
-1322
lines changed

7 files changed

+565
-1322
lines changed

cluster-autoscaler/cloudprovider/externalgrpc/README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ go install google.golang.org/protobuf/cmd/[email protected]
6161
go install google.golang.org/grpc/cmd/[email protected]
6262
```
6363

64-
2. generate gRPC client and server code:
64+
2. import proto dependencies using go modules
65+
```bash
66+
go mod vendor
67+
```
68+
69+
3. generate gRPC client and server code:
6570

6671
```bash
6772
protoc \

cluster-autoscaler/cloudprovider/externalgrpc/examples/external-grpc-cloud-provider-service/wrapper/wrapper.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (w *Wrapper) NodeGroupForNode(_ context.Context, req *protos.NodeGroupForNo
103103
// Checks if ng is nil interface or contains nil value
104104
if ng == nil || reflect.ValueOf(ng).IsNil() {
105105
return &protos.NodeGroupForNodeResponse{
106-
NodeGroup: &protos.NodeGroup{}, //NodeGroup with id = "", meaning the node should not be processed by cluster autoscaler
106+
NodeGroup: &protos.NodeGroup{}, // NodeGroup with id = "", meaning the node should not be processed by cluster autoscaler
107107
}, nil
108108
}
109109
return &protos.NodeGroupForNodeResponse{
@@ -365,6 +365,8 @@ func (w *Wrapper) NodeGroupGetOptions(_ context.Context, req *protos.NodeGroupAu
365365
ScaleDownUnneededTime: pbDefaults.GetScaleDownUnneededTime().Duration,
366366
ScaleDownUnreadyTime: pbDefaults.GetScaleDownUnneededTime().Duration,
367367
MaxNodeProvisionTime: pbDefaults.GetMaxNodeProvisionTime().Duration,
368+
ZeroOrMaxNodeScaling: pbDefaults.GetZeroOrMaxNodeScaling(),
369+
IgnoreDaemonSetsUtilization: pbDefaults.GetIgnoreDaemonSetsUtilization(),
368370
}
369371
opts, err := ng.GetOptions(defaults)
370372
if err != nil {
@@ -374,7 +376,7 @@ func (w *Wrapper) NodeGroupGetOptions(_ context.Context, req *protos.NodeGroupAu
374376
return nil, err
375377
}
376378
if opts == nil {
377-
return nil, fmt.Errorf("GetOptions not implemented") //make this explicitly so that grpc response is discarded
379+
return nil, fmt.Errorf("GetOptions not implemented") // make this explicitly so that grpc response is discarded
378380
}
379381
return &protos.NodeGroupAutoscalingOptionsResponse{
380382
NodeGroupAutoscalingOptions: &protos.NodeGroupAutoscalingOptions{
@@ -389,6 +391,8 @@ func (w *Wrapper) NodeGroupGetOptions(_ context.Context, req *protos.NodeGroupAu
389391
MaxNodeProvisionTime: &metav1.Duration{
390392
Duration: opts.MaxNodeProvisionTime,
391393
},
394+
ZeroOrMaxNodeScaling: opts.ZeroOrMaxNodeScaling,
395+
IgnoreDaemonSetsUtilization: opts.IgnoreDaemonSetsUtilization,
392396
},
393397
}, nil
394398
}

cluster-autoscaler/cloudprovider/externalgrpc/externalgrpc_node_group.go

+4
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ func (n *NodeGroup) GetOptions(defaults config.NodeGroupAutoscalingOptions) (*co
283283
MaxNodeProvisionTime: &metav1.Duration{
284284
Duration: defaults.MaxNodeProvisionTime,
285285
},
286+
ZeroOrMaxNodeScaling: defaults.ZeroOrMaxNodeScaling,
287+
IgnoreDaemonSetsUtilization: defaults.IgnoreDaemonSetsUtilization,
286288
},
287289
})
288290
if err != nil {
@@ -303,6 +305,8 @@ func (n *NodeGroup) GetOptions(defaults config.NodeGroupAutoscalingOptions) (*co
303305
ScaleDownUnneededTime: pbOpts.GetScaleDownUnneededTime().Duration,
304306
ScaleDownUnreadyTime: pbOpts.GetScaleDownUnreadyTime().Duration,
305307
MaxNodeProvisionTime: pbOpts.GetMaxNodeProvisionTime().Duration,
308+
ZeroOrMaxNodeScaling: pbOpts.GetZeroOrMaxNodeScaling(),
309+
IgnoreDaemonSetsUtilization: pbOpts.GetIgnoreDaemonSetsUtilization(),
306310
}
307311
return opts, nil
308312
}

cluster-autoscaler/cloudprovider/externalgrpc/externalgrpc_node_group_test.go

+46-3
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func TestCloudProvider_GetOptions(t *testing.T) {
244244
client, m, teardown := setupTest(t)
245245
defer teardown()
246246

247-
// test correct call
247+
// test correct call, NodeGroupAutoscalingOptionsResponse will override default options
248248
m.On(
249249
"NodeGroupGetOptions", mock.Anything, mock.MatchedBy(func(req *protos.NodeGroupAutoscalingOptionsRequest) bool {
250250
return req.Id == "nodeGroup1"
@@ -257,6 +257,8 @@ func TestCloudProvider_GetOptions(t *testing.T) {
257257
ScaleDownUnneededTime: &v1.Duration{Duration: time.Minute},
258258
ScaleDownUnreadyTime: &v1.Duration{Duration: time.Hour},
259259
MaxNodeProvisionTime: &v1.Duration{Duration: time.Minute},
260+
ZeroOrMaxNodeScaling: true,
261+
IgnoreDaemonSetsUtilization: true,
260262
},
261263
},
262264
nil,
@@ -267,12 +269,15 @@ func TestCloudProvider_GetOptions(t *testing.T) {
267269
client: client,
268270
grpcTimeout: defaultGRPCTimeout,
269271
}
272+
270273
defaultsOpts := config.NodeGroupAutoscalingOptions{
271274
ScaleDownUtilizationThreshold: 0.6,
272275
ScaleDownGpuUtilizationThreshold: 0.7,
273276
ScaleDownUnneededTime: time.Minute,
274277
ScaleDownUnreadyTime: time.Hour,
275278
MaxNodeProvisionTime: time.Minute,
279+
ZeroOrMaxNodeScaling: false,
280+
IgnoreDaemonSetsUtilization: false,
276281
}
277282

278283
opts, err := ng1.GetOptions(defaultsOpts)
@@ -282,16 +287,20 @@ func TestCloudProvider_GetOptions(t *testing.T) {
282287
assert.Equal(t, time.Minute, opts.ScaleDownUnneededTime)
283288
assert.Equal(t, time.Hour, opts.ScaleDownUnreadyTime)
284289
assert.Equal(t, time.Minute, opts.MaxNodeProvisionTime)
290+
assert.Equal(t, true, opts.ZeroOrMaxNodeScaling)
291+
assert.Equal(t, true, opts.IgnoreDaemonSetsUtilization)
285292

286293
// test grpc error
287294
m.On(
288295
"NodeGroupGetOptions", mock.Anything, mock.MatchedBy(func(req *protos.NodeGroupAutoscalingOptionsRequest) bool {
289296
return req.Id == "nodeGroup2"
290297
}),
291298
).Return(
292-
&protos.NodeGroupAutoscalingOptionsResponse{},
299+
&protos.NodeGroupAutoscalingOptionsResponse{
300+
NodeGroupAutoscalingOptions: &protos.NodeGroupAutoscalingOptions{},
301+
},
293302
fmt.Errorf("mock error"),
294-
)
303+
).Once()
295304

296305
ng2 := NodeGroup{
297306
id: "nodeGroup2",
@@ -343,6 +352,40 @@ func TestCloudProvider_GetOptions(t *testing.T) {
343352
assert.Error(t, err)
344353
assert.Equal(t, cloudprovider.ErrNotImplemented, err)
345354

355+
// test with default options
356+
m.On(
357+
"NodeGroupGetOptions", mock.Anything, mock.MatchedBy(func(req *protos.NodeGroupAutoscalingOptionsRequest) bool {
358+
return req.Id == "nodeGroup5"
359+
}),
360+
).Return(
361+
&protos.NodeGroupAutoscalingOptionsResponse{
362+
NodeGroupAutoscalingOptions: &protos.NodeGroupAutoscalingOptions{
363+
ScaleDownUtilizationThreshold: 0.6,
364+
ScaleDownGpuUtilizationThreshold: 0.7,
365+
ScaleDownUnneededTime: &v1.Duration{Duration: time.Minute},
366+
ScaleDownUnreadyTime: &v1.Duration{Duration: time.Hour},
367+
MaxNodeProvisionTime: &v1.Duration{Duration: time.Minute},
368+
},
369+
},
370+
nil,
371+
)
372+
373+
ng5 := NodeGroup{
374+
id: "nodeGroup5",
375+
client: client,
376+
grpcTimeout: defaultGRPCTimeout,
377+
}
378+
379+
opts, err = ng5.GetOptions(defaultsOpts)
380+
assert.NoError(t, err)
381+
assert.Equal(t, 0.6, opts.ScaleDownUtilizationThreshold)
382+
assert.Equal(t, 0.7, opts.ScaleDownGpuUtilizationThreshold)
383+
assert.Equal(t, time.Minute, opts.ScaleDownUnneededTime)
384+
assert.Equal(t, time.Hour, opts.ScaleDownUnreadyTime)
385+
assert.Equal(t, time.Minute, opts.MaxNodeProvisionTime)
386+
assert.Equal(t, false, opts.ZeroOrMaxNodeScaling)
387+
assert.Equal(t, false, opts.IgnoreDaemonSetsUtilization)
388+
346389
}
347390

348391
func TestCloudProvider_TargetSize(t *testing.T) {

0 commit comments

Comments
 (0)