Skip to content

Commit

Permalink
fix(eks): add tag update support for eks cluster (aws#30123)
Browse files Browse the repository at this point in the history
### Issue # (if applicable)

Closes aws#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: 
```ts
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
```ts
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 
```ts
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

```ts
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
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
mrlikl authored and Dahlberg Victor committed Jun 10, 2024
1 parent 56d9f8c commit 1c45651
Show file tree
Hide file tree
Showing 30 changed files with 6,825 additions and 1 deletion.

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

Loading

0 comments on commit 1c45651

Please sign in to comment.