Skip to content
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
16 changes: 16 additions & 0 deletions packages/@aws-cdk/aws-eks-v2-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,22 @@ const cluster = new eks.Cluster(this, 'EksAutoCluster', {

For more information, see [Create a Node Pool for EKS Auto Mode](https://docs.aws.amazon.com/eks/latest/userguide/create-node-pool.html).

### Disabling Default Node Pools

You can disable the default node pools entirely by setting an empty array for `nodePools`. This is useful when you want to use Auto Mode features but manage your compute resources separately:

```ts
const cluster = new eks.Cluster(this, 'EksAutoCluster', {
version: eks.KubernetesVersion.V1_32,
defaultCapacityType: eks.DefaultCapacityType.AUTOMODE,
compute: {
nodePools: [], // Disable default node pools
},
});
```

When node pools are disabled this way, no IAM role will be created for the node pools, preventing deployment failures that would otherwise occur when a role is created without any node pools.

### Node Groups as the default capacity type

If you prefer to manage your own node groups instead of using Auto Mode, you can use the traditional node group approach by specifying `defaultCapacityType` as `NODEGROUP`:
Expand Down
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-eks-v2-alpha/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1184,8 +1184,11 @@ export class Cluster extends ClusterBase {
enabled: autoModeEnabled,
// If the computeConfig enabled flag is set to false when creating a cluster with Auto Mode,
// the request must not include values for the nodeRoleArn or nodePools fields.
// Also, if nodePools is empty, nodeRoleArn should not be included to prevent deployment failures
nodePools: !autoModeEnabled ? undefined : props.compute?.nodePools ?? ['system', 'general-purpose'],
nodeRoleArn: !autoModeEnabled ? undefined : props.compute?.nodeRole?.roleArn ?? this.addNodePoolRole(`${id}nodePoolRole`).roleArn,
nodeRoleArn: !autoModeEnabled || (props.compute?.nodePools && props.compute.nodePools.length === 0) ?
undefined :
props.compute?.nodeRole?.roleArn ?? this.addNodePoolRole(`${id}nodePoolRole`).roleArn,
},
storageConfig: {
blockStorage: {
Expand Down
37 changes: 37 additions & 0 deletions packages/@aws-cdk/aws-eks-v2-alpha/test/automode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,43 @@ describe('eks auto mode', () => {
},
});
});

test('does not include nodeRoleArn when nodePools is empty', () => {
const { stack } = testFixtureNoVpc();

new eks.Cluster(stack, 'Cluster', {
version: CLUSTER_VERSION,
defaultCapacityType: eks.DefaultCapacityType.AUTOMODE,
compute: {
nodePools: [],
},
});

// Verify that nodeRoleArn is not included in the CloudFormation template
Template.fromStack(stack).hasResourceProperties('AWS::EKS::Cluster', {
ComputeConfig: {
Enabled: true,
NodePools: [],
},
});

// Verify that nodeRoleArn is not present in the ComputeConfig
const template = Template.fromStack(stack);
const cluster = template.findResources('AWS::EKS::Cluster');
const clusterLogicalId = Object.keys(cluster)[0];
const computeConfig = cluster[clusterLogicalId].Properties.ComputeConfig;

expect(computeConfig).not.toHaveProperty('NodeRoleArn');

// Verify that no IAM role resource is created for node pools
// The role would typically have a logical ID like 'ClusterClusternodePoolRole...'
const iamRoles = template.findResources('AWS::IAM::Role');
const nodePoolRoleKeys = Object.keys(iamRoles).filter(key =>
key.includes('nodePoolRole'),
);

expect(nodePoolRoleKeys.length).toBe(0);
});
});

describe('network configuration', () => {
Expand Down
Binary file not shown.
Binary file not shown.

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

Loading