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): kubectl 1.16.8-eks-e16311, aws-cli 1.18.86, helm 3.2.4 #8739

Merged
merged 11 commits into from
Jun 29, 2020
7 changes: 7 additions & 0 deletions 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 False
*/
readonly createNamespace?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry but this should be a separate PR :-)

[think about the changelog entry :-)]

I added comments on the namespace change as well here so it's PR can start from there

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like it makes more sense for this to be enabled by default, no? What are the implications?

}

/**
Expand Down Expand Up @@ -104,6 +110,7 @@ export class HelmChart extends Construct {
Values: (props.values ? stack.toJsonString(props.values) : undefined),
Namespace: props.namespace ?? 'default',
Repository: props.repository,
CreateNamespace: props.createNamespace ?? false,
},
});
}
Expand Down
43 changes: 26 additions & 17 deletions packages/@aws-cdk/aws-eks/lib/kubectl-handler/helm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
outdir = os.environ.get('TEST_OUTDIR', '/tmp')
kubeconfig = os.path.join(outdir, 'kubeconfig')


def helm_handler(event, context):
logger.info(json.dumps(event))

Expand All @@ -20,22 +21,23 @@ def helm_handler(event, context):

# resource properties
cluster_name = props['ClusterName']
role_arn = props['RoleArn']
release = props['Release']
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)
role_arn = props['RoleArn']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid aesthetic changes, those make the code review harder.

Any reason spacing was changed?

release = props['Release']
chart = props['Chart']
version = props.get('Version', None)
wait = props.get('Wait', False)
timeout = props.get('Timeout', None)
namespace = props.get('Namespace', None)
create_namespace = props.get('CreateNamespace', None)
repository = props.get('Repository', None)
values_text = props.get('Values', None)

# "log in" to the cluster
subprocess.check_call([ 'aws', 'eks', 'update-kubeconfig',
'--role-arn', role_arn,
'--name', cluster_name,
'--kubeconfig', kubeconfig
])
subprocess.check_call(['aws', 'eks', 'update-kubeconfig',
'--role-arn', role_arn,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

'--name', cluster_name,
'--kubeconfig', kubeconfig
])

# Write out the values to a file and include them with the install and upgrade
values_file = None
Expand All @@ -46,21 +48,26 @@ 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 not create_namespace is None:
cmnd.append('--create-namespace')
if not repo is None:
cmnd.extend(['--repo', repo])
if not file is None:
Expand All @@ -72,9 +79,11 @@ def helm(verb, release, chart = None, repo = None, file = None, namespace = None
if wait:
cmnd.append('--wait')
if not timeout is None:
cmnd.extend(['--timeout', timeout])
cmnd.extend(['--timeout', timeout])
cmnd.extend(['--kubeconfig', kubeconfig])

logger.info(cmnd)

retry = 3
while retry > 0:
try:
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-eks/lib/kubectl-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class KubectlProvider extends NestedStack {
runtime: lambda.Runtime.PYTHON_3_7,
handler: 'index.handler',
timeout: Duration.minutes(15),
layers: [ KubectlLayer.getOrCreate(this, { version: '2.0.0-beta2' }) ],
layers: [ KubectlLayer.getOrCreate(this, { version: '2.0.0' }) ],
memorySize: 256,
});

Expand Down
Loading