Skip to content

Commit c3666e5

Browse files
committed
operator: add flag to control AWS API pagination
Signed-off-by: Anton Ippolitov <anton.ippolitov@datadoghq.com>
1 parent f219b7a commit c3666e5

5 files changed

Lines changed: 23 additions & 7 deletions

File tree

Documentation/cmdref/cilium-operator-aws.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Documentation/cmdref/cilium-operator.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

operator/cmd/provider_aws_flags.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,8 @@ func (hook *awsFlagsHooks) RegisterProviderFlag(cmd *cobra.Command, vp *viper.Vi
5050
flags.String(operatorOption.EC2APIEndpoint, "", "AWS API endpoint for the EC2 service")
5151
option.BindEnv(vp, operatorOption.EC2APIEndpoint)
5252

53+
flags.Bool(operatorOption.AWSPaginationEnabled, true, "Enable pagination for AWS EC2 API requests. The default page size is 1000 items.")
54+
option.BindEnv(vp, operatorOption.AWSPaginationEnabled)
55+
5356
vp.BindPFlags(flags)
5457
}

operator/option/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ const (
213213
// PodRestartSelector specify the labels contained in the pod that needs to be restarted before the node can be de-stained
214214
// default values: k8s-app=kube-dns
215215
PodRestartSelector = "pod-restart-selector"
216+
217+
// AWSPaginationEnabled toggles pagination for AWS EC2 API requests
218+
AWSPaginationEnabled = "aws-pagination-enabled"
216219
)
217220

218221
// OperatorConfig is the configuration used by the operator.
@@ -392,6 +395,9 @@ type OperatorConfig struct {
392395

393396
// PodRestartSelector specify the labels contained in the pod that needs to be restarted before the node can be de-stained
394397
PodRestartSelector string
398+
399+
// AWSPaginationEnabled toggles pagination for AWS EC2 API requests
400+
AWSPaginationEnabled bool
395401
}
396402

397403
// Populate sets all options with the values from viper.
@@ -453,6 +459,7 @@ func (c *OperatorConfig) Populate(logger *slog.Logger, vp *viper.Viper) {
453459
c.EC2APIEndpoint = vp.GetString(EC2APIEndpoint)
454460
c.ExcessIPReleaseDelay = vp.GetInt(ExcessIPReleaseDelay)
455461
c.ENIGarbageCollectionInterval = vp.GetDuration(ENIGarbageCollectionInterval)
462+
c.AWSPaginationEnabled = vp.GetBool(AWSPaginationEnabled)
456463

457464
// Azure options
458465

pkg/aws/ec2/ec2.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ import (
2020
"github.com/aws/aws-sdk-go-v2/service/ec2"
2121
ec2_types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
2222

23+
operatorOption "github.com/cilium/cilium/operator/option"
2324
"github.com/cilium/cilium/pkg/api/helpers"
2425
eniTypes "github.com/cilium/cilium/pkg/aws/eni/types"
2526
"github.com/cilium/cilium/pkg/aws/types"
2627
"github.com/cilium/cilium/pkg/defaults"
2728
ipPkg "github.com/cilium/cilium/pkg/ip"
28-
"github.com/cilium/cilium/pkg/ipam/option"
29+
ipamOption "github.com/cilium/cilium/pkg/ipam/option"
2930
ipamTypes "github.com/cilium/cilium/pkg/ipam/types"
3031
"github.com/cilium/cilium/pkg/logging/logfields"
3132
"github.com/cilium/cilium/pkg/spanstat"
@@ -214,14 +215,16 @@ func DetectEKSClusterName(ctx context.Context, cfg aws.Config) (string, error) {
214215
func (c *Client) GetDetachedNetworkInterfaces(ctx context.Context, tags ipamTypes.Tags, maxResults int32) ([]string, error) {
215216
result := make([]string, 0, int(maxResults))
216217
input := &ec2.DescribeNetworkInterfacesInput{
217-
Filters: NewTagsFilter(tags),
218-
MaxResults: aws.Int32(defaults.ENIMaxResultsPerApiCall),
218+
Filters: NewTagsFilter(tags),
219219
}
220220
for _, subnetFilter := range c.subnetsFilters {
221221
if aws.ToString(subnetFilter.Name) == "subnet-id" {
222222
input.Filters = append(input.Filters, subnetFilter)
223223
}
224224
}
225+
if operatorOption.Config.AWSPaginationEnabled {
226+
input.MaxResults = aws.Int32(maxResults)
227+
}
225228

226229
input.Filters = append(input.Filters, ec2_types.Filter{
227230
Name: aws.String("status"),
@@ -259,7 +262,9 @@ func (c *Client) describeNetworkInterfaces(ctx context.Context, subnets ipamType
259262
Values: []string{"*"},
260263
},
261264
},
262-
MaxResults: aws.Int32(defaults.ENIMaxResultsPerApiCall),
265+
}
266+
if operatorOption.Config.AWSPaginationEnabled {
267+
input.MaxResults = aws.Int32(defaults.ENIMaxResultsPerApiCall)
263268
}
264269
if len(c.subnetsFilters) > 0 {
265270
subnetsIDs := make([]string, 0, len(subnets))
@@ -296,7 +301,6 @@ func (c *Client) describeNetworkInterfacesByInstance(ctx context.Context, instan
296301
Values: []string{instanceID},
297302
},
298303
},
299-
MaxResults: aws.Int32(defaults.ENIMaxResultsPerApiCall),
300304
}
301305
paginator := ec2.NewDescribeNetworkInterfacesPaginator(c.ec2Client, input)
302306
for paginator.HasMorePages() {
@@ -358,7 +362,7 @@ func (c *Client) describeNetworkInterfacesFromInstances(ctx context.Context) ([]
358362
}
359363
if len(enisListFromInstances) > 0 {
360364
ENIAttrs.NetworkInterfaceIds = enisListFromInstances
361-
} else {
365+
} else if operatorOption.Config.AWSPaginationEnabled {
362366
// MaxResults is incompatible with NetworkInterfaceIds
363367
ENIAttrs.MaxResults = aws.Int32(defaults.ENIMaxResultsPerApiCall)
364368
}
@@ -697,7 +701,7 @@ func (c *Client) CreateNetworkInterface(ctx context.Context, toAllocate int32, s
697701
Groups: groups,
698702
}
699703
if allocatePrefixes {
700-
prefixCount := ipPkg.PrefixCeil(int(toAllocate), option.ENIPDBlockSizeIPv4)
704+
prefixCount := ipPkg.PrefixCeil(int(toAllocate), ipamOption.ENIPDBlockSizeIPv4)
701705
input.Ipv4PrefixCount = aws.Int32(int32(prefixCount))
702706
c.logger.Debug("Creating interface with prefixes",
703707
logfields.PrefixCount, prefixCount,

0 commit comments

Comments
 (0)