Skip to content

Commit

Permalink
Support asking Helm to wait for install to finish
Browse files Browse the repository at this point in the history
Currently, Helm will not wait until all applicable resources are in a ready
state before deciding a release is successful and moving on. This can be
problematic for subsequent chart installations that will necessarily fail
if the previous has not completed, even if explicitly added as a dependency.
  • Loading branch information
michaelmoussa committed Feb 14, 2020
1 parent 18c6c8f commit da34454
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/@aws-cdk/aws-eks/lib/helm-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ export interface HelmChartOptions {
* @default - No values are provided to the chart.
*/
readonly values?: {[key: string]: any};

/**
* Whether or not Helm should wait until all Pods, PVCs, Services, and minimum number of Pods of a
* Deployment, StatefulSet, or ReplicaSet are in a ready state before marking the release as successful.
* @default - Helm will not wait before marking release as successful
*/
readonly wait?: boolean;
}

/**
Expand Down Expand Up @@ -83,6 +90,7 @@ export class HelmChart extends Construct {
Release: props.release || this.node.uniqueId.slice(-53).toLowerCase(), // Helm has a 53 character limit for the name
Chart: props.chart,
Version: props.version,
Wait: props.wait || false,
Values: (props.values ? stack.toJsonString(props.values) : undefined),
Namespace: props.namespace || 'default',
Repository: props.repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def helm_handler(event, context):
release = props['Release']
chart = props['Chart']
version = props.get('Version', None)
wait = props.get('Wait', False)
namespace = props.get('Namespace', None)
repository = props.get('Repository', None)
values_text = props.get('Values', None)
Expand Down Expand Up @@ -51,7 +52,7 @@ def helm_handler(event, context):
except Exception as e:
logger.info("delete error: %s" % e)

def helm(verb, release, chart = None, repo = None, file = None, namespace = None, version = None):
def helm(verb, release, chart = None, repo = None, file = None, namespace = None, version = None, wait = False):
import subprocess
try:
cmnd = ['helm', verb, release]
Expand All @@ -67,6 +68,8 @@ def helm(verb, release, chart = None, repo = None, file = None, namespace = None
cmnd.extend(['--version', version])
if not namespace is None:
cmnd.extend(['--namespace', namespace])
if wait:
cmnd.append('--wait')
cmnd.extend(['--kubeconfig', kubeconfig])
output = subprocess.check_output(cmnd, stderr=subprocess.STDOUT, cwd=outdir)
logger.info(output)
Expand Down
11 changes: 11 additions & 0 deletions packages/@aws-cdk/aws-eks/test/test.helm-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ export = {
// THEN
expect(stack).to(haveResource(eks.HelmChart.RESOURCE_TYPE, { Values: '{\"foo\":123}' }));
test.done();
},
'should support waiting until everything is completed before marking release as successful'(test: Test) {
// GIVEN
const { stack, cluster } = testFixtureCluster();

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

// THEN
expect(stack).to(haveResource(eks.HelmChart.RESOURCE_TYPE, { Wait: true }));
test.done();
}
}
};

0 comments on commit da34454

Please sign in to comment.