Skip to content

Commit

Permalink
add support for passing helm chart values to aws-load-balancer-contro…
Browse files Browse the repository at this point in the history
…ller
  • Loading branch information
mtrspringer committed Apr 4, 2024
1 parent b82320b commit 5033cba
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/aws-cdk-lib/aws-eks/lib/alb-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,27 @@ export interface AlbControllerOptions {
* @default - Corresponds to the predefined version.
*/
readonly policy?: any;

/**
* Override values to be used by the chart.
* For nested values use a nested dictionary. For example:
* values: {
* autoscaling: false,
* ingressClassParams: { create: true }
* }
*
* Note that the following values are set by the controller and cannot be overridden:
* - clusterName
* - serviceAccount.create
* - serviceAccount.name
* - region
* - vpcId
* - image.repository
* - image.tag
*
* @default - No values are provided to the chart.
*/
readonly values?: {[key: string]: any};
}

/**
Expand Down Expand Up @@ -312,6 +333,7 @@ export class AlbController extends Construct {
wait: true,
timeout: Duration.minutes(15),
values: {
...(props.values ?? {}),
clusterName: props.cluster.clusterName,
serviceAccount: {
create: false,
Expand Down
84 changes: 84 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 @@ -118,3 +118,87 @@ test('correct helm chart version is set for selected alb controller version', ()
},
});
});

test('can pass values to the aws-load-balancer-controller helm chart', () => {
const { stack } = testFixture();

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

AlbController.create(stack, {
cluster,
version: AlbControllerVersion.V2_6_2,
repository: 'custom',
values: {
enableWafv2: false,
},
});

Template.fromStack(stack).hasResourceProperties(HelmChart.RESOURCE_TYPE, {
Version: '1.6.2', // The helm chart version associated with AlbControllerVersion.V2_6_2
Values: {
'Fn::Join': [
'',
[
'{"enableWafv2":false,"clusterName":"',
{
Ref: 'Cluster9EE0221C',
},
'","serviceAccount":{"create":false,"name":"aws-load-balancer-controller"},"region":"us-east-1","vpcId":"',
{
Ref: 'ClusterDefaultVpcFA9F2722',
},
'","image":{"repository":"custom","tag":"v2.6.2"}}',
],
],
},
});
});

test('values passed to the aws-load-balancer-controller do not override values set by construct', () => {
const { stack } = testFixture();

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

AlbController.create(stack, {
cluster,
version: AlbControllerVersion.V2_6_2,
repository: 'custom',
values: {
clusterName: 'test-cluster',
serviceAccount: {
create: true,
name: 'test-service-account',
},
region: 'test-region',
vpcId: 'test-vpc-id',
image: {
repository: 'test-repository',
tag: 'test-tag',
},
},
});

Template.fromStack(stack).hasResourceProperties(HelmChart.RESOURCE_TYPE, {
Version: '1.6.2', // The helm chart version associated with AlbControllerVersion.V2_6_2
Values: {
'Fn::Join': [
'',
[
'{"clusterName":"',
{
Ref: 'Cluster9EE0221C',
},
'","serviceAccount":{"create":false,"name":"aws-load-balancer-controller"},"region":"us-east-1","vpcId":"',
{
Ref: 'ClusterDefaultVpcFA9F2722',
},
'","image":{"repository":"custom","tag":"v2.6.2"}}',
],
],
},
});
});

0 comments on commit 5033cba

Please sign in to comment.