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
ccd1cd04
Commit
ccd1cd04
authored
Jun 26, 2023
by
prakash.raguri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix-26-06-2023
parent
1f8bac27
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
10 deletions
+56
-10
helm_automation/helm_automate_script.py
helm_automation/helm_automate_script.py
+34
-8
scripts/core/git_handler.py
scripts/core/git_handler.py
+22
-2
No files found.
helm_automation/helm_automate_script.py
View file @
ccd1cd04
...
...
@@ -24,7 +24,26 @@ helm_repo = EnvironmentVariables.helm_repo
mapping_json
=
{
"visualization-4"
:
"visualization4.0"
,
"metadata-service"
:
"metadata-services"
"metadata-service"
:
"metadata-services"
,
"workflow-management"
:
"workflow-management-v2"
,
"flow-parser"
:
"flow-parser-pipeline-builder"
,
"iot-data-processor-worker-solar"
:
"data-processor-worker"
,
"iot-data-processor-worker"
:
"data-processor-worker"
,
"mqtt-data-processor-worker"
:
"data-processor-worker"
,
"http-data-processor-worker"
:
"data-processor-worker"
,
"data-processor-worker-iot-apollo"
:
"data-processor-worker"
,
"data-processor-worker-iot-goodyear"
:
"data-processor-worker"
,
"data-processor-worker-mqtt-app"
:
"data-processor-worker"
,
"data-processor-worker-mqtt-demo"
:
"data-processor-worker"
,
"ilens-notifications"
:
"notification-engine"
,
"ilens_scheduler"
:
"ilens-scheduler"
,
"data-export-celery"
:
"data-import"
,
"data-management-celery"
:
"data-import"
,
"ilens-notifications-batch-email-trigger"
:
"notification-engine"
,
"simulation-services"
:
"simulation-services"
,
"chiller-efficiency-calculation"
:
"chiller-efficiency-calculation"
,
"chiller-vibration-anomaly"
:
"chiller-vibration-anomaly"
,
"audit-management-worker"
:
"audit-management"
}
...
...
@@ -54,11 +73,13 @@ class HelmVersionUpgrade:
"global_configmap, git_repos, client_name, ilens_version and release_version details not found!!!!!"
)
sys
.
exit
()
_branch
=
f
"{_client_name}_{_ilens_version}.{_release_version}"
_backup_branch
=
f
"v{_ilens_version}.{(int(_release_version) - 1)}-{_client_name}"
if
not
os
.
path
.
exists
(
helm_temp_path
):
os
.
makedirs
(
helm_temp_path
)
if
not
os
.
path
.
exists
(
output_path
):
os
.
makedirs
(
output_path
)
helm_path
=
os
.
path
.
join
(
helm_temp_path
,
"helm-charts"
)
self
.
git_handler_obj
.
create_backup_branch
(
repo_link
=
helm_repo
,
current_branch
=
_client_name
,
target_branch
=
_backup_branch
)
if
not
self
.
git_handler_obj
.
clone_repository
(
repo_link
=
helm_repo
,
module_output_path
=
helm_path
,
clone_branch
=
_client_name
):
logging
.
error
(
f
"Cannot clone helm repo with branch: {_client_name}"
)
...
...
@@ -82,10 +103,13 @@ class HelmVersionUpgrade:
for
_module
in
_module_names
:
updated_module_name
=
mapping_json
.
get
(
_module
,
_module
)
if
_module
==
"data"
:
continue
continue
helm_out_file_path
=
os
.
path
.
join
(
output_path
,
f
'{_module}.yml'
)
if
_module
in
ModuleConstants
.
IOT_DATA_PROCESSOR
:
_module
=
ModuleConstants
.
IOT_DATA_PROCESSOR_MODULE
_original_module
=
""
# if _module in ModuleConstants.IOT_DATA_PROCESSOR:
# _original_module = _module
# _module = ModuleConstants.IOT_DATA_PROCESSOR_MODULE
_original_module
=
_module
module_path
=
os
.
path
.
join
(
general_temp_path
)
module_path
=
os
.
path
.
join
(
module_path
,
_module
)
if
not
os
.
path
.
exists
(
module_path
):
...
...
@@ -94,7 +118,7 @@ class HelmVersionUpgrade:
logging
.
debug
(
f
"Helm Deployment File found for selected the module {_module}"
)
continue
variables_file_path
=
os
.
path
.
join
(
module_path
,
variables_file
)
git_info
=
self
.
git_handler_obj
.
get_git_url_by_module_name
(
module_name
=
updated_module_name
)
git_info
=
self
.
git_handler_obj
.
get_git_url_by_module_name
(
module_name
=
updated_module_name
)
#or _original_module)
if
not
git_info
:
logging
.
debug
(
"Failed to fetch module info!! Skipping Helm File Preparation"
)
continue
...
...
@@ -125,10 +149,12 @@ class HelmVersionUpgrade:
template_path
=
template_path
,
helm_out_file_path
=
helm_out_file_path
,
global_config_data
=
global_config_data
,
module_name
=
_module
)
module_name
=
_
original_module
or
_
module
)
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
]
# sorted_files = list(filter(lambda f: f.startswith((_original_module or _module)), files_info))
sorted_files
=
list
(
filter
(
lambda
f
:
f
.
startswith
((
_original_module
or
_module
)),
files_info
))
updated_files_info
=
[
x
for
x
in
sorted_files
if
f
'{_original_module or _module}.yml'
!=
x
]
# print("updated_files_info",updated_files_info)
for
_file
in
updated_files_info
:
sub_file_path
=
os
.
path
.
join
(
base_helm_directory_path
,
_file
)
helm_out_file_path
=
os
.
path
.
join
(
output_path
,
_file
)
...
...
scripts/core/git_handler.py
View file @
ccd1cd04
...
...
@@ -21,8 +21,10 @@ class GitHandler:
try
:
if
repo_link
.
split
(
"https://"
)[
-
1
]
.
startswith
(
"gitlab-pm"
):
repo_link
=
repo_link
.
replace
(
"https://"
,
f
"https://{self.user_name}:{self.access_token}@"
)
# print ("repo_link", repo_link)
repo
=
git
.
Repo
.
clone_from
(
repo_link
,
module_output_path
,
branch
=
clone_branch
)
return
True
except
Exception
as
e
:
logging
.
exception
(
f
"Exception occurred while cloning the git repo - {repo_link} - {e.args}"
)
...
...
@@ -39,7 +41,7 @@ class GitHandler:
pl
=
gl
.
projects
.
list
(
search
=
search_str
)
if
not
pl
:
return
False
pl
=
pl
[
0
]
pl
=
pl
[
-
1
]
with
open
(
file_output_path
,
'wb'
)
as
f
:
pl
.
files
.
raw
(
file_path
=
clone_file_path
,
ref
=
clone_branch
,
streamed
=
True
,
action
=
f
.
write
)
return
True
...
...
@@ -107,6 +109,24 @@ class GitHandler:
'title'
:
f
'{source_branch} merge'
})
def
create_backup_branch
(
self
,
repo_link
:
str
,
current_branch
:
str
,
target_branch
:
str
):
base_url
=
os
.
environ
.
get
(
"GIT_BASE_URL"
,
default
=
default_link
)
repo_link_split
=
repo_link
.
split
(
base_url
)
if
not
repo_link_split
:
return
False
gl
=
gitlab
.
Gitlab
(
url
=
base_url
,
private_token
=
self
.
access_token
)
search_str
=
repo_link_split
[
-
1
]
.
replace
(
".git"
,
""
)
if
pl
:
=
gl
.
projects
.
list
(
search
=
search_str
):
pl
=
pl
[
0
]
else
:
return
False
current_branches
=
pl
.
tags
.
list
(
get_all
=
False
)
if
target_branch
in
[
tag
.
name
for
tag
in
current_branches
]:
#print("Tag already exists:", target_branch)
logging
.
error
(
f
"Tag already exists: {target_branch}"
)
return
False
pl
.
tags
.
create
({
'tag_name'
:
target_branch
,
'ref'
:
current_branch
})
@
staticmethod
def
push_deployments_to_git
(
repo_link
:
str
,
private_token
:
str
,
branch
:
str
,
folder_path
,
base_path
:
str
,
helm_deployment
=
True
):
...
...
@@ -134,6 +154,7 @@ class GitHandler:
if
not
files_list
:
logging
.
debug
(
'Files not found for pushing to git.'
)
for
file
in
files_list
:
print
()
file_path
=
f
'{file}'
if
helm_deployment
:
file_path
=
f
"{HELM_PATH}/{file}"
...
...
@@ -144,7 +165,6 @@ class GitHandler:
}
commit_actions
.
append
(
_action
)
commit_data
=
{
'branch'
:
branch
,
'commit_message'
:
f
"{branch} helm creation"
}
|
{
'actions'
:
commit_actions
}
pl
.
commits
.
create
(
commit_data
)
except
Exception
as
e
:
logging
.
exception
(
f
'Exception while pushing deployments to git: {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