Commit 8a30c4d9 authored by sangeetha's avatar sangeetha

updated script generation logic.

parent 144753c7
......@@ -36,7 +36,7 @@ def render_helm_chart(helm_name, data_dict, variables_list, helm_template_file):
output_path = "helm-charts"
if not os.path.exists(output_path):
os.makedirs(output_path)
helm_path = os.path.join(output_path, f'{helm_name}.yaml')
helm_path = os.path.join(output_path, f'{helm_name}.yml')
environment = jinja2.Environment(
loader=jinja2.FileSystemLoader(searchpath='./templates'),
......@@ -62,6 +62,17 @@ def clone_repository(repo_link, module_output_path, clone_branch):
logging.exception(f"Exception occurred while cloning the git repo - {repo_link} - {e.args}")
return False
def get_module_names_from_files():
try:
module_names = set()
dir_list = os.listdir(f'{REPO_CLONE_PATH}{HELM_PATH}')
for file in dir_list:
if file.endswith(".yml"):
module_names.add(file.removesuffix(".yml"))
return list(module_names)
except Exception as e:
logging.exception(f"Exception occurred while fetching module names from files: {e.args}")
def clone_repository_with_defined_file(repo_link: str, file_output_path, clone_branch, private_token, clone_file_path):
try:
......@@ -148,30 +159,13 @@ if __name__ == '__main__':
default=None,
help="Client Name Tag"
)
ap.add_argument(
"--module_details",
"-md",
required=False,
default=None,
type=json.loads,
help="Module details to be added in helm",
)
ap.add_argument(
"--exclude_files",
"-ef",
required=False,
default=[],
help="Files to be excluded from deleting from repo",
nargs="+"
)
arguments = vars(ap.parse_args())
_ilens_version = arguments["ilens_version"]
_release_version = arguments["release_version"]
_client_name = arguments['client_name']
_module_details = arguments['module_details']
_exclude_files = arguments["exclude_files"]
if not _ilens_version or not _release_version or not _client_name or not _module_details or not global_configmap:
print("global_configmap, module_details, client_name, ilens_version and release_version details not found!!!!!")
if not _ilens_version or not _release_version or not _client_name or not global_configmap:
print("global_configmap, client_name, ilens_version and release_version details not found!!!!!")
sys.exit()
_branch = f"{_client_name}_{_ilens_version}.{_release_version}"
try:
......@@ -180,11 +174,9 @@ if __name__ == '__main__':
sys.exit()
with open("config.json", "r") as f:
data = json.load(f)
_git_repos = [x['git_link'] for x in _module_details if x.get('git_link')]
_module_names = [x['module_name'] for x in _module_details if x.get('module_name')]
data['git_modules'] = [x for x in data['git_modules'] if (x['module_name'] in _module_names) or (x['git_link'] in _git_repos)]
_module_names = list(set(get_module_names_from_files()).difference(list(global_configmap.removesuffix(".yml"))))
data['git_modules'] = [x for x in data['git_modules'] if (x['module_name'] in _module_names)]
global_config_data = convert_yaml_to_json(global_configmap)
remove_all_files_from_repo(exclude_file=_exclude_files)
for _data in data.get('git_modules'):
_ilens_version = _data.get("ilens_version", _ilens_version)
_release_version = _data.get("ilens_version", _release_version)
......@@ -223,7 +215,11 @@ if __name__ == '__main__':
except Exception as e:
logging.exception(f'Unable to update helms: {e.args}')
finally:
if os.path.exists(REPO_CLONE_PATH):
shutil.rmtree(REPO_CLONE_PATH)
if os.path.exists("./tmp"):
shutil.rmtree("./tmp")
if os.path.exists(HELM_STORE_PATH):
shutil.rmtree(HELM_STORE_PATH)
if os.path.isfile(f"./{global_configmap}"):
os.remove(f"./{global_configmap}")
\ No newline at end of file
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