Commit afc35f18 authored by harshavardhan.c's avatar harshavardhan.c

fix: code fixes while registering new helm_template.

parent 6373f195
from copy import deepcopy from copy import deepcopy
from scripts.db.psql.databases import get_db_for_func import shortuuid
from scripts.schemas import GetRequest
if __name__ == "__main__": if __name__ == "__main__":
from dotenv import load_dotenv from dotenv import load_dotenv
load_dotenv() load_dotenv()
from scripts.db.psql.databases import get_db_for_func
from scripts.schemas import GetRequest
import argparse import argparse
import logging import logging
import os import os
...@@ -132,6 +134,7 @@ if __name__ == '__main__': ...@@ -132,6 +134,7 @@ if __name__ == '__main__':
# global_config_data = common_util.convert_yaml_to_json("ilens-global-configmap.yml") # global_config_data = common_util.convert_yaml_to_json("ilens-global-configmap.yml")
if repo_info: if repo_info:
global_config_data.update(repo_info) global_config_data.update(repo_info)
shortuuid.uuid()
variables_file = "variables.yml" variables_file = "variables.yml"
template_path = os.path.join(GENERAL_TEMP_PATH, "templates") template_path = os.path.join(GENERAL_TEMP_PATH, "templates")
if not os.path.exists(template_path): if not os.path.exists(template_path):
...@@ -177,12 +180,13 @@ if __name__ == '__main__': ...@@ -177,12 +180,13 @@ if __name__ == '__main__':
module_env_variables=module_env_variables, module_env_variables=module_env_variables,
helm_out_file_path=helm_out_file_path, helm_out_file_path=helm_out_file_path,
global_config_data=global_config_data, module_name=new_module) 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, else:
module_env_variables=module_env_variables, helm_handler.create_existing_helm_deployment_file(template_yml_path=existing_yml_path, image_tag=image_url,
helm_out_file_path=helm_out_file_path, module_env_variables=module_env_variables,
global_config_data=global_config_data, helm_out_file_path=helm_out_file_path,
module_name=new_module, template_file=template_file, global_config_data=global_config_data,
template_path=template_path ) module_name=new_module, template_file=template_file,
template_path=template_path)
if os.path.exists(base_helm_directory_path): if os.path.exists(base_helm_directory_path):
files_info = os.listdir(base_helm_directory_path) files_info = os.listdir(base_helm_directory_path)
sorted_files = list(filter(lambda f: f.startswith(_module), files_info)) sorted_files = list(filter(lambda f: f.startswith(_module), files_info))
......
...@@ -25,10 +25,12 @@ class HelmHandler: ...@@ -25,10 +25,12 @@ class HelmHandler:
existing_env_variables = {_v['name']: _v for _v in existing_env_variables = {_v['name']: _v for _v in
existing_data.get('deployment', {}).get('environmentVar', [])} existing_data.get('deployment', {}).get('environmentVar', [])}
diff_keys = list(set(existing_env_variables.keys()).symmetric_difference(set(module_env_variables.keys()))) diff_keys = list(set(existing_env_variables.keys()).symmetric_difference(set(module_env_variables.keys())))
module_port = ''
for _each in diff_keys: for _each in diff_keys:
if _each.lower() in {'port', 'service_port', 'module_port'} and module_env_variables.get(_each) and \ if _each.lower() in {'port', 'service_port', 'module_port', 'node_port'} and module_env_variables.get(
_each) and \
module_env_variables[_each].get("value"): module_env_variables[_each].get("value"):
global_config_vars["SERVICE_PORT"] = module_env_variables[_each]["value"] module_port = module_env_variables[_each]["value"]
continue continue
if module_env_variables.get(_each): if module_env_variables.get(_each):
existing_data['deployment']['environmentVar'].append(module_env_variables[_each]) existing_data['deployment']['environmentVar'].append(module_env_variables[_each])
...@@ -37,7 +39,7 @@ class HelmHandler: ...@@ -37,7 +39,7 @@ class HelmHandler:
self.common_utils.convert_json_to_yaml(json_data=existing_data, output_file_path=template_file) self.common_utils.convert_json_to_yaml(json_data=existing_data, output_file_path=template_file)
self.render_helm_chart(data_dict=global_config_vars, helm_template_file=f'{module_name}.yml', self.render_helm_chart(data_dict=global_config_vars, helm_template_file=f'{module_name}.yml',
outfile_path=helm_out_file_path, template_path=template_path, outfile_path=helm_out_file_path, template_path=template_path,
service_type=service_type) service_type=service_type, module_port=module_port)
return True return True
except Exception as e: except Exception as e:
logging.exception(f'Exception occurred while preparing the helm deployment file {e.args}') 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