Skip to content

Commit

Permalink
Support for no_manage=false (aws#1607)
Browse files Browse the repository at this point in the history
* Support for no_manage=false

* pr comments
  • Loading branch information
jayanthvn committed Sep 11, 2021
1 parent be5d0b6 commit 00b38e6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
8 changes: 8 additions & 0 deletions pkg/awsutils/awsutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ type APIs interface {

//Update cached prefix delegation flag
InitCachedPrefixDelegation(bool)

// GetInstanceID returns the instance ID
GetInstanceID() string
}

// EC2InstanceMetadataCache caches instance metadata
Expand Down Expand Up @@ -1651,6 +1654,11 @@ func (cache *EC2InstanceMetadataCache) SetUnmanagedENIs(eniIDs []string) {
cache.unmanagedENIs.Set(eniIDs)
}

// GetInstanceID returns the instance ID
func (cache *EC2InstanceMetadataCache) GetInstanceID() string {
return cache.instanceID
}

//IsUnmanagedENI returns if the eni is unmanaged
func (cache *EC2InstanceMetadataCache) IsUnmanagedENI(eniID string) bool {
if len(eniID) != 0 {
Expand Down
14 changes: 14 additions & 0 deletions pkg/awsutils/mocks/awsutils_mocks.go

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

36 changes: 30 additions & 6 deletions pkg/ipamd/ipamd.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ const (
//envWarmPrefixTarget is used to keep a /28 prefix in warm pool.
envWarmPrefixTarget = "WARM_PREFIX_TARGET"
defaultWarmPrefixTarget = 0

// envManageUntaggedENI is used to determine if untagged ENIs should be managed or unmanaged
envManageUntaggedENI = "MANAGE_UNTAGGED_ENI"

eniNodeTagKey = "node.k8s.amazonaws.com/instance_id"
)

var log = logger.Get()
Expand Down Expand Up @@ -223,6 +228,7 @@ type IPAMContext struct {
enablePodENI bool
myNodeName string
enableIpv4PrefixDelegation bool
enableManageUntaggedMode bool
}

// setUnmanagedENIs will rebuild the set of ENI IDs for ENIs tagged as "no_manage"
Expand All @@ -231,14 +237,27 @@ func (c *IPAMContext) setUnmanagedENIs(tagMap map[string]awsutils.TagMap) {
return
}
var unmanagedENIlist []string
// if "no_manage" tag is present and is true - ENI is unmanaged
// if "no_manage" tag is present and is "not true" - ENI is managed
// if "instance_id" tag is present and is set to instanceID - ENI is managed since this was created by IPAMD
// if "no_manage" tag is not present or not IPAMD created ENI, check if we are in Manage Untagged Mode, default is true.
// if enableManageUntaggedMode is false, then consider all untagged ENIs as unmanaged.
for eniID, tags := range tagMap {
if tags[eniNoManageTagKey] == "true" {
if eniID == c.awsClient.GetPrimaryENI() {
log.Debugf("Ignoring no_manage tag on primary ENI %s", eniID)
} else {
log.Debugf("Marking ENI %s tagged with %s as being unmanaged", eniID, eniNoManageTagKey)
unmanagedENIlist = append(unmanagedENIlist, eniID)
if _, found := tags[eniNoManageTagKey]; found {
if tags[eniNoManageTagKey] != "true" {
continue
}
} else if _, found := tags[eniNodeTagKey]; found && tags[eniNodeTagKey] == c.awsClient.GetInstanceID() {
continue
} else if c.enableManageUntaggedMode {
continue
}

if eniID == c.awsClient.GetPrimaryENI() {
log.Debugf("Ignoring primary ENI %s since it is always managed", eniID)
} else {
log.Debugf("Marking ENI %s as being unmanaged", eniID)
unmanagedENIlist = append(unmanagedENIlist, eniID)
}
}
c.awsClient.SetUnmanagedENIs(unmanagedENIlist)
Expand Down Expand Up @@ -319,6 +338,7 @@ func New(rawK8SClient client.Client, cachedK8SClient client.Client) (*IPAMContex

c.disableENIProvisioning = disablingENIProvisioning()
c.enablePodENI = enablePodENI()
c.enableManageUntaggedMode = enableManageUntaggedMode()

hypervisorType, err := c.awsClient.GetInstanceHypervisorFamily()
if err != nil {
Expand Down Expand Up @@ -1510,6 +1530,10 @@ func useIpv4PrefixDelegation() bool {
return getEnvBoolWithDefault(envEnableIpv4PrefixDelegation, false)
}

func enableManageUntaggedMode() bool {
return getEnvBoolWithDefault(envManageUntaggedENI, true)
}

// filterUnmanagedENIs filters out ENIs marked with the "node.k8s.amazonaws.com/no_manage" tag
func (c *IPAMContext) filterUnmanagedENIs(enis []awsutils.ENIMetadata) []awsutils.ENIMetadata {
numFiltered := 0
Expand Down

0 comments on commit 00b38e6

Please sign in to comment.