aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

fix(eks): add tag update support for eks cluster

Open mrlikl opened this issue 9 months ago • 1 comments

Issue # (if applicable)

Closes #19388

Reason for this change

Adding tag/untag for eks cluster post its creation

Description of changes

Added API calls tagResource and untagResource in Cluster resource handler to handle tag changes

Description of how you validated changes

Have tested the changes by first deploying a cluster with below config:

const vpc = ec2.Vpc.fromLookup(stack, 'Vpc', { isDefault: true });
new eks.Cluster(stack, 'Cluster', {
  vpc,
  ...getClusterVersionConfig(stack, eks.KubernetesVersion.V1_29),
  defaultCapacity: 0,
 tags: {
    foo: 'bar',
  },
});

TestCase - 1 Update to add one more tag

new eks.Cluster(stack, 'Cluster', {
  vpc,
  ...getClusterVersionConfig(stack, eks.KubernetesVersion.V1_29),
  defaultCapacity: 0,
  tags: {
    foo: 'bar',
   hello: "world"
  },
});

Logs -

{
    "updates": {
        "replaceName": false,
        "replaceVpc": false,
        "updateAccess": false,
        "replaceRole": false,
        "updateVersion": false,
        "updateEncryption": false,
        "updateLogging": false,
        "updateTags": true
    }
}
{
  clientName: 'EKSClient',
  commandName: 'TagResourceCommand',
  input: {
    resourceArn: 'arn:aws:eks:us-east-1:xxxxx:cluster/Cluster9EE0221C-f0d60e8e0bf14fb5896ade518b5bbc15',
    tags: { hello: 'world' }
  },
  output: {},
  metadata: {}
}

TestCase2 - Add, update and remove at the same time

new eks.Cluster(stack, 'Cluster', {
  vpc,
  ...getClusterVersionConfig(stack, eks.KubernetesVersion.V1_29),
  defaultCapacity: 0,
  tags: {
    hello: 'world1',
    foobar: 'baz',
  },
  endpointAccess: eks.EndpointAccess.PUBLIC,
  vpcSubnets: [{ subnetType: ec2.SubnetType.PUBLIC }],
});
{
  clientName: 'EKSClient',
  commandName: 'TagResourceCommand',
  input: {
    resourceArn: 'arn:aws:eks:us-east-1:xxxxx:cluster/Cluster9EE0221C-f0d60e8e0bf14fb5896ade518b5bbc15',
    tags: { foobar: 'baz', hello: 'world1' }
  },
  output: {},
  metadata: {}
}
{
  clientName: 'EKSClient',
  commandName: 'UntagResourceCommand',
  input: {
    resourceArn: 'arn:aws:eks:us-east-1:xxxxx:cluster/Cluster9EE0221C-f0d60e8e0bf14fb5896ade518b5bbc15',
    tagKeys: [ 'foo' ]
  },
  output: {},
  metadata: {}
}

TestCase - 3 Remove all tags

new eks.Cluster(stack, 'Cluster', {
  vpc,
  ...getClusterVersionConfig(stack, eks.KubernetesVersion.V1_29),
  defaultCapacity: 0,
  endpointAccess: eks.EndpointAccess.PUBLIC,
  vpcSubnets: [{ subnetType: ec2.SubnetType.PUBLIC }],
});
{
  clientName: 'EKSClient',
  commandName: 'UntagResourceCommand',
  input: {
    resourceArn: 'arn:aws:eks:us-east-1:xxxxx:cluster/Cluster9EE0221C-f0d60e8e0bf14fb5896ade518b5bbc15',
    tagKeys: [ 'foobar', 'hello' ]
  },
  output: {},
  metadata: {}

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

mrlikl avatar May 09 '24 12:05 mrlikl

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: e2da4e9d04fa036058ea992ee58a944807eecf35
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

aws-cdk-automation avatar May 13 '24 20:05 aws-cdk-automation

@shikha372 I have made the proposed changes, please take a look

mrlikl avatar May 16 '24 16:05 mrlikl

@shikha372 I have made the proposed changes, please take a look

Thank you @mrlikl full coverage with unit tests now :)... wdyt about integ test , just last step of verification to confirm that API is working as expected

shikha372 avatar May 24 '24 22:05 shikha372

Thank you @mrlikl full coverage with unit tests now :)... wdyt about integ test , just last step of verification to confirm that API is working as expected

@shikha372 The updates were manually tested I was unable to convert that flow to an integ test.

mrlikl avatar May 25 '24 22:05 mrlikl

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

mergify[bot] avatar May 29 '24 17:05 mergify[bot]

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

mergify[bot] avatar May 29 '24 17:05 mergify[bot]

@mergifyio update

shikha372 avatar May 31 '24 02:05 shikha372

update

✅ Branch has been successfully updated

mergify[bot] avatar May 31 '24 02:05 mergify[bot]

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: ed6dedffe813e94f3f4ef9f240db017d6f79ffbc
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

aws-cdk-automation avatar May 31 '24 02:05 aws-cdk-automation

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

mergify[bot] avatar May 31 '24 18:05 mergify[bot]

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.

aws-cdk-automation avatar Jul 25 '24 21:07 aws-cdk-automation