Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import (
"context"
"fmt"
"reflect"
"time"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/durationpb"

apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -388,8 +390,13 @@ func (w *Wrapper) NodeGroupTemplateNodeInfo(_ context.Context, req *protos.NodeG
}
return nil, err
}
infoBytes, err := info.Node().Marshal()
if err != nil {
return nil, err
}
return &protos.NodeGroupTemplateNodeInfoResponse{
NodeInfo: info.Node(),
NodeInfo: info.Node(),
NodeBytes: infoBytes,
}, nil
}

Expand All @@ -406,12 +413,37 @@ func (w *Wrapper) NodeGroupGetOptions(_ context.Context, req *protos.NodeGroupAu
if pbDefaults == nil {
return nil, fmt.Errorf("request fields were nil")
}

var scaleDownUnneededTime time.Duration
if d := pbDefaults.GetScaleDownUnneededDuration(); d != nil {
scaleDownUnneededTime = d.AsDuration()
} else {
// fall back to deprecated field removed in 1.35
scaleDownUnneededTime = pbDefaults.GetScaleDownUnneededTime().Duration
}

var scaleDownUnreadyTime time.Duration
if d := pbDefaults.GetScaleDownUnreadyDuration(); d != nil {
scaleDownUnreadyTime = d.AsDuration()
} else {
// fall back to deprecated field removed in 1.35
scaleDownUnreadyTime = pbDefaults.GetScaleDownUnreadyTime().Duration
}

var maxNodeProvisionTime time.Duration
if d := pbDefaults.GetMaxNodeProvisionDuration(); d != nil {
maxNodeProvisionTime = d.AsDuration()
} else {
// fall back to deprecated field removed in 1.35
maxNodeProvisionTime = pbDefaults.GetMaxNodeProvisionTime().Duration
}

defaults := config.NodeGroupAutoscalingOptions{
ScaleDownUtilizationThreshold: pbDefaults.GetScaleDownGpuUtilizationThreshold(),
ScaleDownGpuUtilizationThreshold: pbDefaults.GetScaleDownGpuUtilizationThreshold(),
ScaleDownUnneededTime: pbDefaults.GetScaleDownUnneededTime().Duration,
ScaleDownUnreadyTime: pbDefaults.GetScaleDownUnneededTime().Duration,
MaxNodeProvisionTime: pbDefaults.GetMaxNodeProvisionTime().Duration,
ScaleDownUnneededTime: scaleDownUnneededTime,
ScaleDownUnreadyTime: scaleDownUnreadyTime,
MaxNodeProvisionTime: maxNodeProvisionTime,
ZeroOrMaxNodeScaling: pbDefaults.GetZeroOrMaxNodeScaling(),
IgnoreDaemonSetsUtilization: pbDefaults.GetIgnoreDaemonSetsUtilization(),
}
Expand All @@ -438,6 +470,9 @@ func (w *Wrapper) NodeGroupGetOptions(_ context.Context, req *protos.NodeGroupAu
MaxNodeProvisionTime: &metav1.Duration{
Duration: opts.MaxNodeProvisionTime,
},
ScaleDownUnneededDuration: durationpb.New(opts.ScaleDownUnneededTime),
ScaleDownUnreadyDuration: durationpb.New(opts.ScaleDownUnreadyTime),
MaxNodeProvisionDuration: durationpb.New(opts.MaxNodeProvisionTime),
ZeroOrMaxNodeScaling: opts.ZeroOrMaxNodeScaling,
IgnoreDaemonSetsUtilization: opts.IgnoreDaemonSetsUtilization,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/durationpb"

apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
Expand Down Expand Up @@ -227,7 +229,16 @@ func (n *NodeGroup) TemplateNodeInfo() (*framework.NodeInfo, error) {
klog.V(1).Infof("Error on gRPC call NodeGroupTemplateNodeInfo: %v", err)
return nil, err
}
pbNodeInfo := res.GetNodeInfo()
var pbNodeInfo *apiv1.Node
if pbNodeBytes := res.GetNodeBytes(); pbNodeBytes != nil {
pbNodeInfo = &apiv1.Node{}
if err := pbNodeInfo.Unmarshal(pbNodeBytes); err != nil {
return nil, err
}
} else {
// Fall back to deprecated field removed in 1.35
pbNodeInfo = res.GetNodeInfo()
}
if pbNodeInfo == nil {
n.nodeInfo = new(*framework.NodeInfo)
return nil, nil
Expand Down Expand Up @@ -283,6 +294,9 @@ func (n *NodeGroup) GetOptions(defaults config.NodeGroupAutoscalingOptions) (*co
MaxNodeProvisionTime: &metav1.Duration{
Duration: defaults.MaxNodeProvisionTime,
},
ScaleDownUnneededDuration: durationpb.New(defaults.ScaleDownUnneededTime),
ScaleDownUnreadyDuration: durationpb.New(defaults.ScaleDownUnreadyTime),
MaxNodeProvisionDuration: durationpb.New(defaults.MaxNodeProvisionTime),
ZeroOrMaxNodeScaling: defaults.ZeroOrMaxNodeScaling,
IgnoreDaemonSetsUtilization: defaults.IgnoreDaemonSetsUtilization,
},
Expand All @@ -299,12 +313,37 @@ func (n *NodeGroup) GetOptions(defaults config.NodeGroupAutoscalingOptions) (*co
if pbOpts == nil {
return nil, nil
}

var scaleDownUnneededTime time.Duration
if d := pbOpts.GetScaleDownUnneededDuration(); d != nil {
scaleDownUnneededTime = d.AsDuration()
} else {
// fall back to deprecated field removed in 1.35
scaleDownUnneededTime = pbOpts.GetScaleDownUnneededTime().Duration
}

var scaleDownUnreadyTime time.Duration
if d := pbOpts.GetScaleDownUnreadyDuration(); d != nil {
scaleDownUnreadyTime = d.AsDuration()
} else {
// fall back to deprecated field removed in 1.35
scaleDownUnreadyTime = pbOpts.GetScaleDownUnreadyTime().Duration
}

var maxNodeProvisionTime time.Duration
if d := pbOpts.GetMaxNodeProvisionDuration(); d != nil {
maxNodeProvisionTime = d.AsDuration()
} else {
// fall back to deprecated field removed in 1.35
maxNodeProvisionTime = pbOpts.GetMaxNodeProvisionTime().Duration
}

opts := &config.NodeGroupAutoscalingOptions{
ScaleDownUtilizationThreshold: pbOpts.GetScaleDownUtilizationThreshold(),
ScaleDownGpuUtilizationThreshold: pbOpts.GetScaleDownGpuUtilizationThreshold(),
ScaleDownUnneededTime: pbOpts.GetScaleDownUnneededTime().Duration,
ScaleDownUnreadyTime: pbOpts.GetScaleDownUnreadyTime().Duration,
MaxNodeProvisionTime: pbOpts.GetMaxNodeProvisionTime().Duration,
ScaleDownUnneededTime: scaleDownUnneededTime,
ScaleDownUnreadyTime: scaleDownUnreadyTime,
MaxNodeProvisionTime: maxNodeProvisionTime,
ZeroOrMaxNodeScaling: pbOpts.GetZeroOrMaxNodeScaling(),
IgnoreDaemonSetsUtilization: pbOpts.GetIgnoreDaemonSetsUtilization(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"github.com/stretchr/testify/mock"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/durationpb"

apiv1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
Expand Down Expand Up @@ -124,17 +126,20 @@ func TestCloudProvider_TemplateNodeInfo(t *testing.T) {
// test correct call
apiv1Node1 := &apiv1.Node{}
apiv1Node1.Name = "node1"
apiv1Node1Bytes, _ := apiv1Node1.Marshal()

apiv1Node2 := &apiv1.Node{}
apiv1Node2.Name = "node2"
apiv1Node2Bytes, _ := apiv1Node2.Marshal()

m.On(
"NodeGroupTemplateNodeInfo", mock.Anything, mock.MatchedBy(func(req *protos.NodeGroupTemplateNodeInfoRequest) bool {
return req.Id == "nodeGroup1"
}),
).Return(
&protos.NodeGroupTemplateNodeInfoResponse{
NodeInfo: apiv1Node1,
NodeInfo: apiv1Node1,
NodeBytes: apiv1Node1Bytes,
}, nil,
).Once()

Expand All @@ -144,7 +149,8 @@ func TestCloudProvider_TemplateNodeInfo(t *testing.T) {
}),
).Return(
&protos.NodeGroupTemplateNodeInfoResponse{
NodeInfo: apiv1Node2,
NodeInfo: apiv1Node2,
NodeBytes: apiv1Node2Bytes,
}, nil,
).Once()

Expand Down Expand Up @@ -181,7 +187,8 @@ func TestCloudProvider_TemplateNodeInfo(t *testing.T) {
}),
).Return(
&protos.NodeGroupTemplateNodeInfoResponse{
NodeInfo: nil,
NodeInfo: nil,
NodeBytes: nil,
}, nil,
).Once()

Expand All @@ -202,7 +209,8 @@ func TestCloudProvider_TemplateNodeInfo(t *testing.T) {
}),
).Return(
&protos.NodeGroupTemplateNodeInfoResponse{
NodeInfo: nil,
NodeInfo: nil,
NodeBytes: nil,
},
fmt.Errorf("mock error"),
).Once()
Expand All @@ -223,7 +231,8 @@ func TestCloudProvider_TemplateNodeInfo(t *testing.T) {
}),
).Return(
&protos.NodeGroupTemplateNodeInfoResponse{
NodeInfo: nil,
NodeInfo: nil,
NodeBytes: nil,
},
status.Error(codes.Unimplemented, "mock error"),
).Once()
Expand Down Expand Up @@ -257,6 +266,9 @@ func TestCloudProvider_GetOptions(t *testing.T) {
ScaleDownUnneededTime: &v1.Duration{Duration: time.Minute},
ScaleDownUnreadyTime: &v1.Duration{Duration: time.Hour},
MaxNodeProvisionTime: &v1.Duration{Duration: time.Minute},
ScaleDownUnneededDuration: durationpb.New(time.Minute),
ScaleDownUnreadyDuration: durationpb.New(time.Hour),
MaxNodeProvisionDuration: durationpb.New(time.Minute),
ZeroOrMaxNodeScaling: true,
IgnoreDaemonSetsUtilization: true,
},
Expand Down Expand Up @@ -365,6 +377,9 @@ func TestCloudProvider_GetOptions(t *testing.T) {
ScaleDownUnneededTime: &v1.Duration{Duration: time.Minute},
ScaleDownUnreadyTime: &v1.Duration{Duration: time.Hour},
MaxNodeProvisionTime: &v1.Duration{Duration: time.Minute},
ScaleDownUnneededDuration: durationpb.New(time.Minute),
ScaleDownUnreadyDuration: durationpb.New(time.Hour),
MaxNodeProvisionDuration: durationpb.New(time.Minute),
},
},
nil,
Expand Down
Loading
Loading