Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into snat_test_agent_c…
Browse files Browse the repository at this point in the history
…hanges

# Conflicts:
#	README.md
#	charts/aws-vpc-cni/values.yaml
#	scripts/generate-cni-yaml.sh
  • Loading branch information
Chinmay Gadgil committed Aug 30, 2021
2 parents e5f2a8c + 867e3be commit 17516ee
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 21 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,16 @@ This environment variable works when `ENABLE_PREFIX_DELEGATION` is set to `true`

---

#### `DISABLE_NETWORK_RESOURCE_PROVISIONING` (v1.9.1+)

Type: Boolean as a String

Default: `false`

Setting `DISABLE_NETWORK_RESOURCE_PROVISIONING` to `true` will make IPAMD to depend only on IMDS to get attached ENIs and IPs/prefixes.

---

### ENI tags related to Allocation

This plugin interacts with the following tags on ENIs:
Expand Down
1 change: 1 addition & 0 deletions charts/aws-vpc-cni/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ env:
ENABLE_PREFIX_DELEGATION: "false"
WARM_ENI_TARGET: "1"
WARM_PREFIX_TARGET: "1"
DISABLE_NETWORK_RESOURCE_PROVISIONING: "false"

# this flag enables you to use the match label that was present in the original daemonset deployed by EKS
# You can then annotate and label the original aws-node resources and 'adopt' them into a helm release
Expand Down
2 changes: 2 additions & 0 deletions config/master/aws-k8s-cni-cn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@
"value": "false"
- "name": "DISABLE_METRICS"
"value": "false"
- "name": "DISABLE_NETWORK_RESOURCE_PROVISIONING"
"value": "false"
- "name": "ENABLE_POD_ENI"
"value": "false"
- "name": "ENABLE_PREFIX_DELEGATION"
Expand Down
2 changes: 2 additions & 0 deletions config/master/aws-k8s-cni-us-gov-east-1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@
"value": "false"
- "name": "DISABLE_METRICS"
"value": "false"
- "name": "DISABLE_NETWORK_RESOURCE_PROVISIONING"
"value": "false"
- "name": "ENABLE_POD_ENI"
"value": "false"
- "name": "ENABLE_PREFIX_DELEGATION"
Expand Down
2 changes: 2 additions & 0 deletions config/master/aws-k8s-cni-us-gov-west-1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@
"value": "false"
- "name": "DISABLE_METRICS"
"value": "false"
- "name": "DISABLE_NETWORK_RESOURCE_PROVISIONING"
"value": "false"
- "name": "ENABLE_POD_ENI"
"value": "false"
- "name": "ENABLE_PREFIX_DELEGATION"
Expand Down
2 changes: 2 additions & 0 deletions config/master/aws-k8s-cni.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@
"value": "false"
- "name": "DISABLE_METRICS"
"value": "false"
- "name": "DISABLE_NETWORK_RESOURCE_PROVISIONING"
"value": "false"
- "name": "ENABLE_POD_ENI"
"value": "false"
- "name": "ENABLE_PREFIX_DELEGATION"
Expand Down
1 change: 1 addition & 0 deletions config/master/manifests.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ local awsnode = {
DISABLE_METRICS: "false",
ENABLE_POD_ENI: "false",
ENABLE_PREFIX_DELEGATION: "false",
DISABLE_NETWORK_RESOURCE_PROVISIONING: "false",
MY_NODE_NAME: {
valueFrom: {
fieldRef: {fieldPath: "spec.nodeName"},
Expand Down
6 changes: 4 additions & 2 deletions pkg/awsutils/awsutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func (i instrumentedIMDS) GetMetadataWithContext(ctx context.Context, p string)
}

// New creates an EC2InstanceMetadataCache
func New(useCustomNetworking bool) (*EC2InstanceMetadataCache, error) {
func New(useCustomNetworking, disableENIProvisioning bool) (*EC2InstanceMetadataCache, error) {
//ctx is passed to initWithEC2Metadata func to cancel spawned go-routines when tests are run
ctx := context.Background()

Expand Down Expand Up @@ -379,7 +379,9 @@ func New(useCustomNetworking bool) (*EC2InstanceMetadataCache, error) {
}

// Clean up leaked ENIs in the background
go wait.Forever(cache.cleanUpLeakedENIs, time.Hour)
if !disableENIProvisioning {
go wait.Forever(cache.cleanUpLeakedENIs, time.Hour)
}

return cache, nil
}
Expand Down
36 changes: 20 additions & 16 deletions pkg/ipamd/ipamd.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,9 @@ func New(rawK8SClient client.Client, cachedK8SClient client.Client) (*IPAMContex
c.networkClient = networkutils.New()
c.useCustomNetworking = UseCustomNetworkCfg()
c.enableIpv4PrefixDelegation = useIpv4PrefixDelegation()
c.disableENIProvisioning = disablingENIProvisioning()

client, err := awsutils.New(c.useCustomNetworking)
client, err := awsutils.New(c.useCustomNetworking, c.disableENIProvisioning)
if err != nil {
return nil, errors.Wrap(err, "ipamd: can not initialize with AWS SDK interface")
}
Expand All @@ -317,7 +318,6 @@ func New(rawK8SClient client.Client, cachedK8SClient client.Client) (*IPAMContex
c.minimumIPTarget = getMinimumIPTarget()
c.warmPrefixTarget = getWarmPrefixTarget()

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

hypervisorType, err := c.awsClient.GetInstanceHypervisorFamily()
Expand All @@ -341,15 +341,17 @@ func New(rawK8SClient client.Client, cachedK8SClient client.Client) (*IPAMContex

mac := c.awsClient.GetPrimaryENImac()
// retrieve security groups
if !c.disableENIProvisioning {
err = c.awsClient.RefreshSGIDs(mac)
if err != nil {
return nil, err
}

err = c.awsClient.RefreshSGIDs(mac)
if err != nil {
return nil, err
// Refresh security groups and VPC CIDR blocks in the background
// Ignoring errors since we will retry in 30s
go wait.Forever(func() { _ = c.awsClient.RefreshSGIDs(mac) }, 30*time.Second)
}

// Refresh security groups and VPC CIDR blocks in the background
// Ignoring errors since we will retry in 30s
go wait.Forever(func() { _ = c.awsClient.RefreshSGIDs(mac) }, 30*time.Second)
return c, nil
}

Expand Down Expand Up @@ -401,7 +403,7 @@ func (c *IPAMContext) nodeInit() error {

isTrunkENI := eni.ENIID == metadataResult.TrunkENI
isEFAENI := metadataResult.EFAENIs[eni.ENIID]
if !isTrunkENI {
if !isTrunkENI && !c.disableENIProvisioning {
if err := c.awsClient.TagENI(eni.ENIID, metadataResult.TagMap[eni.ENIID]); err != nil {
return errors.Wrapf(err, "ipamd init: failed to tag managed ENI %v", eni.ENIID)
}
Expand Down Expand Up @@ -489,12 +491,14 @@ func (c *IPAMContext) nodeInit() error {
c.askForTrunkENIIfNeeded(ctx)
}

// For a new node, attach Cidrs (secondary ips/prefixes)
increasedPool, err := c.tryAssignCidrs()
if err == nil && increasedPool {
c.updateLastNodeIPPoolAction()
} else if err != nil {
return err
if !c.disableENIProvisioning {
// For a new node, attach Cidrs (secondary ips/prefixes)
increasedPool, err := c.tryAssignCidrs()
if err == nil && increasedPool {
c.updateLastNodeIPPoolAction()
} else if err != nil {
return err
}
}
return nil
}
Expand Down Expand Up @@ -1177,7 +1181,7 @@ func (c *IPAMContext) nodeIPPoolReconcile(ctx context.Context, interval time.Dur

isTrunkENI := attachedENI.ENIID == trunkENI
isEFAENI := efaENIs[attachedENI.ENIID]
if !isTrunkENI {
if !isTrunkENI && !c.disableENIProvisioning {
if err := c.awsClient.TagENI(attachedENI.ENIID, eniTagMap[attachedENI.ENIID]); err != nil {
log.Errorf("IP pool reconcile: failed to tag managed ENI %v: %v", attachedENI.ENIID, err)
ipamdErrInc("eniReconcileAdd")
Expand Down
6 changes: 3 additions & 3 deletions scripts/generate-cni-yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -euo pipefail
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"

PLATFORM=$(uname | tr '[:upper:]' '[:lower:]')
HELM_VERSION="3.0.2"
HELM_VERSION="3.6.3"
NAMESPACE="kube-system"

MAKEFILEPATH=$SCRIPTPATH/../Makefile
Expand Down Expand Up @@ -70,7 +70,7 @@ jq -c '.[]' $REGIONS_FILE | while read i; do
NEW_METRICS_RESOURCES_YAML="${METRICS_RESOURCES_YAML}-${ecrRegion}.yaml"
fi

$BUILD_DIR/helm template charts/aws-vpc-cni \
$BUILD_DIR/helm template aws-vpc-cni \
--set originalMatchLabels=true,\
--set init.image.region=$ecrRegion,\
--set init.image.account=$ecrAccount,\
Expand All @@ -83,7 +83,7 @@ jq -c '.[]' $REGIONS_FILE | while read i; do
cat $NEW_CNI_RESOURCES_YAML | grep -v 'helm.sh\|app.kubernetes.io/managed-by: Helm' > $BUILD_DIR/helm_annotations_removed.yaml
mv $BUILD_DIR/helm_annotations_removed.yaml $NEW_CNI_RESOURCES_YAML

$BUILD_DIR/helm template charts/cni-metrics-helper \
$BUILD_DIR/helm template cni-metrics-helper \
--set image.region=$ecrRegion,\
--set image.account=$ecrAccount,\
--set image.domain=$ecrDomain \
Expand Down

0 comments on commit 17516ee

Please sign in to comment.