Skip to content

Commit 8141be3

Browse files
committed
changes from code review
1 parent 7c30d18 commit 8141be3

File tree

4 files changed

+34
-33
lines changed

4 files changed

+34
-33
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as eks from 'aws-cdk-lib/aws-eks';
1111
const LATEST_VERSION: eks.AlbControllerVersion = eks.AlbControllerVersion.V2_8_2;
1212

1313
interface EksClusterAlbControllerStackProps extends StackProps {
14-
albControllerValues?: {[key:string]: any};
14+
albControllerHelmChartValues?: {[key:string]: any};
1515
}
1616

1717
class EksClusterAlbControllerStack extends Stack {
@@ -27,7 +27,7 @@ class EksClusterAlbControllerStack extends Stack {
2727
...getClusterVersionConfig(this, eks.KubernetesVersion.V1_30),
2828
albController: {
2929
version: LATEST_VERSION,
30-
values: props.albControllerValues,
30+
helmChartValues: props.albControllerHelmChartValues,
3131
},
3232
});
3333

@@ -77,7 +77,7 @@ class EksClusterAlbControllerStack extends Stack {
7777

7878
const app = new App();
7979
const stack = new EksClusterAlbControllerStack(app, 'aws-cdk-eks-cluster-alb-controller');
80-
const stackWithAlbControllerValues = new EksClusterAlbControllerStack(app, 'aws-cdk-eks-cluster-alb-controller-values', { albControllerValues: { enableWafv2: false } });
80+
const stackWithAlbControllerValues = new EksClusterAlbControllerStack(app, 'aws-cdk-eks-cluster-alb-controller-values', { albControllerHelmChartValues: { enableWafv2: false } });
8181
new integ.IntegTest(app, 'aws-cdk-cluster-alb-controller-integ', {
8282
testCases: [stack, stackWithAlbControllerValues],
8383
// Test includes assets that are updated weekly. If not disabled, the upgrade PR will fail.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ if (cluster.albController) {
692692
```
693693

694694
If you need to configure the underlying ALB Controller, you can pass optional values that will be forwarded to the underling HelmChart construct.
695-
For example, if your organization uses AWS Firewall Manager you will need to disable aws-load-balancer-controller's waf modification behavior or it will disassociate WAFs that are not specified in the Ingress' annotations.
695+
For example, if your organization uses AWS Firewall Manager you will need to disable aws-load-balancer-controller's waf modification behavior or it will periodically disassociate WAFs that are not specified in the Ingress' annotations.
696696

697697
Note: supported value options may vary depending on the version of the aws-load-balancer-controller helm chart you are using. You should consult the [ArtifactHub documentation](https://artifacthub.io/packages/helm/aws/aws-load-balancer-controller) for your version to ensure you are configuring the chart correctly.
698698

@@ -701,7 +701,7 @@ new eks.Cluster(this, 'HelloEKS', {
701701
version: eks.KubernetesVersion.V1_29,
702702
albController: {
703703
version: eks.AlbControllerVersion.V2_6_2,
704-
values: {
704+
helmChartValues: {
705705
enableWaf: false,
706706
enableWafv2: false,
707707
},

packages/aws-cdk-lib/aws-eks/lib/alb-controller.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ export interface AlbControllerOptions {
275275
/**
276276
* Override values to be used by the chart.
277277
* For nested values use a nested dictionary. For example:
278-
* values: {
278+
* helmChartValues: {
279279
* autoscaling: false,
280280
* ingressClassParams: { create: true }
281281
* }
@@ -291,7 +291,7 @@ export interface AlbControllerOptions {
291291
*
292292
* @default - No values are provided to the chart.
293293
*/
294-
readonly values?: {[key: string]: any};
294+
readonly helmChartValues?: {[key: string]: any};
295295
}
296296

297297
/**
@@ -352,6 +352,8 @@ export class AlbController extends Construct {
352352
}
353353

354354
// https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.2/deploy/installation/#add-controller-to-cluster
355+
const { helmChartValues = {} } = props;
356+
this.validateHelmChartValues(helmChartValues);
355357
const chart = new HelmChart(this, 'Resource', {
356358
cluster: props.cluster,
357359
chart: 'aws-load-balancer-controller',
@@ -363,7 +365,8 @@ export class AlbController extends Construct {
363365
wait: true,
364366
timeout: Duration.minutes(15),
365367
values: {
366-
...(props.values ?? {}),
368+
...helmChartValues,
369+
// if you modify these values, you must also update this.restrictedHelmChartValueKeys
367370
clusterName: props.cluster.clusterName,
368371
serviceAccount: {
369372
create: false,
@@ -402,4 +405,22 @@ export class AlbController extends Construct {
402405
}
403406
return resources.map(rewriteResource);
404407
}
408+
409+
private validateHelmChartValues(values: {[key: string]: any}) {
410+
const valuesKeySet = new Set(Object.keys(values));
411+
const invalidKeys = new Set([...valuesKeySet].filter((key) => this.restrictedHelmChartValueKeys.has(key)));
412+
if (invalidKeys.size > 0) {
413+
throw new Error(`The following aws-load-balancer-controller HelmChart value keys are restricted and cannot be overridden: ${Array.from(this.restrictedHelmChartValueKeys).join(', ')}. (Invalid keys: ${Array.from(invalidKeys).join(', ')})`);
414+
}
415+
}
416+
417+
private get restrictedHelmChartValueKeys(): Set<string> {
418+
return new Set([
419+
'clusterName',
420+
'serviceAccount',
421+
'region',
422+
'vpcId',
423+
'image',
424+
]);
425+
}
405426
}

packages/aws-cdk-lib/aws-eks/test/alb-controller.test.ts

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ test('can pass values to the aws-load-balancer-controller helm chart', () => {
164164
cluster,
165165
version: AlbControllerVersion.V2_6_2,
166166
repository: 'custom',
167-
values: {
167+
helmChartValues: {
168168
enableWafv2: false,
169169
},
170170
});
@@ -190,18 +190,18 @@ test('can pass values to the aws-load-balancer-controller helm chart', () => {
190190
});
191191
});
192192

193-
test('values passed to the aws-load-balancer-controller do not override values set by construct', () => {
193+
test('values passed to the aws-load-balancer-controller result in an error if they conflict with restricted values set by the construct', () => {
194194
const { stack } = testFixture();
195195

196196
const cluster = new Cluster(stack, 'Cluster', {
197197
version: KubernetesVersion.V1_27,
198198
});
199199

200-
AlbController.create(stack, {
200+
expect(() => AlbController.create(stack, {
201201
cluster,
202202
version: AlbControllerVersion.V2_6_2,
203203
repository: 'custom',
204-
values: {
204+
helmChartValues: {
205205
clusterName: 'test-cluster',
206206
serviceAccount: {
207207
create: true,
@@ -214,27 +214,7 @@ test('values passed to the aws-load-balancer-controller do not override values s
214214
tag: 'test-tag',
215215
},
216216
},
217-
});
218-
219-
Template.fromStack(stack).hasResourceProperties(HelmChart.RESOURCE_TYPE, {
220-
Version: '1.6.2', // The helm chart version associated with AlbControllerVersion.V2_6_2
221-
Values: {
222-
'Fn::Join': [
223-
'',
224-
[
225-
'{"clusterName":"',
226-
{
227-
Ref: 'Cluster9EE0221C',
228-
},
229-
'","serviceAccount":{"create":false,"name":"aws-load-balancer-controller"},"region":"us-east-1","vpcId":"',
230-
{
231-
Ref: 'ClusterDefaultVpcFA9F2722',
232-
},
233-
'","image":{"repository":"custom","tag":"v2.6.2"}}',
234-
],
235-
],
236-
},
237-
});
217+
})).toThrow(/The following aws-load-balancer-controller HelmChart value keys are restricted and cannot be overridden: .*/);
238218
});
239219

240220
describe('AlbController AwsAuth creation', () => {

0 commit comments

Comments
 (0)