Skip to content

Commit b420033

Browse files
authored
feat(eks): Addon support configurationValues (#34061)
### Issue # (if applicable) Closes #34001 ### Description of changes `Addon` support configurationValues, both v1 and v2 ### Description of how you validated changes Unit + Integ ### 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*
1 parent 04061f2 commit b420033

17 files changed

+83
-16
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-eks/test/integ.eks-addon.js.snapshot/EksClusterWithAddonStack.assets.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-eks/test/integ.eks-addon.js.snapshot/EksClusterWithAddonStack.template.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,9 @@
526526
"S3Bucket": {
527527
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
528528
},
529-
"S3Key": "9953ad4c3e84d120643ece4b2e51caf43fd9850063641b4d78bf30fbe6b4d381.zip"
529+
"S3Key": "6094cb0ff874f89ab5ab24fb6b9417df0fdeb6966645f90c88ec1d7e28130112.zip"
530530
},
531-
"Description": "/opt/kubectl/kubectl 1.30; /opt/helm/helm 3.17.1",
531+
"Description": "/opt/kubectl/kubectl 1.32.3; /opt/helm/helm 3.17.2",
532532
"LicenseInfo": "Apache-2.0"
533533
}
534534
},
@@ -849,7 +849,7 @@
849849
]
850850
},
851851
"Config": {
852-
"version": "1.30",
852+
"version": "1.32",
853853
"roleArn": {
854854
"Fn::GetAtt": [
855855
"ClusterRoleFA261979",
@@ -1157,6 +1157,7 @@
11571157
"ClusterName": {
11581158
"Ref": "Cluster9EE0221C"
11591159
},
1160+
"ConfigurationValues": "{\"replicaCount\":2}",
11601161
"PreserveOnDelete": true
11611162
}
11621163
}

packages/@aws-cdk-testing/framework-integ/test/aws-eks/test/integ.eks-addon.js.snapshot/asset.9953ad4c3e84d120643ece4b2e51caf43fd9850063641b4d78bf30fbe6b4d381.zip

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/@aws-cdk-testing/framework-integ/test/aws-eks/test/integ.eks-addon.js.snapshot/tree.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-eks/test/integ.eks-addon.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ class EksClusterStack extends Stack {
1111
const vpc = new ec2.Vpc(this, 'Vpc', { natGateways: 1 });
1212
const cluster = new eks.Cluster(this, 'Cluster', {
1313
vpc,
14-
...getClusterVersionConfig(this, eks.KubernetesVersion.V1_30),
14+
...getClusterVersionConfig(this, eks.KubernetesVersion.V1_32),
1515
});
1616

1717
new eks.Addon(this, 'Addon', {
1818
addonName: 'coredns',
1919
cluster,
2020
preserveOnDelete: true,
21+
configurationValues: {
22+
replicaCount: 2,
23+
},
2124
});
2225
}
2326
}

packages/@aws-cdk/aws-eks-v2-alpha/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,10 +1079,13 @@ declare const cluster: eks.Cluster;
10791079

