Commit 7d0669d5 authored by harshavardhan.c's avatar harshavardhan.c

enh: fixes while registering to new module.

parent 52f52565
from copy import deepcopy
from scripts.db.psql.databases import get_db_for_func
from scripts.schemas import GetRequest
if __name__ == "__main__":
from dotenv import load_dotenv
......@@ -115,9 +118,9 @@ if __name__ == '__main__':
if not os.path.exists(OUTPUT_PATH):
os.makedirs(OUTPUT_PATH)
helm_path = os.path.join(HELM_TEMP_PATH, "helm-charts")
# if not git_handler_obj.clone_repository(repo_link=helm_repo, module_output_path=helm_path,
# clone_branch=_reference_branch or _client_name):
# logging.error(f"Cannot clone helm repo with branch: {_reference_branch or _client_name}")
if not git_handler_obj.clone_repository(repo_link=helm_repo, module_output_path=helm_path,
clone_branch=_reference_branch or _client_name):
logging.error(f"Cannot clone helm repo with branch: {_reference_branch or _client_name}")
base_helm_directory_path = os.path.join(HELM_TEMP_PATH, "helm-charts", "ilens-core", "ilens-modules")
if os.path.exists(base_helm_directory_path) and len(_module_names) == 1 and _module_names[0].lower() == "all":
updated_list = []
......@@ -127,7 +130,8 @@ if __name__ == '__main__':
global_config_data = common_util.convert_yaml_to_json(os.path.join(base_helm_directory_path, global_configmap))
# global_config_data = common_util.convert_yaml_to_json("ilens-global-configmap.yml")
if repo_info:
global_config_data.update(repo_info)
variables_file = "variables.yml"
template_path = os.path.join(GENERAL_TEMP_PATH, "templates")
if not os.path.exists(template_path):
......@@ -157,23 +161,29 @@ if __name__ == '__main__':
module_env_variables = {_v['name']: _v['value'] for _v in module_env_variables if
{'name', 'value'}.issubset(set(list(_v.keys())))}
template_file = os.path.join(template_path, f'{_module}.yml')
# session_obj = get_db_for_func()
# module_info = db_handler.get_module_versions(
# input_data=GetRequest(module_name=_module, client='iLens', ilens_version=_ilens_version,
# release_version=_release_version), db=session_obj)
# session_obj.close()
module_info = {}
session_obj = get_db_for_func()
module_info = db_handler.get_module_versions(
input_data=GetRequest(module_name=_module, client='iLens', ilens_version=_ilens_version,
release_version=_release_version), db=session_obj)
session_obj.close()
image_url = module_info.get("image_url", '') if module_info else ''
existing_yml_path = os.path.join(base_helm_directory_path, f'{_module}.yml')
new_module = deepcopy(_module)
worker_type = True if "worker" in _module or "celery" in _module else False
if not os.path.exists(existing_yml_path):
existing_yml_path = os.path.join("templates", "helm_deployment.yml")
new_module = "helm_deployment"
worker_type = True if "worker" in _module | "celery" in _module else False
helm_handler.create_helm_deployment_file(template_yml_path=existing_yml_path, image_tag=image_url,
module_env_variables=module_env_variables,
helm_out_file_path=helm_out_file_path,
global_config_data=global_config_data, module_name=new_module)
helm_handler.create_existing_helm_deployment_file(template_yml_path=existing_yml_path, image_tag=image_url,
module_env_variables=module_env_variables,
helm_out_file_path=helm_out_file_path,
global_config_data=global_config_data,
module_name=new_module, template_file=template_file,
template_path=template_path )
if os.path.exists(base_helm_directory_path):
files_info = os.listdir(base_helm_directory_path)
sorted_files = list(filter(lambda f: f.startswith(_module), files_info))
updated_files_info = [x for x in sorted_files if f'{_module}.yml' != x]
......@@ -181,8 +191,9 @@ if __name__ == '__main__':
sub_file_path = os.path.join(base_helm_directory_path, _file)
helm_out_file_path = os.path.join(OUTPUT_PATH, _file)
template_file = os.path.join(template_path, _file)
worker_type = True if "worker" in _module | "celery" in _module else False
helm_handler.create_existing_helm_deployment_file(template_yml_path=sub_file_path, image_tag=image_url,
worker_type = True if "worker" in _module or "celery" in _module else False
helm_handler.create_existing_helm_deployment_file(template_yml_path=sub_file_path,
image_tag=image_url,
module_env_variables=module_env_variables,
template_file=template_file,
template_path=template_path,
......@@ -190,8 +201,8 @@ if __name__ == '__main__':
global_config_data=global_config_data,
service_type=False,
module_name=_file.split(".yml")[0])
git_handler_obj.push_helm_deployments(helm_repo, git_access_token, _client_name, final_helm_path=OUTPUT_PATH,
base_path=helm_path)
# git_handler_obj.push_helm_deployments(helm_repo, git_access_token, _client_name, final_helm_path=OUTPUT_PATH,
# base_path=helm_path)
except Exception as e:
logging.exception(f"Exception Occurred while processing the Helm-Script Preparation {e.args}")
......
......@@ -65,13 +65,20 @@ class HelmHandler:
return False
global_config_vars = global_config_data.get('data', {})
for k, v in module_env_variables.items():
if k.lower() in {'port', 'service_port', 'module_port'} and v:
if 'module_port' not in global_config_vars:
global_config_vars["module_port"] = v
if 'node_port' not in global_config_vars:
global_config_vars["node_port"] = v
continue
if global_config_vars.get(k):
continue
global_config_vars.update({k: v})
value_key = v.strip("<{ }>")
global_config_vars.update({k: global_config_vars.get(value_key, v)})
self.render_helm_chart(data_dict=global_config_vars, helm_template_file=f'{module_name}.yml',
self.render_helm_chart(data_dict={}, helm_template_file=f'{module_name}.yml',
outfile_path=helm_out_file_path, template_path="templates",
service_type=service_type, image_url=image_tag)
service_type=service_type, image_url=image_tag, variables=global_config_vars)
return True
except Exception as e:
logging.exception(f'Exception occurred while preparing the helm deployment file {e.args}')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment