@@ -46,7 +46,7 @@ import (
4646	"gopkg.in/gcfg.v1" 
4747	"k8s.io/klog" 
4848
49- 	"k8s.io/api/core/v1" 
49+ 	v1  "k8s.io/api/core/v1" 
5050	"k8s.io/apimachinery/pkg/api/resource" 
5151	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 
5252	"k8s.io/apimachinery/pkg/types" 
@@ -280,6 +280,9 @@ type EC2 interface {
280280	// Query EC2 for instances matching the filter 
281281	DescribeInstances (request  * ec2.DescribeInstancesInput ) ([]* ec2.Instance , error )
282282
283+ 	// Query EC2 for instances matching the filter with pagination 
284+ 	DescribeInstancesPages (input  * ec2.DescribeInstancesInput , fn  func (* ec2.DescribeInstancesOutput , bool ) bool ) error 
285+ 
283286	// Attach a volume to an instance 
284287	AttachVolume (* ec2.AttachVolumeInput ) (* ec2.VolumeAttachment , error )
285288	// Detach a volume from an instance it is attached to 
@@ -902,6 +905,11 @@ func (s *awsSdkEC2) DescribeInstances(request *ec2.DescribeInstancesInput) ([]*e
902905	return  results , nil 
903906}
904907
908+ // Implementation of EC2.Instances with pagination 
909+ func  (s  * awsSdkEC2 ) DescribeInstancesPages (input  * ec2.DescribeInstancesInput , fn  func (* ec2.DescribeInstancesOutput , bool ) bool ) error  {
910+ 	return  s .ec2 .DescribeInstancesPages (input , fn )
911+ }
912+ 
905913// Implements EC2.DescribeSecurityGroups 
906914func  (s  * awsSdkEC2 ) DescribeSecurityGroups (request  * ec2.DescribeSecurityGroupsInput ) ([]* ec2.SecurityGroup , error ) {
907915	// Security groups are paged 
@@ -4499,21 +4507,29 @@ func (c *Cloud) getInstancesByNodeNames(nodeNames []string, states ...string) ([
44994507
45004508// TODO: Move to instanceCache 
45014509func  (c  * Cloud ) describeInstances (filters  []* ec2.Filter ) ([]* ec2.Instance , error ) {
4510+ 	// Set the Maxresults to the maximum allowed per the AWS doc 
4511+ 	// https://docs.aws.amazon.com/sdk-for-go/api/service/ec2/#DescribeInstancesInput 
4512+ 	maxResults  :=  int64 (1000 )
45024513	request  :=  & ec2.DescribeInstancesInput {
4503- 		Filters : filters ,
4514+ 		Filters :    filters ,
4515+ 		MaxResults : & maxResults ,
45044516	}
45054517
4506- 	response , err  :=  c .ec2 .DescribeInstances (request )
4518+ 	var  matches  []* ec2.Instance 
4519+ 	err  :=  c .ec2 .DescribeInstancesPages (request , func (page  * ec2.DescribeInstancesOutput , lastPage  bool ) bool  {
4520+ 		for  _ , reservations  :=  range  page .Reservations  {
4521+ 			for  _ , instance  :=  range  reservations .Instances  {
4522+ 				if  c .tagging .hasClusterTag (instance .Tags ) {
4523+ 					matches  =  append (matches , instance )
4524+ 				}
4525+ 			}
4526+ 		}
4527+ 		return  ! lastPage 
4528+ 	})
45074529	if  err  !=  nil  {
45084530		return  nil , err 
45094531	}
45104532
4511- 	var  matches  []* ec2.Instance 
4512- 	for  _ , instance  :=  range  response  {
4513- 		if  c .tagging .hasClusterTag (instance .Tags ) {
4514- 			matches  =  append (matches , instance )
4515- 		}
4516- 	}
45174533	return  matches , nil 
45184534}
45194535
0 commit comments