in images/dataplane/daemonset/app/daemonset.py [0:0]
def update_cluster(config_dict):
cluster_name = config_dict[ConfigKey.cluster_name_key]
daemon = config_dict[ConfigKey.daemon_key]
name_space = config_dict[ConfigKey.name_space_key]
logger.info(f'Cluster found, named: {cluster_name}')
# 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.')
# update 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)
# list pods
output = subprocess.run(f'/usr/local/bin/kubectl get po -n {name_space}', encoding='utf-8', capture_output=True,
shell=True)
command_output = get_stdout(output)
daemon_pod_count = 0
for line in command_output.split('\n'):
if line.startswith(daemon):
daemon_pod_count += 1
output = subprocess.run(f'/usr/local/bin/eksctl utils update-{daemon} --cluster={cluster_name} --approve',
encoding='utf-8', capture_output=True, shell=True)
command_output = get_stdout(output)
logger.info(f'update-{daemon}: {command_output}')
return daemon_pod_count