Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for no_manage=false #1607

Merged
merged 2 commits into from
Sep 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1653,6 +1656,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.warmPrefixTarget = getWarmPrefixTarget()

c.enablePodENI = enablePodENI()
c.enableManageUntaggedMode = enableManageUntaggedMode()

hypervisorType, err := c.awsClient.GetInstanceHypervisorFamily()
if err != nil {
Expand Down Expand Up @@ -1514,6 +1534,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