10801080
new eks.Addon(this, 'Addon', {
10811081
cluster,
1082-
addonName: 'aws-guardduty-agent',
1083-
addonVersion: 'v1.6.1',
1082+
addonName: 'coredns',
1083+
addonVersion: 'v1.11.4-eksbuild.2',
10841084
// whether to preserve the add-on software on your cluster but Amazon EKS stops managing any settings for the add-on.
10851085
preserveOnDelete: false,
1086+
configurationValues: {
1087+
replicaCount: 2,
1088+
},
10861089
});
10871090
```
10881091

packages/@aws-cdk/aws-eks-v2-alpha/lib/addon.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ export interface AddonProps {
4949
* @default true
5050
*/
5151
readonly preserveOnDelete?: boolean;
52+
53+
/**
54+
* The configuration values for the Add-on.
55+
*
56+
* @default - Use default configuration.
57+
*/
58+
readonly configurationValues?: Record<string, any>;
5259
}
5360

5461
/**
@@ -144,6 +151,7 @@ export class Addon extends Resource implements IAddon {
144151
clusterName: this.clusterName,
145152
addonVersion: props.addonVersion,
146153
preserveOnDelete: props.preserveOnDelete,
154+
configurationValues: this.stack.toJsonString(props.configurationValues),
147155
});
148156

149157
this.addonName = this.getResourceNameAttribute(resource.ref);

packages/@aws-cdk/aws-eks-v2-alpha/test/addon.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,26 @@ describe('Addon', () => {
7575
});
7676
});
7777

78+
test('create a new Addon with configurationValues', () => {
79+
// WHEN
80+
new Addon(stack, 'TestAddonWithPreserveOnDelete', {
81+
addonName: 'test-addon',
82+
cluster,
83+
configurationValues: {
84+
replicaCount: 2,
85+
},
86+
});
87+
88+
// THEN
89+
Template.fromStack(stack).hasResourceProperties('AWS::EKS::Addon', {
90+
AddonName: 'test-addon',
91+
ClusterName: {
92+
Ref: 'ClusterEB0386A7',
93+
},
94+
ConfigurationValues: '{\"replicaCount\":2}',
95+
});
96+
});
97+
7898
test('creates an Addon from attributes', () => {
7999
// GIVEN
80100
const addonName = 'test-addon';

packages/@aws-cdk/aws-eks-v2-alpha/test/integ.eks-addon.js.snapshot/EksClusterWithAddonStack.template.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,7 @@
11921192
"ClusterName": {
11931193
"Ref": "ClusterEB0386A7"
11941194
},
1195+
"ConfigurationValues": "{\"replicaCount\":2}",
11951196
"PreserveOnDelete": true
11961197
}
11971198
}

packages/@aws-cdk/aws-eks-v2-alpha/test/integ.eks-addon.js.snapshot/tree.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-eks-v2-alpha/test/integ.eks-addon.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class EksClusterStack extends Stack {
2121
addonName: 'coredns',
2222
cluster,
2323
preserveOnDelete: true,
24+
configurationValues: {
25+
replicaCount: 2,
26+
},
2427
});
2528
}
2629
}

packages/aws-cdk-lib/aws-eks/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,10 +1946,13 @@ declare const cluster: eks.Cluster;
19461946

19471947
new eks.Addon(this, 'Addon', {
19481948
cluster,
1949-
addonName: 'aws-guardduty-agent',
1950-
addonVersion: 'v1.6.1',
1949+
addonName: 'coredns',
1950+
addonVersion: 'v1.11.4-eksbuild.2',
19511951
// whether to preserve the add-on software on your cluster but Amazon EKS stops managing any settings for the add-on.
19521952
preserveOnDelete: false,
1953+
configurationValues: {
1954+
replicaCount: 2,
1955+
},
19531956
});
19541957
```
19551958

packages/aws-cdk-lib/aws-eks/lib/addon.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ export interface AddonProps {
4949
* @default true
5050
*/
5151
readonly preserveOnDelete?: boolean;
52+
53+
/**
54+
* The configuration values for the Add-on.
55+
*
56+
* @default - Use default configuration.
57+
*/
58+
readonly configurationValues?: Record<string, any>;
5259
}
5360

5461
/**
@@ -143,6 +150,7 @@ export class Addon extends Resource implements IAddon {
143150
clusterName: this.clusterName,
144151
addonVersion: props.addonVersion,
145152
preserveOnDelete: props.preserveOnDelete,
153+
configurationValues: this.stack.toJsonString(props.configurationValues),
146154
});
147155

148156
this.addonName = this.getResourceNameAttribute(resource.ref);

packages/aws-cdk-lib/aws-eks/test/addon.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,26 @@ describe('Addon', () => {
7575
});
7676
});
7777

78+
test('create a new Addon with configurationValues', () => {
79+
// WHEN
80+
new Addon(stack, 'TestAddonWithPreserveOnDelete', {
81+
addonName: 'test-addon',
82+
cluster,
83+
configurationValues: {
84+
replicaCount: 2,
85+
},
86+
});
87+
88+
// THEN
89+
Template.fromStack(stack).hasResourceProperties('AWS::EKS::Addon', {
90+
AddonName: 'test-addon',
91+
ClusterName: {
92+
Ref: 'Cluster9EE0221C',
93+
},
94+
ConfigurationValues: '{\"replicaCount\":2}',
95+
});
96+
});
97+
7898
test('creates an Addon from attributes', () => {
7999
// GIVEN
80100
const addonName = 'test-addon';

0 commit comments

Comments
 (0)