From 98f26a27319b4322acfecbc8a8e8c6135bda2f81 Mon Sep 17 00:00:00 2001 From: Nick Turner Date: Tue, 9 Nov 2021 18:50:19 +0000 Subject: [PATCH] [AWS] Set max results if its not set * If max results is not set and instance IDs are not provided for the describe instances call in the aws cloud provider, set max results. * This prevents an expensive call against the EC2 API, which can result in timeouts. --- staging/src/k8s.io/legacy-cloud-providers/aws/aws.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/staging/src/k8s.io/legacy-cloud-providers/aws/aws.go b/staging/src/k8s.io/legacy-cloud-providers/aws/aws.go index 3ca90c459aa..541f741cfd1 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/aws/aws.go +++ b/staging/src/k8s.io/legacy-cloud-providers/aws/aws.go @@ -960,6 +960,13 @@ func (s *awsSdkEC2) DescribeInstances(request *ec2.DescribeInstancesInput) ([]*e results := []*ec2.Instance{} var nextToken *string requestTime := time.Now() + + if request.MaxResults == nil && request.InstanceIds == nil { + // MaxResults must be set in order for pagination to work + // MaxResults cannot be set with InstanceIds + request.MaxResults = aws.Int64(1000) + } + for { response, err := s.ec2.DescribeInstances(request) if err != nil {