@@ -129,7 +129,7 @@ type APIs interface {
129
129
DeallocIPAddresses (eniID string , ips []string ) error
130
130
131
131
// GetVPCIPv4CIDRs returns VPC's CIDRs from instance metadata
132
- GetVPCIPv4CIDRs () []string
132
+ GetVPCIPv4CIDRs () ( []string , error )
133
133
134
134
// GetLocalIPv4 returns the primary IP address on the primary ENI interface
135
135
GetLocalIPv4 () net.IP
@@ -164,7 +164,6 @@ type EC2InstanceMetadataCache struct {
164
164
localIPv4 net.IP
165
165
instanceID string
166
166
instanceType string
167
- vpcIPv4CIDRs StringSet
168
167
primaryENI string
169
168
primaryENImac string
170
169
availabilityZone string
@@ -401,16 +400,9 @@ func (cache *EC2InstanceMetadataCache) initWithEC2Metadata(ctx context.Context)
401
400
return err
402
401
}
403
402
404
- // retrieve VPC IPv4 CIDR blocks
405
- err = cache .refreshVPCIPv4CIDRs (mac )
406
- if err != nil {
407
- return err
408
- }
409
-
410
403
// Refresh security groups and VPC CIDR blocks in the background
411
404
// Ignoring errors since we will retry in 30s
412
405
go wait .Forever (func () { _ = cache .refreshSGIDs (mac ) }, 30 * time .Second )
413
- go wait .Forever (func () { _ = cache .refreshVPCIPv4CIDRs (mac ) }, 30 * time .Second )
414
406
415
407
// We use the ctx here for testing, since we spawn go-routines above which will run forever.
416
408
select {
@@ -484,36 +476,6 @@ func (cache *EC2InstanceMetadataCache) refreshSGIDs(mac string) error {
484
476
return nil
485
477
}
486
478
487
- // refreshVPCIPv4CIDRs retrieves VPC IPv4 CIDR blocks
488
- func (cache * EC2InstanceMetadataCache ) refreshVPCIPv4CIDRs (mac string ) error {
489
- ctx := context .TODO ()
490
-
491
- ipnets , err := cache .imds .GetVPCIPv4CIDRBlocks (ctx , mac )
492
- if err != nil {
493
- return err
494
- }
495
-
496
- // TODO: keep as net.IPNet and remove this round-trip to/from string
497
- vpcIPv4CIDRs := make ([]string , len (ipnets ))
498
- for i , ipnet := range ipnets {
499
- vpcIPv4CIDRs [i ] = ipnet .String ()
500
- }
501
-
502
- newVpcIPv4CIDRs := StringSet {}
503
- newVpcIPv4CIDRs .Set (vpcIPv4CIDRs )
504
- addedVpcIPv4CIDRs := newVpcIPv4CIDRs .Difference (& cache .vpcIPv4CIDRs )
505
- deletedVpcIPv4CIDRs := cache .vpcIPv4CIDRs .Difference (& newVpcIPv4CIDRs )
506
-
507
- for _ , vpcIPv4CIDR := range addedVpcIPv4CIDRs .SortedList () {
508
- log .Infof ("Found %s, added to ipamd cache" , vpcIPv4CIDR )
509
- }
510
- for _ , vpcIPv4CIDR := range deletedVpcIPv4CIDRs .SortedList () {
511
- log .Infof ("Removed %s from ipamd cache" , vpcIPv4CIDR )
512
- }
513
- cache .vpcIPv4CIDRs .Set (vpcIPv4CIDRs )
514
- return nil
515
- }
516
-
517
479
// GetAttachedENIs retrieves ENI information from meta data service
518
480
func (cache * EC2InstanceMetadataCache ) GetAttachedENIs () (eniList []ENIMetadata , err error ) {
519
481
ctx := context .TODO ()
@@ -1454,8 +1416,21 @@ func (cache *EC2InstanceMetadataCache) getFilteredListOfNetworkInterfaces() ([]*
1454
1416
}
1455
1417
1456
1418
// GetVPCIPv4CIDRs returns VPC CIDRs
1457
- func (cache * EC2InstanceMetadataCache ) GetVPCIPv4CIDRs () []string {
1458
- return cache .vpcIPv4CIDRs .SortedList ()
1419
+ func (cache * EC2InstanceMetadataCache ) GetVPCIPv4CIDRs () ([]string , error ) {
1420
+ ctx := context .TODO ()
1421
+
1422
+ ipnets , err := cache .imds .GetVPCIPv4CIDRBlocks (ctx , cache .primaryENImac )
1423
+ if err != nil {
1424
+ return nil , err
1425
+ }
1426
+
1427
+ // TODO: keep as net.IPNet and remove this round-trip to/from string
1428
+ asStrs := make ([]string , len (ipnets ))
1429
+ for i , ipnet := range ipnets {
1430
+ asStrs [i ] = ipnet .String ()
1431
+ }
1432
+
1433
+ return asStrs , nil
1459
1434
}
1460
1435
1461
1436
// GetLocalIPv4 returns the primary IP address on the primary interface
0 commit comments