+
+
+def _get_kube_config_path(dmId: str, kubeconfig: dict) -> dict:
+
+ # TODO: update this kube file for each DMS k8s when it changes.
+
+ link_file_path = '/tmp/kubeconfig_' + dmId
+ if os.path.exists(link_file_path) and \
+ os.path.exists(os.readlink(link_file_path)):
+ return link_file_path
+
+ # Generate a random key for tmp kube config file
+ letters = string.ascii_uppercase
+ random_key = ''.join(random.choice(letters) for i in range(10))
+
+ # Get datetime of now as tag of the tmp file
+ current_time = datetime.now().strftime("%Y%m%d%H%M%S")
+ tmp_file_name = random_key + "_" + current_time
+ tmp_file_path = '/tmp/kubeconfig_' + tmp_file_name
+
+ data = config.gen_k8s_config_dict(
+ kubeconfig.pop('cluster_api_endpoint', None),
+ kubeconfig.pop('cluster_ca_cert', None),
+ kubeconfig.pop('admin_user', None),
+ kubeconfig.pop('admin_client_cert', None),
+ kubeconfig.pop('admin_client_key', None),
+ )
+
+ # write down the yaml file of kubectl into tmp folder
+ with open(tmp_file_path, 'w') as file:
+ yaml.dump(data, file)
+
+ # os.symlink(tmp_file_path, link_file_path)
+ os.symlink(tmp_file_path, '/tmp/tmp_'+tmp_file_name)
+ os.rename('/tmp/tmp_'+tmp_file_name, link_file_path)
+ if os.path.realpath(link_file_path) != tmp_file_path:
+ # Symlink was updated failed
+ logger.error('symlink update failed')
+
+ return link_file_path