Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
Helm-Automation-Script
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
harshavardhan.c
Helm-Automation-Script
Commits
7d0669d5
You need to sign in or sign up before continuing.
Commit
7d0669d5
authored
Oct 17, 2022
by
harshavardhan.c
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
enh: fixes while registering to new module.
parent
52f52565
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
36 deletions
+54
-36
helm_register.py
helm_register.py
+44
-33
scripts/core/helm_handler.py
scripts/core/helm_handler.py
+10
-3
No files found.
helm_register.py
View file @
7d0669d5
from
copy
import
deepcopy
from
copy
import
deepcopy
from
scripts.db.psql.databases
import
get_db_for_func
from
scripts.schemas
import
GetRequest
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
from
dotenv
import
load_dotenv
from
dotenv
import
load_dotenv
...
@@ -115,9 +118,9 @@ if __name__ == '__main__':
...
@@ -115,9 +118,9 @@ if __name__ == '__main__':
if
not
os
.
path
.
exists
(
OUTPUT_PATH
):
if
not
os
.
path
.
exists
(
OUTPUT_PATH
):
os
.
makedirs
(
OUTPUT_PATH
)
os
.
makedirs
(
OUTPUT_PATH
)
helm_path
=
os
.
path
.
join
(
HELM_TEMP_PATH
,
"helm-charts"
)
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,
if
not
git_handler_obj
.
clone_repository
(
repo_link
=
helm_repo
,
module_output_path
=
helm_path
,
#
clone_branch=_reference_branch or _client_name):
clone_branch
=
_reference_branch
or
_client_name
):
#
logging.error(f"Cannot clone helm repo with 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"
)
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"
:
if
os
.
path
.
exists
(
base_helm_directory_path
)
and
len
(
_module_names
)
==
1
and
_module_names
[
0
]
.
lower
()
==
"all"
:
updated_list
=
[]
updated_list
=
[]
...
@@ -127,7 +130,8 @@ if __name__ == '__main__':
...
@@ -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
(
os
.
path
.
join
(
base_helm_directory_path
,
global_configmap
))
# 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
:
global_config_data
.
update
(
repo_info
)
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
):
...
@@ -157,41 +161,48 @@ if __name__ == '__main__':
...
@@ -157,41 +161,48 @@ if __name__ == '__main__':
module_env_variables
=
{
_v
[
'name'
]:
_v
[
'value'
]
for
_v
in
module_env_variables
if
module_env_variables
=
{
_v
[
'name'
]:
_v
[
'value'
]
for
_v
in
module_env_variables
if
{
'name'
,
'value'
}
.
issubset
(
set
(
list
(
_v
.
keys
())))}
{
'name'
,
'value'
}
.
issubset
(
set
(
list
(
_v
.
keys
())))}
template_file
=
os
.
path
.
join
(
template_path
,
f
'{_module}.yml'
)
template_file
=
os
.
path
.
join
(
template_path
,
f
'{_module}.yml'
)
# session_obj = get_db_for_func()
session_obj
=
get_db_for_func
()
# module_info = db_handler.get_module_versions(
module_info
=
db_handler
.
get_module_versions
(
# input_data=GetRequest(module_name=_module, client='iLens', ilens_version=_ilens_version,
input_data
=
GetRequest
(
module_name
=
_module
,
client
=
'iLens'
,
ilens_version
=
_ilens_version
,
# release_version=_release_version), db=session_obj)
release_version
=
_release_version
),
db
=
session_obj
)
# session_obj.close()
session_obj
.
close
()
module_info
=
{}
image_url
=
module_info
.
get
(
"image_url"
,
''
)
if
module_info
else
''
image_url
=
module_info
.
get
(
"image_url"
,
''
)
if
module_info
else
''
existing_yml_path
=
os
.
path
.
join
(
base_helm_directory_path
,
f
'{_module}.yml'
)
existing_yml_path
=
os
.
path
.
join
(
base_helm_directory_path
,
f
'{_module}.yml'
)
new_module
=
deepcopy
(
_module
)
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
):
if
not
os
.
path
.
exists
(
existing_yml_path
):
existing_yml_path
=
os
.
path
.
join
(
"templates"
,
"helm_deployment.yml"
)
existing_yml_path
=
os
.
path
.
join
(
"templates"
,
"helm_deployment.yml"
)
new_module
=
"helm_deployment"
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
,
helm_handler
.
create_helm_deployment_file
(
template_yml_path
=
existing_yml_path
,
image_tag
=
image_url
,
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
,
files_info
=
os
.
listdir
(
base_helm_directory_path
)
module_env_variables
=
module_env_variables
,
sorted_files
=
list
(
filter
(
lambda
f
:
f
.
startswith
(
_module
),
files_info
))
helm_out_file_path
=
helm_out_file_path
,
updated_files_info
=
[
x
for
x
in
sorted_files
if
f
'{_module}.yml'
!=
x
]
global_config_data
=
global_config_data
,
for
_file
in
updated_files_info
:
module_name
=
new_module
,
template_file
=
template_file
,
sub_file_path
=
os
.
path
.
join
(
base_helm_directory_path
,
_file
)
template_path
=
template_path
)
helm_out_file_path
=
os
.
path
.
join
(
OUTPUT_PATH
,
_file
)
if
os
.
path
.
exists
(
base_helm_directory_path
):
template_file
=
os
.
path
.
join
(
template_path
,
_file
)
files_info
=
os
.
listdir
(
base_helm_directory_path
)
worker_type
=
True
if
"worker"
in
_module
|
"celery"
in
_module
else
False
sorted_files
=
list
(
filter
(
lambda
f
:
f
.
startswith
(
_module
),
files_info
))
helm_handler
.
create_existing_helm_deployment_file
(
template_yml_path
=
sub_file_path
,
image_tag
=
image_url
,
updated_files_info
=
[
x
for
x
in
sorted_files
if
f
'{_module}.yml'
!=
x
]
module_env_variables
=
module_env_variables
,
for
_file
in
updated_files_info
:
template_file
=
template_file
,
sub_file_path
=
os
.
path
.
join
(
base_helm_directory_path
,
_file
)
template_path
=
template_path
,
helm_out_file_path
=
os
.
path
.
join
(
OUTPUT_PATH
,
_file
)
helm_out_file_path
=
helm_out_file_path
,
template_file
=
os
.
path
.
join
(
template_path
,
_file
)
global_config_data
=
global_config_data
,
worker_type
=
True
if
"worker"
in
_module
or
"celery"
in
_module
else
False
service_type
=
False
,
helm_handler
.
create_existing_helm_deployment_file
(
template_yml_path
=
sub_file_path
,
module_name
=
_file
.
split
(
".yml"
)[
0
])
image_tag
=
image_url
,
git_handler_obj
.
push_helm_deployments
(
helm_repo
,
git_access_token
,
_client_name
,
final_helm_path
=
OUTPUT_PATH
,
module_env_variables
=
module_env_variables
,
base_path
=
helm_path
)
template_file
=
template_file
,
template_path
=
template_path
,
helm_out_file_path
=
helm_out_file_path
,
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)
except
Exception
as
e
:
except
Exception
as
e
:
logging
.
exception
(
f
"Exception Occurred while processing the Helm-Script Preparation {e.args}"
)
logging
.
exception
(
f
"Exception Occurred while processing the Helm-Script Preparation {e.args}"
)
...
...
scripts/core/helm_handler.py
View file @
7d0669d5
...
@@ -65,13 +65,20 @@ class HelmHandler:
...
@@ -65,13 +65,20 @@ class HelmHandler:
return
False
return
False
global_config_vars
=
global_config_data
.
get
(
'data'
,
{})
global_config_vars
=
global_config_data
.
get
(
'data'
,
{})
for
k
,
v
in
module_env_variables
.
items
():
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
):
if
global_config_vars
.
get
(
k
):
continue
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"
,
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
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}'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment