Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@
{
"Ref": "Vpc8378EB38"
},
"\",\"image\":{\"repository\":\"602401143452.dkr.ecr.us-west-2.amazonaws.com/amazon/aws-load-balancer-controller\",\"tag\":\"v2.8.2\"}}"
"\",\"image\":{\"repository\":\"602401143452.dkr.ecr.us-west-2.amazonaws.com/amazon/aws-load-balancer-controller\",\"tag\":\"v2.8.2\"},\"enableWafv2\":false}"
]
]
},
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class EksClusterAlbControllerStack extends Stack {
...getClusterVersionConfig(this, eks.KubernetesVersion.V1_30),
albController: {
version: LATEST_VERSION,
additionalHelmChartValues: {
enableWafv2: false,
},
},
});

Expand Down
17 changes: 17 additions & 0 deletions packages/aws-cdk-lib/aws-eks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,23 @@ new eks.Cluster(this, 'HelloEKS', {
});
```

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:

```ts
import { KubectlV32Layer } from '@aws-cdk/lambda-layer-kubectl-v32';

new eks.Cluster(this, 'HelloEKS', {
version: eks.KubernetesVersion.V1_32,
albController: {
version: eks.AlbControllerVersion.V2_8_2,
additionalHelmChartValues: {
enableWafv2: false
}
},
kubectlLayer: new KubectlV32Layer(this, 'kubectl'),
});
```

The `albController` requires `defaultCapacity` or at least one nodegroup. If there's no `defaultCapacity` or available
nodegroup for the cluster, the `albController` deployment would fail.

Expand Down
35 changes: 32 additions & 3 deletions packages/aws-cdk-lib/aws-eks/lib/alb-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as iam from '../../aws-iam';

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

/**
* Controller version.
Expand Down Expand Up @@ -238,6 +238,28 @@ export enum AlbScheme {
INTERNET_FACING = 'internet-facing',
}

/**
* Helm chart options that can be set for AlbControllerChart
* To add any new supported values refer
* https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/main/helm/aws-load-balancer-controller/values.yaml
*/
export interface AlbControllerHelmChartOptions {

/**
* Enable or disable AWS WAFv2 on the ALB ingress controller.
*
* @default - no value defined for this helm chart option, so it will not be set in the helm chart values
*/
readonly enableWafv2?: boolean;

/**
* Enable or disable AWS WAF on the ALB ingress controller.
*
* @default - no value defined for this helm chart option, so it will not be set in the helm chart values
*/
readonly enableWaf?: boolean;
}

/**
* Options for `AlbController`.
*/
Expand Down Expand Up @@ -270,6 +292,13 @@ export interface AlbControllerOptions {
* @default - Corresponds to the predefined version.
*/
readonly policy?: any;

/**
* Additional helm chart values for ALB controller
*
* @default - no additional helm chart values
*/
readonly additionalHelmChartValues?: AlbControllerHelmChartOptions;
}

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

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

// https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.2/deploy/installation/#iam-permissions
Expand All @@ -337,7 +366,6 @@ export class AlbController extends Construct {
namespace,
release: 'aws-load-balancer-controller',
version: props.version.helmChartVersion,

wait: true,
timeout: Duration.minutes(15),
values: {
Expand All @@ -352,6 +380,7 @@ export class AlbController extends Construct {
repository: props.repository ?? '602401143452.dkr.ecr.us-west-2.amazonaws.com/amazon/aws-load-balancer-controller',
tag: props.version.version,
},
...props.additionalHelmChartValues, // additional helm chart options for ALB controller chart
},
});

Expand Down
40 changes: 40 additions & 0 deletions packages/aws-cdk-lib/aws-eks/test/alb-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,46 @@ test('correct helm chart version is set for selected alb controller version', ()
});
});

test.each([
{ setting: 'enableWaf', value: false },
{ setting: 'enableWafv2', value: false },
{ setting: 'enableWaf', value: true },
{ setting: 'enableWafv2', value: true },
])('custom WAF settings - $setting', ({ setting, value }) => {
// GIVEN
const { stack } = testFixture();
const cluster = new Cluster(stack, 'Cluster', {
version: KubernetesVersion.V1_27,
kubectlLayer: new KubectlV31Layer(stack, 'KubectlLayer'),
});

// WHEN
new AlbController(stack, 'AlbController', {
cluster,
version: AlbControllerVersion.V2_4_1,
additionalHelmChartValues: {
[setting]: value,
},
});

// THEN
const template = Template.fromStack(stack);
template.hasResourceProperties(HelmChart.RESOURCE_TYPE, {
Values: {
'Fn::Join': [
'',
Match.arrayWith([
'{"clusterName":"',
{ Ref: 'Cluster9EE0221C' },
'","serviceAccount":{"create":false,"name":"aws-load-balancer-controller"},"region":"us-east-1","vpcId":"',
{ Ref: 'ClusterDefaultVpcFA9F2722' },
`","image":{"repository":"602401143452.dkr.ecr.us-west-2.amazonaws.com/amazon/aws-load-balancer-controller","tag":"v2.4.1"},"${setting}":${value}}`,
]),
],
},
});
});

describe('AlbController AwsAuth creation', () => {
const setupTest = (authenticationMode?: AuthenticationMode) => {
const { stack } = testFixture();
Expand Down