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

feat(eks): implement ITaggableV2 for Cluster #31239

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 9 additions & 3 deletions packages/aws-cdk-lib/aws-eks/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import * as iam from '../../aws-iam';
import * as kms from '../../aws-kms';
import * as lambda from '../../aws-lambda';
import * as ssm from '../../aws-ssm';
import { Annotations, CfnOutput, CfnResource, IResource, Resource, Stack, Tags, Token, Duration, Size } from '../../core';
import { Annotations, CfnOutput, CfnResource, IResource, Resource, Stack, Tags, Token, Duration, Size, ITaggableV2, TagManager, TagType } from '../../core';

// defaults are based on https://eksctl.io
const DEFAULT_CAPACITY_COUNT = 2;
Expand Down Expand Up @@ -1306,7 +1306,7 @@ export interface IngressLoadBalancerAddressOptions extends ServiceLoadBalancerAd
* This is a fully managed cluster of API Servers (control-plane)
* The user is still required to create the worker nodes.
*/
export class Cluster extends ClusterBase {
export class Cluster extends ClusterBase implements ITaggableV2 {
/**
* Import an existing cluster
*
Expand Down Expand Up @@ -1520,6 +1520,11 @@ export class Cluster extends ClusterBase {
*/
public readonly authenticationMode?: AuthenticationMode;

/**
* `TagManager` for `ITaggableV2` implementation.
*/
public readonly cdkTagManager: TagManager;

/**
* If this cluster is kubectl-enabled, returns the `ClusterResource` object
* that manages it. If this cluster is not kubectl-enabled (i.e. uses the
Expand Down Expand Up @@ -1569,6 +1574,7 @@ export class Cluster extends ClusterBase {

this.prune = props.prune ?? true;
this.vpc = props.vpc || new ec2.Vpc(this, 'DefaultVpc');
this.cdkTagManager = new TagManager(TagType.KEY_VALUE, 'AWS::EKS::Cluster', props.tags);

const kubectlVersion = new semver.SemVer(`${props.version.version}.0`);
if (semver.gte(kubectlVersion, '1.22.0') && !props.kubectlLayer) {
Expand Down Expand Up @@ -1694,7 +1700,7 @@ export class Cluster extends ClusterBase {
subnets: placeClusterHandlerInVpc ? privateSubnets : undefined,
clusterHandlerSecurityGroup: this.clusterHandlerSecurityGroup,
onEventLayer: this.onEventLayer,
tags: props.tags,
tags: this.cdkTagManager.renderedTags as unknown as { [key:string]: string},
logging: this.logging,
});

Expand Down
34 changes: 33 additions & 1 deletion packages/aws-cdk-lib/aws-eks/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3380,4 +3380,36 @@ describe('cluster', () => {

});

});
describe('ITaggableV2', () => {
test('cluster isTaggableV2', () => {
// GIVEN
const { stack, vpc } = testFixture();
// WHEN
const cluster = new eks.Cluster(stack, 'Cluster', {
vpc,
version: CLUSTER_VERSION,
});
// THEN
expect(cdk.TagManager.isTaggableV2(cluster)).toBeTruthy();
});
test('cluster can be tagged with Tags.of', () => {
// GIVEN
const { stack, vpc } = testFixture();
// WHEN
const cluster = new eks.Cluster(stack, 'Cluster', {
vpc,
version: CLUSTER_VERSION,
});
cdk.Tags.of(cluster).add('TagsOf', '1');
// THEN
const template = Template.fromStack(stack);
template.hasResourceProperties('Custom::AWSCDK-EKS-Cluster', {
Config: {
tags: [{ Key: 'TagsOf', Value: '1' }],
},
});
});

});

});
Loading