in images/dataplane/nodegroup/app/nodegroup_ver_update.py [0:0]
def update_cluster(config_dict):
cluster_name = config_dict[ConfigKey.cluster_name_key]
node_group_name = config_dict[ConfigKey.node_group_key]
launch_template_name = config_dict[ConfigKey.launch_template_name]
launch_template_version = config_dict[ConfigKey.launch_template_version]
logger.info(f'Cluster found, named: {config_dict[ConfigKey.cluster_name_key]}')
# write config
configure_cli = f'aws eks update-kubeconfig --name {cluster_name}'
output = subprocess.run(f'{configure_cli}', encoding='utf-8', capture_output=True, shell=True)
if output.returncode != 0:
raise RuntimeError(f'Falied to create kube config file {output.stderr}.')
logger.info('Create kube config file.')
# updates existing config file
output = subprocess.run(['/usr/local/bin/eksctl', 'utils', 'write-kubeconfig', '--cluster', cluster_name],
encoding='utf-8', capture_output=True)
logger.info(output)
# update .kube/config for aws2 version of cli
subprocess.run(['sed', '-i', '-e', 's/command: aws/command: \/usr\/local\/bin\/aws/g', kube_config_path],
encoding='utf-8', capture_output=True)
# enable cluster logs
logger.info('run eksctl enable logs command')
output = subprocess.run(
f'/usr/local/bin/eksctl utils update-cluster-logging --cluster {cluster_name} --enable-types=controllerManager --approve',
encoding='utf-8', capture_output=True, shell=True)
command_output = get_stdout(output)
logger.info(f'enable cluster control plane logs: {command_output}')
# describe nodegroup
logger.info('run awscli to update nodegroup template version')
update_nodegroup_version = f'aws eks update-nodegroup-version --cluster-name {cluster_name} --nodegroup-name {node_group_name} --launch-template name={launch_template_name},version={launch_template_version}'
output = subprocess.run(f'{update_nodegroup_version}', encoding='utf-8', capture_output=True, shell=True)
command_output = get_stdout(output)
logger.info(f'update nodegroup dataplane output: {command_output}')
update_nodegroup_desc = json.loads(command_output)
return update_nodegroup_desc['update']['id']