Skip to content

Commit 6f0605b

Browse files
authored
feat(eks): pass additional helm chart values to aws-load-balancer-controller (#34077)
### Issue # (if applicable) Closes #29707 . ### Reason for this change Currently passing in additional value to ALB helm chart is not supported. Added support for value `enableWaf` and `enableWafv2` List of supported values can be verified from https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/main/helm/aws-load-balancer-controller/values.yaml#L199 ### Description of changes - Added new interface `AlbControllerHelmChartOptions` to support additional helm chart values - Added support for boolean type value `enableWaf` and `enableWafv2` ### Describe any new or updated permissions being added NA ### Description of how you validated changes - Added Unit test - Modified integration test ### 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 2fac64e commit 6f0605b

File tree

6 files changed

+94
-5
lines changed

6 files changed

+94
-5
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-eks/test/integ.alb-controller.js.snapshot/aws-cdk-eks-cluster-alb-controller.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@
16421642
{
16431643
"Ref": "Vpc8378EB38"
16441644
},
1645-
"\",\"image\":{\"repository\":\"602401143452.dkr.ecr.us-west-2.amazonaws.com/amazon/aws-load-balancer-controller\",\"tag\":\"v2.8.2\"}}"
1645+
"\",\"image\":{\"repository\":\"602401143452.dkr.ecr.us-west-2.amazonaws.com/amazon/aws-load-balancer-controller\",\"tag\":\"v2.8.2\"},\"enableWafv2\":false}"
16461646
]
16471647
]
16481648
},

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

+1-1
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.alb-controller.ts

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class EksClusterAlbControllerStack extends Stack {
2222
...getClusterVersionConfig(this, eks.KubernetesVersion.V1_30),
2323
albController: {
2424
version: LATEST_VERSION,
25+
additionalHelmChartValues: {
26+
enableWafv2: false,
27+
},
2528
},
2629
});
2730

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

