Skip to content

Commit

Permalink
support timeout option for helm command
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardomourar committed Jun 3, 2020
1 parent c0246c8 commit 878cbd1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 9 additions & 2 deletions packages/@aws-cdk/aws-eks/lib/helm-chart.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Construct, CustomResource, Stack } from '@aws-cdk/core';
import { Construct, CustomResource, Duration, Stack } from '@aws-cdk/core';
import { Cluster } from './cluster';

/**
Expand Down Expand Up @@ -47,6 +47,12 @@ export interface HelmChartOptions {
* @default - Helm will not wait before marking release as successful
*/
readonly wait?: boolean;

/**
* Amount of time to wait for any individual Kubernetes operation. Maximum 15 minutes.
* @default Duration.minutes(5)
*/
readonly timeout?: Duration;
}

/**
Expand All @@ -68,7 +74,7 @@ export interface HelmChartProps extends HelmChartOptions {
*/
export class HelmChart extends Construct {
/**
* The CloudFormation reosurce type.
* The CloudFormation resource type.
*/
public static readonly RESOURCE_TYPE = 'Custom::AWSCDK-EKS-HelmChart';

Expand All @@ -89,6 +95,7 @@ export class HelmChart extends Construct {
Chart: props.chart,
Version: props.version,
Wait: props.wait || false,
Timeout: props.timeout && props.timeout.toSeconds(),
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 @@ -25,6 +25,7 @@ def helm_handler(event, context):
chart = props['Chart']
version = props.get('Version', None)
wait = props.get('Wait', False)
timeout = props.get('Timeout', None)
namespace = props.get('Namespace', None)
repository = props.get('Repository', None)
values_text = props.get('Values', None)
Expand All @@ -45,14 +46,14 @@ def helm_handler(event, context):
f.write(json.dumps(values, indent=2))

if request_type == 'Create' or request_type == 'Update':
helm('upgrade', release, chart, repository, values_file, namespace, version)
helm('upgrade', release, chart, repository, values_file, namespace, version, wait, timeout)
elif request_type == "Delete":
try:
helm('uninstall', release, namespace=namespace)
helm('uninstall', release, namespace=namespace, timeout=timeout)
except Exception as e:
logger.info("delete error: %s" % e)

def helm(verb, release, chart = None, repo = None, file = None, namespace = None, version = None, wait = False):
def helm(verb, release, chart = None, repo = None, file = None, namespace = None, version = None, wait = False, timeout = None):
import subprocess

cmnd = ['helm', verb, release]
Expand All @@ -70,6 +71,8 @@ def helm(verb, release, chart = None, repo = None, file = None, namespace = None
cmnd.extend(['--namespace', namespace])
if wait:
cmnd.append('--wait')
if not timeout is None:
cmnd.extend(['--timeout', timeout])
cmnd.extend(['--kubeconfig', kubeconfig])

retry = 3
Expand Down

0 comments on commit 878cbd1

Please sign in to comment.