Skip to content

Commit

Permalink
Use managed cni policy if not using cluster scoped ones
Browse files Browse the repository at this point in the history
  • Loading branch information
kishiel committed Nov 1, 2023
1 parent ece5253 commit 0f0ea66
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/aws-cdk-lib/aws-eks/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,7 @@ abstract class ClusterBase extends Resource implements ICluster {
}

autoScalingGroup.role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonEKSWorkerNodePolicy'));
autoScalingGroup.role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonEKS_CNI_Policy'));
autoScalingGroup.role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonEC2ContainerRegistryReadOnly'));

// EKS Required Tags
Expand Down
5 changes: 3 additions & 2 deletions packages/aws-cdk-lib/aws-eks/lib/managed-nodegroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,19 +446,20 @@ export class Nodegroup extends Resource implements INodegroup {
});

ngRole.addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName('AmazonEKSWorkerNodePolicy'));
ngRole.addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName('AmazonEKS_CNI_Policy'));
ngRole.addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName('AmazonEC2ContainerRegistryReadOnly'));

this.role = ngRole;
} else {
this.role = props.nodeRole;
}

// Apply the CNI policies to the node group role
// Apply the cluster-scoped CNI policies to the node group role
if (props.cluster.cniPolicies && this.applyLimitedCNIPoliciesToRole) {
for (let policy of props.cluster.cniPolicies) {
this.role.addToPrincipalPolicy(policy);
}
} else {
this.role.addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName('AmazonEKS_CNI_Policy'));
}

this.validateUpdateConfig(props.maxUnavailable, props.maxUnavailablePercentage);
Expand Down

0 comments on commit 0f0ea66

Please sign in to comment.