Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eks): add atomic flag for aws-eks Helm Chart #29454

Merged
merged 10 commits into from
Apr 26, 2024
12 changes: 12 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 @@ -33,6 +33,7 @@ export interface HelmChartOptions {
* The repository which contains the chart. For example: https://charts.helm.sh/stable/
* @default - No repository will be used, which means that the chart needs to be an absolute URL.
*/

shikha372 marked this conversation as resolved.
Show resolved Hide resolved
readonly repository?: string;

/**
Expand Down Expand Up @@ -73,6 +74,13 @@ export interface HelmChartOptions {
*/
readonly timeout?: Duration;

/**
* 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;
shikha372 marked this conversation as resolved.
Show resolved Hide resolved

/**
* create namespace if not exist
* @default true
Expand Down Expand Up @@ -112,6 +120,7 @@ export class HelmChart extends Construct {
public readonly repository?: string;
public readonly version?: string;
public readonly chartAsset?: Asset;
public readonly atomic?: boolean;

constructor(scope: Construct, id: string, props: HelmChartProps) {
super(scope, id);
Expand Down Expand Up @@ -148,6 +157,8 @@ export class HelmChart extends Construct {
const createNamespace = props.createNamespace ?? true;
// default to not skip crd installation
const skipCrds = props.skipCrds ?? false;
// default to set atomic as false
const atomic = props.atomic ?? false;

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

Expand All @@ -168,6 +179,7 @@ export class HelmChart extends Construct {
Repository: this.repository,
CreateNamespace: createNamespace || undefined,
SkipCrds: skipCrds || undefined,
Atomic: atomic || undefined, // props are stringified so we encode “false” as undefined
shikha372 marked this conversation as resolved.
Show resolved Hide resolved
},
});
}
Expand Down
24 changes: 24 additions & 0 deletions packages/aws-cdk-lib/aws-eks/test/helm-chart.test.ts
shikha372 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,30 @@ describe('helm chart', () => {
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 });
});

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

//WHEN
new eks.HelmChart(stack, 'MyAtomicChart', { 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 timeout only after 10 minutes', () => {
// GIVEN
const { stack, cluster } = testFixtureCluster();
Expand Down
1 change: 1 addition & 0 deletions packages/aws-cdk-lib/awslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@
"docs-public-apis:aws-cdk-lib.aws_eks.HelmChart.chartAsset",
"docs-public-apis:aws-cdk-lib.aws_eks.HelmChart.repository",
"docs-public-apis:aws-cdk-lib.aws_eks.HelmChart.version",
"docs-public-apis:aws-cdk-lib.aws_eks.HelmChart.atomic",
"docs-public-apis:aws-cdk-lib.aws_elasticloadbalancing.LoadBalancer.loadBalancerCanonicalHostedZoneName",
"docs-public-apis:aws-cdk-lib.aws_elasticloadbalancing.LoadBalancer.loadBalancerCanonicalHostedZoneNameId",
"docs-public-apis:aws-cdk-lib.aws_elasticloadbalancing.LoadBalancer.loadBalancerDnsName",
Expand Down
Loading