Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
aayushrangwala committed Sep 15, 2023
2 parents 1ac9f55 + 1a6b1e9 commit a707cdc
Show file tree
Hide file tree
Showing 478 changed files with 232,484 additions and 931 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@
Session.vim
.netrwhist

# Binary files
bin/
20 changes: 20 additions & 0 deletions cluster-autoscaler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,23 @@ test-in-docker: clean docker-builder
docker run ${RM_FLAG} -v `pwd`:/cluster-autoscaler/:Z autoscaling-builder:latest bash -c 'cd /cluster-autoscaler && go test -race ./... ${TAGS_FLAG}'

.PHONY: all build test-unit clean format execute-release dev-release docker-builder build-in-docker release generate push-image push-manifest

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

## Tool Binaries
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen

## Tool Versions
CONTROLLER_TOOLS_VERSION ?= v0.13.0

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

.PHONY: manifest
manifest: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd
1 change: 1 addition & 0 deletions cluster-autoscaler/cloudprovider/aws/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,4 @@ Please note: it is also possible to mount the cloud config file from host:
Otherwise, the `/latest/api/token` call will timeout and result in an error. See [AWS docs here](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html#configuring-instance-metadata-options) for further information.
- If you don't use EKS managed nodegroups, don't add the `eks:nodegroup-name` tag to the ASG as this will lead to extra EKS API calls that could slow down scaling when there are 0 nodes in the nodegroup.
- Set `AWS_MAX_ATTEMPTS` to configure max retries
- If you are running a private cluster in a VPC without certain VPC interfaces for AWS services, the CA might crash on startup due to failing to dynamically fetch supported EC2-instance types. To avoid this, add the argument `--aws-use-static-instance-list=true` to the CA startup command. For more information on private cluster requirements, see [AWS docs here](https://docs.aws.amazon.com/eks/latest/userguide/private-clusters.html).
2 changes: 2 additions & 0 deletions cluster-autoscaler/cloudprovider/aws/aws_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const (
autoDiscovererTypeASG = "asg"
asgAutoDiscovererKeyTag = "tag"
optionsTagsPrefix = "k8s.io/cluster-autoscaler/node-template/autoscaling-options/"
labelAwsCSITopologyZone = "topology.ebs.csi.aws.com/zone"
)

// AwsManager is handles aws communication and data caching.
Expand Down Expand Up @@ -416,6 +417,7 @@ func buildGenericLabels(template *asgTemplate, nodeName string) map[string]strin

result[apiv1.LabelTopologyRegion] = template.Region
result[apiv1.LabelTopologyZone] = template.Zone
result[labelAwsCSITopologyZone] = template.Zone
result[apiv1.LabelHostname] = nodeName
return result
}
Expand Down
5 changes: 4 additions & 1 deletion cluster-autoscaler/cloudprovider/aws/aws_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ func TestBuildGenericLabels(t *testing.T) {
Architecture: cloudprovider.DefaultArch,
},
Region: "us-east-1",
Zone: "us-east-1c",
}, "sillyname")
assert.Equal(t, "us-east-1", labels[apiv1.LabelZoneRegionStable])
assert.Equal(t, "us-east-1", labels[apiv1.LabelTopologyRegion])
assert.Equal(t, "us-east-1c", labels[apiv1.LabelTopologyZone])
assert.Equal(t, "us-east-1c", labels[labelAwsCSITopologyZone])
assert.Equal(t, "sillyname", labels[apiv1.LabelHostname])
assert.Equal(t, "c4.large", labels[apiv1.LabelInstanceTypeStable])
assert.Equal(t, cloudprovider.DefaultArch, labels[apiv1.LabelArchStable])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"context"
"fmt"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/anypb"
apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -113,6 +115,9 @@ func (w *Wrapper) PricingNodePrice(_ context.Context, req *protos.PricingNodePri

model, err := w.provider.Pricing()
if err != nil {
if err == cloudprovider.ErrNotImplemented {
return nil, status.Error(codes.Unimplemented, err.Error())
}
return nil, err
}
reqNode := req.GetNode()
Expand All @@ -136,6 +141,9 @@ func (w *Wrapper) PricingPodPrice(_ context.Context, req *protos.PricingPodPrice

model, err := w.provider.Pricing()
if err != nil {
if err == cloudprovider.ErrNotImplemented {
return nil, status.Error(codes.Unimplemented, err.Error())
}
return nil, err
}
reqPod := req.GetPod()
Expand Down Expand Up @@ -326,6 +334,9 @@ func (w *Wrapper) NodeGroupTemplateNodeInfo(_ context.Context, req *protos.NodeG
}
info, err := ng.TemplateNodeInfo()
if err != nil {
if err == cloudprovider.ErrNotImplemented {
return nil, status.Error(codes.Unimplemented, err.Error())
}
return nil, err
}
return &protos.NodeGroupTemplateNodeInfoResponse{
Expand Down Expand Up @@ -355,6 +366,9 @@ func (w *Wrapper) NodeGroupGetOptions(_ context.Context, req *protos.NodeGroupAu
}
opts, err := ng.GetOptions(defaults)
if err != nil {
if err == cloudprovider.ErrNotImplemented {
return nil, status.Error(codes.Unimplemented, err.Error())
}
return nil, err
}
if opts == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import (
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/status"
"gopkg.in/yaml.v2"
apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -158,6 +160,10 @@ func (m *pricingModel) NodePrice(node *apiv1.Node, startTime time.Time, endTime
EndTime: &end,
})
if err != nil {
st, ok := status.FromError(err)
if ok && st.Code() == codes.Unimplemented {
return 0, cloudprovider.ErrNotImplemented
}
klog.V(1).Infof("Error on gRPC call PricingNodePrice: %v", err)
return 0, err
}
Expand All @@ -178,6 +184,10 @@ func (m *pricingModel) PodPrice(pod *apiv1.Pod, startTime time.Time, endTime tim
EndTime: &end,
})
if err != nil {
st, ok := status.FromError(err)
if ok && st.Code() == codes.Unimplemented {
return 0, cloudprovider.ErrNotImplemented
}
klog.V(1).Infof("Error on gRPC call PricingPodPrice: %v", err)
return 0, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/anypb"
apiv1 "k8s.io/api/core/v1"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/externalgrpc/protos"
)

Expand Down Expand Up @@ -286,6 +289,23 @@ func TestCloudProvider_Pricing(t *testing.T) {
_, err = model.NodePrice(apiv1Node3, time.Time{}, time.Time{})
assert.Error(t, err)

// test notImplemented for NodePrice
m.On(
"PricingNodePrice", mock.Anything, mock.MatchedBy(func(req *protos.PricingNodePriceRequest) bool {
return req.Node.Name == "node4"
}),
).Return(
&protos.PricingNodePriceResponse{},
status.Error(codes.Unimplemented, "mock error"),
)

apiv1Node4 := &apiv1.Node{}
apiv1Node4.Name = "node4"

_, err = model.NodePrice(apiv1Node4, time.Time{}, time.Time{})
assert.Error(t, err)
assert.Equal(t, cloudprovider.ErrNotImplemented, err)

// test correct PodPrice call
m.On(
"PricingPodPrice", mock.Anything, mock.MatchedBy(func(req *protos.PricingPodPriceRequest) bool {
Expand Down Expand Up @@ -333,6 +353,24 @@ func TestCloudProvider_Pricing(t *testing.T) {

_, err = model.PodPrice(apiv1Pod3, time.Time{}, time.Time{})
assert.Error(t, err)

// test notImplemented for PodPrice
m.On(
"PricingPodPrice", mock.Anything, mock.MatchedBy(func(req *protos.PricingPodPriceRequest) bool {
return req.Pod.Name == "pod4"
}),
).Return(
&protos.PricingPodPriceResponse{},
status.Error(codes.Unimplemented, "mock error"),
)

apiv1Pod4 := &apiv1.Pod{}
apiv1Pod4.Name = "pod4"

_, err = model.PodPrice(apiv1Pod4, time.Time{}, time.Time{})
assert.Error(t, err)
assert.Equal(t, cloudprovider.ErrNotImplemented, err)

}

func TestCloudProvider_GPULabel(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"context"
"sync"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
Expand Down Expand Up @@ -206,6 +208,10 @@ func (n *NodeGroup) TemplateNodeInfo() (*schedulerframework.NodeInfo, error) {
Id: n.id,
})
if err != nil {
st, ok := status.FromError(err)
if ok && st.Code() == codes.Unimplemented {
return nil, cloudprovider.ErrNotImplemented
}
klog.V(1).Infof("Error on gRPC call NodeGroupTemplateNodeInfo: %v", err)
return nil, err
}
Expand Down Expand Up @@ -269,6 +275,10 @@ func (n *NodeGroup) GetOptions(defaults config.NodeGroupAutoscalingOptions) (*co
},
})
if err != nil {
st, ok := status.FromError(err)
if ok && st.Code() == codes.Unimplemented {
return nil, cloudprovider.ErrNotImplemented
}
klog.V(1).Infof("Error on gRPC call NodeGroupGetOptions: %v", err)
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
apiv1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
Expand Down Expand Up @@ -208,6 +210,27 @@ func TestCloudProvider_TemplateNodeInfo(t *testing.T) {
_, err = ng4.TemplateNodeInfo()
assert.Error(t, err)

// test notImplemented
m.On(
"NodeGroupTemplateNodeInfo", mock.Anything, mock.MatchedBy(func(req *protos.NodeGroupTemplateNodeInfoRequest) bool {
return req.Id == "nodeGroup5"
}),
).Return(
&protos.NodeGroupTemplateNodeInfoResponse{
NodeInfo: nil,
},
status.Error(codes.Unimplemented, "mock error"),
).Once()

ng5 := NodeGroup{
id: "nodeGroup5",
client: client,
}

_, err = ng5.TemplateNodeInfo()
assert.Error(t, err)
assert.Equal(t, cloudprovider.ErrNotImplemented, err)

}

func TestCloudProvider_GetOptions(t *testing.T) {
Expand Down Expand Up @@ -289,6 +312,26 @@ func TestCloudProvider_GetOptions(t *testing.T) {
opts, err = ng3.GetOptions(defaultsOpts)
assert.NoError(t, err)
assert.Nil(t, opts)

// test notImplemented
m.On(
"NodeGroupGetOptions", mock.Anything, mock.MatchedBy(func(req *protos.NodeGroupAutoscalingOptionsRequest) bool {
return req.Id == "nodeGroup4"
}),
).Return(
&protos.NodeGroupAutoscalingOptionsResponse{},
status.Error(codes.Unimplemented, "mock error"),
)

ng4 := NodeGroup{
id: "nodeGroup4",
client: client,
}

_, err = ng4.GetOptions(defaultsOpts)
assert.Error(t, err)
assert.Equal(t, cloudprovider.ErrNotImplemented, err)

}

func TestCloudProvider_TargetSize(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ service CloudProvider {

// PricingNodePrice returns a theoretical minimum price of running a node for
// a given period of time on a perfectly matching machine.
// Implementation optional.
// Implementation optional: if unimplemented return error code 12 (for `Unimplemented`)
rpc PricingNodePrice(PricingNodePriceRequest)
returns (PricingNodePriceResponse) {}

// PricingPodPrice returns a theoretical minimum price of running a pod for a given
// period of time on a perfectly matching machine.
// Implementation optional.
// Implementation optional: if unimplemented return error code 12 (for `Unimplemented`)
rpc PricingPodPrice(PricingPodPriceRequest)
returns (PricingPodPriceResponse) {}

Expand Down Expand Up @@ -103,13 +103,13 @@ service CloudProvider {
// NodeGroupTemplateNodeInfo returns a structure of an empty (as if just started) node,
// with all of the labels, capacity and allocatable information. This will be used in
// scale-up simulations to predict what would a new node look like if a node group was expanded.
// Implementation optional.
// Implementation optional: if unimplemented return error code 12 (for `Unimplemented`)
rpc NodeGroupTemplateNodeInfo(NodeGroupTemplateNodeInfoRequest)
returns (NodeGroupTemplateNodeInfoResponse) {}

// GetOptions returns NodeGroupAutoscalingOptions that should be used for this particular
// NodeGroup. Returning a grpc error will result in using default options.
// Implementation optional.
// NodeGroup.
// Implementation optional: if unimplemented return error code 12 (for `Unimplemented`)
rpc NodeGroupGetOptions(NodeGroupAutoscalingOptionsRequest)
returns (NodeGroupAutoscalingOptionsResponse) {}
}
Expand Down Expand Up @@ -371,4 +371,3 @@ message NodeGroupAutoscalingOptionsResponse {
// autoscaling options for the requested node.
NodeGroupAutoscalingOptions nodeGroupAutoscalingOptions = 1;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a707cdc

Please sign in to comment.