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

chore(eks): support create namespace with helm #8787

Merged
merged 6 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/@aws-cdk/aws-eks/lib/helm-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ export interface HelmChartOptions {
* @default Duration.minutes(5)
*/
readonly timeout?: Duration;

/**
* create namespace if not exist
* @default true
*/
readonly createNamespace?: boolean;
}

/**
Expand Down Expand Up @@ -90,6 +96,11 @@ export class HelmChart extends Construct {
throw new Error('Helm chart timeout cannot be higher than 15 minutes.');
}

// default not to wait
const wait = props.wait ?? false;
// default to create new namespace
const createNamespace = props.createNamespace ?? true;

new CustomResource(this, 'Resource', {
serviceToken: provider.serviceToken,
resourceType: HelmChart.RESOURCE_TYPE,
Expand All @@ -99,11 +110,12 @@ 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,
Wait: wait || undefined, // props are stringified so we encode “false” as undefined
Timeout: timeout ? `${timeout.toString()}s` : undefined, // Helm v3 expects duration instead of integer
Values: (props.values ? stack.toJsonString(props.values) : undefined),
Namespace: props.namespace ?? 'default',
Repository: props.repository,
CreateNamespace: createNamespace || undefined,
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def helm_handler(event, context):
wait = props.get('Wait', False)
timeout = props.get('Timeout', None)
namespace = props.get('Namespace', None)
create_namespace = props.get('CreateNamespace', None)
eladb marked this conversation as resolved.
Show resolved Hide resolved
repository = props.get('Repository', None)
values_text = props.get('Values', None)

Expand All @@ -46,21 +47,23 @@ 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, wait, timeout)
helm('upgrade', release, chart, repository, values_file, namespace, version, wait, timeout, create_namespace)
elif request_type == "Delete":
try:
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, timeout = None):
def helm(verb, release, chart = None, repo = None, file = None, namespace = None, version = None, wait = False, timeout = None, create_namespace = None):
import subprocess

cmnd = ['helm', verb, release]
if not chart is None:
cmnd.append(chart)
if verb == 'upgrade':
cmnd.append('--install')
if create_namespace:
cmnd.append('--create-namespace')
if not repo is None:
cmnd.extend(['--repo', repo])
if not file is None:
Expand Down
Loading