+17
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,23 @@ new eks.Cluster(this, 'HelloEKS', {
694694
});
695695
```
696696

697+
To provide additional Helm chart values supported by `albController` in CDK, use the `additionalHelmChartValues` property. For example, the following code snippet shows how to set the `enableWafV2` flag:
698+
699+
```ts
700+
import { KubectlV32Layer } from '@aws-cdk/lambda-layer-kubectl-v32';
701+
702+
new eks.Cluster(this, 'HelloEKS', {
703+
version: eks.KubernetesVersion.V1_32,
704+
albController: {
705+
version: eks.AlbControllerVersion.V2_8_2,
706+
additionalHelmChartValues: {
707+
enableWafv2: false
708+
}
709+
},
710+
kubectlLayer: new KubectlV32Layer(this, 'kubectl'),
711+
});
712+
```
713+
697714
The `albController` requires `defaultCapacity` or at least one nodegroup. If there's no `defaultCapacity` or available
698715
nodegroup for the cluster, the `albController` deployment would fail.
699716

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

+32-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as iam from '../../aws-iam';
88

99
// v2 - keep this import as a separate section to reduce merge conflict when forward merging with the v2 branch.
1010
// eslint-disable-next-line
11-
import { Aws, Duration, Names, Stack } from '../../core';
11+
import { Aws, Duration, Names, Stack, ValidationError } from '../../core';
1212

1313
/**
1414
* Controller version.
@@ -238,6 +238,28 @@ export enum AlbScheme {
238238
INTERNET_FACING = 'internet-facing',
239239
}
240240

241+
/**
242+
* Helm chart options that can be set for AlbControllerChart
243+
* To add any new supported values refer
244+
* https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/main/helm/aws-load-balancer-controller/values.yaml
245+
*/
246+
export interface AlbControllerHelmChartOptions {
247+
248+
/**
249+
* Enable or disable AWS WAFv2 on the ALB ingress controller.
250+
*
251+
* @default - no value defined for this helm chart option, so it will not be set in the helm chart values
252+
*/
253+
readonly enableWafv2?: boolean;
254+
255+
/**
256+
* Enable or disable AWS WAF on the ALB ingress controller.
257+
*
258+
* @default - no value defined for this helm chart option, so it will not be set in the helm chart values
259+
*/
260+
readonly enableWaf?: boolean;
261+
}
262+
241263
/**
242264
* Options for `AlbController`.
243265
*/
@@ -270,6 +292,13 @@ export interface AlbControllerOptions {
270292
* @default - Corresponds to the predefined version.
271293
*/
272294
readonly policy?: any;
295+
296+
/**
297+
* Additional helm chart values for ALB controller
298+
*
299+
* @default - no additional helm chart values
300+
*/
301+
readonly additionalHelmChartValues?: AlbControllerHelmChartOptions;
273302
}
274303

275304
/**
@@ -315,7 +344,7 @@ export class AlbController extends Construct {
315344
const serviceAccount = new ServiceAccount(this, 'alb-sa', { namespace, name: 'aws-load-balancer-controller', cluster: props.cluster });
316345

317346
if (props.version.custom && !props.policy) {
318-
throw new Error("'albControllerOptions.policy' is required when using a custom controller version");
347+
throw new ValidationError("'albControllerOptions.policy' is required when using a custom controller version", this);
319348
}
320349

321350
// https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.2/deploy/installation/#iam-permissions
@@ -337,7 +366,6 @@ export class AlbController extends Construct {
337366
namespace,
338367
release: 'aws-load-balancer-controller',
339368
version: props.version.helmChartVersion,
340-
341369
wait: true,
342370
timeout: Duration.minutes(15),
343371
values: {
@@ -352,6 +380,7 @@ export class AlbController extends Construct {
352380
repository: props.repository ?? '602401143452.dkr.ecr.us-west-2.amazonaws.com/amazon/aws-load-balancer-controller',
353381
tag: props.version.version,
354382
},
383+
...props.additionalHelmChartValues, // additional helm chart options for ALB controller chart
355384
},
356385
});
357386

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

+40
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,46 @@ test('correct helm chart version is set for selected alb controller version', ()
157157
});
158158
});
159159

160+
test.each([
161+
{ setting: 'enableWaf', value: false },
162+
{ setting: 'enableWafv2', value: false },
163+
{ setting: 'enableWaf', value: true },
164+
{ setting: 'enableWafv2', value: true },
165+
])('custom WAF settings - $setting', ({ setting, value }) => {
166+
// GIVEN
167+
const { stack } = testFixture();
168+
const cluster = new Cluster(stack, 'Cluster', {
169+
version: KubernetesVersion.V1_27,
170+
kubectlLayer: new KubectlV31Layer(stack, 'KubectlLayer'),
171+
});
172+
173+
// WHEN
174+
new AlbController(stack, 'AlbController', {
175+
cluster,
176+
version: AlbControllerVersion.V2_4_1,
177+
additionalHelmChartValues: {
178+
[setting]: value,
179+
},
180+
});
181+
182+
// THEN
183+
const template = Template.fromStack(stack);
184+
template.hasResourceProperties(HelmChart.RESOURCE_TYPE, {
185+
Values: {
186+
'Fn::Join': [
187+
'',
188+
Match.arrayWith([
189+
'{"clusterName":"',
190+
{ Ref: 'Cluster9EE0221C' },
191+
'","serviceAccount":{"create":false,"name":"aws-load-balancer-controller"},"region":"us-east-1","vpcId":"',
192+
{ Ref: 'ClusterDefaultVpcFA9F2722' },
193+
`","image":{"repository":"602401143452.dkr.ecr.us-west-2.amazonaws.com/amazon/aws-load-balancer-controller","tag":"v2.4.1"},"${setting}":${value}}`,
194+
]),
195+
],
196+
},
197+
});
198+
});
199+
160200
describe('AlbController AwsAuth creation', () => {
161201
const setupTest = (authenticationMode?: AuthenticationMode) => {
162202
const { stack } = testFixture();

0 commit comments

Comments
 (0)