Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions packages/@aws-cdk/aws-eks/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1262,8 +1262,12 @@ export class Cluster extends ClusterBase {
autoScalingGroup.role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonEC2ContainerRegistryReadOnly'));

// EKS Required Tags
// https://docs.aws.amazon.com/eks/latest/userguide/worker.html
Tags.of(autoScalingGroup).add(`kubernetes.io/cluster/${this.clusterName}`, 'owned', {
applyToLaunchedInstances: true,
// exclude security groups to avoid multiple "owned" security groups.
// (the cluster security group already has this tag)
excludeResourceTypes: ['AWS::EC2::SecurityGroup'],
});

// do not attempt to map the role if `kubectl` is not enabled for this
Expand Down
22 changes: 22 additions & 0 deletions packages/@aws-cdk/aws-eks/test/test.cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,28 @@ export = {

},

'security group of self-managed asg is not tagged with owned'(test: Test) {

// GIVEN
const { stack, vpc } = testFixture();
const cluster = new eks.Cluster(stack, 'Cluster', {
vpc,
version: CLUSTER_VERSION,
});

// WHEN
cluster.addAutoScalingGroupCapacity('self-managed', {
instanceType: new ec2.InstanceType('t2.medium'),
});

// make sure the "kubernetes.io/cluster/<CLUSTER_NAME>: owned" tag isn't here.
test.deepEqual(expect(stack).value.Resources.ClusterselfmanagedInstanceSecurityGroup64468C3A.Properties.Tags, [
{ Key: 'Name', Value: 'Stack/Cluster/self-managed' },
]);
test.done();

},

'cluster security group is attached when connecting self-managed nodes'(test: Test) {

// GIVEN
Expand Down