Skip to content

Commit

Permalink
feat(aws-eks): Allow atomic flag for helm chart
Browse files Browse the repository at this point in the history
* Add atomic flag for helm chart construct
* Update unit test
* Update README
  • Loading branch information
alexandersperling committed Dec 12, 2023
1 parent 14e5e50 commit d98088c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/aws-cdk-lib/aws-eks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,9 @@ new eks.HelmChart(this, 'NginxIngress', {
});
```

Helm can treat operations as atomic, if so, upgrade process rolls back changes made in case of failed upgrade.
The --wait flag will be set automatically if --atomic is used.

### OCI Charts

OCI charts are also supported.
Expand Down
10 changes: 10 additions & 0 deletions packages/aws-cdk-lib/aws-eks/lib/helm-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ export interface HelmChartOptions {
* @default - CRDs are installed if not already present
*/
readonly skipCrds?: boolean;

/**
* Whether or not Helm should treat this operation as atomic; if set, upgrade process rolls back changes
* made in case of failed upgrade. The --wait flag will be set automatically if --atomic is used.
* @default false;
*/
readonly atomic?: boolean;
}

/**
Expand Down Expand Up @@ -148,6 +155,8 @@ export class HelmChart extends Construct {
const createNamespace = props.createNamespace ?? true;
// default to not skip crd installation
const skipCrds = props.skipCrds ?? false;
// default to not use atomic operations
const atomic = props.atomic ?? false;

this.chartAsset?.grantRead(provider.handlerRole);

Expand All @@ -168,6 +177,7 @@ export class HelmChart extends Construct {
Repository: this.repository,
CreateNamespace: createNamespace || undefined,
SkipCrds: skipCrds || undefined,
Atomic: atomic || undefined,
},
});
}
Expand Down
22 changes: 22 additions & 0 deletions packages/aws-cdk-lib/aws-eks/test/helm-chart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,26 @@ describe('helm chart', () => {
Template.fromStack(stack).hasResourceProperties(eks.HelmChart.RESOURCE_TYPE, { SkipCrds: true });
});
});

test('should disable atomic operations by default', () => {
// GIVEN
const { stack, cluster } = testFixtureCluster();

// WHEN
new eks.HelmChart(stack, 'MyChart', { cluster, chart: 'chart' });

// THEN
const charts = Template.fromStack(stack).findResources(eks.HelmChart.RESOURCE_TYPE, { Atomic: true });
expect(Object.keys(charts).length).toEqual(0);
});
test('should enable atomic operations when specified', () => {
// GIVEN
const { stack, cluster } = testFixtureCluster();

// WHEN
new eks.HelmChart(stack, 'MyAtomicChart', { cluster, chart: 'chart', atomic: true });

// THEN
Template.fromStack(stack).hasResourceProperties(eks.HelmChart.RESOURCE_TYPE, { Atomic: true });
});
});

0 comments on commit d98088c

Please sign in to comment.