-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
start refactoring toward python grpc client #56
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
daefcbd
start refactoring toward python grpc client
robertchoi80 1dcabfe
temp: one step further
robertchoi80 04660f1
temp: two steps further
robertchoi80 bdb6bd2
almost done except the last step
robertchoi80 df60457
move tks-specific WFT to tks-flow repo
robertchoi80 4156669
remove deprecated script
robertchoi80 c0aabde
use mutex to synchronize tasks
robertchoi80 d6674ed
add site_repo_url param
robertchoi80 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
136 changes: 136 additions & 0 deletions
136
templates/decapod-manifests/update-decapod-manifest-wftpl.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: WorkflowTemplate | ||
metadata: | ||
name: update-decapod-manifest | ||
namespace: argo | ||
spec: | ||
templates: | ||
- name: updateManifest | ||
synchronization: | ||
mutex: | ||
name: default | ||
inputs: | ||
parameters: | ||
- name: action | ||
value: "update" | ||
- name: cluster_name | ||
value: "hanu-reference" | ||
- name: app_group | ||
value: "lma" | ||
- name: chart | ||
value: "thanos" | ||
# kv_map_str usage # | ||
# - 'update' action: {"k1": "v1", "k2": "v2"} | ||
# - 'insert' action: above format or value as list type. For eg, {"key": [v1, v2]} | ||
- name: kv_map_str | ||
value: "" | ||
script: | ||
image: sktdev/python-centos-wf-worker:v1.0 | ||
command: ["python"] | ||
env: | ||
source: | | ||
import sys | ||
import argparse | ||
import git | ||
import ruamel.yaml | ||
import os | ||
import json | ||
|
||
action = "{{inputs.parameters.action}}" | ||
clusterName = "{{inputs.parameters.cluster_name}}" | ||
appGroup = "{{inputs.parameters.app_group}}" | ||
chartName = "{{inputs.parameters.chart}}" | ||
kvMapStr = "{{inputs.parameters.kv_map_str}}" | ||
kvMapStr2 = kvMapStr.replace("'", "\"") | ||
kvMap = json.loads(kvMapStr2) | ||
|
||
repo = None | ||
config = {} | ||
commit_msg = '' | ||
numChanged = 0 | ||
sitePath = './decapod-site' | ||
siteFileName = "{}/{}/site-values.yaml".format(clusterName,appGroup) | ||
siteFileNameFull = "{}/{}".format(sitePath, siteFileName) | ||
|
||
# Clone or re-use decapod-site repository # | ||
if not os.path.isdir(sitePath): | ||
print("Cloning repository...") | ||
|
||
repo = git.Repo.clone_from("{{workflow.parameters.site_repo_url}}", 'decapod-site') | ||
with repo.config_writer() as git_config: | ||
git_config.set_value('user', 'email', '[email protected]') | ||
git_config.set_value('user', 'name', 'TKS Argo') | ||
else: | ||
print("The repo already exists. Pulling latest updates..") | ||
|
||
repo = git.Repo(sitePath) | ||
repo.remotes.origin.pull() | ||
|
||
with open(siteFileNameFull, 'r') as f: | ||
config = ruamel.yaml.round_trip_load(f, preserve_quotes=True) | ||
|
||
charts = config["charts"] | ||
chartFound = [chart for chart in charts if chart['name'] == chartName][0] | ||
|
||
if action == 'update': | ||
for k,v in kvMap.items(): | ||
if (chartFound['override'][k] == v): | ||
print("The value {} isn't changed. Skipping update...".format(v)) | ||
else: | ||
chartFound['override'][k] = v | ||
numChanged += 1 | ||
commit_msg = "update items for {} chart in '{}' cluster".format(chartName, clusterName) | ||
elif action == 'insert': | ||
for k,v in kvMap.items(): | ||
# If the value is list type, then append one by one iterating over the list. | ||
if isinstance(v, list): | ||
for item in v: | ||
if item in chartFound['override'][k]: | ||
print("The value {} already exists.".format(item)) | ||
else: | ||
chartFound['override'][k].append(item) | ||
numChanged += 1 | ||
elif (v in chartFound['override'][k]): | ||
print("The value {} already exists.".format(v)) | ||
else: | ||
chartFound['override'][k].append(v) | ||
numChanged += 1 | ||
commit_msg = "insert items for {} chart in '{}' cluster".format(chartName, clusterName) | ||
elif action == 'delete': | ||
for k,v in kvMap.items(): | ||
if (v in chartFound['override'][k]): | ||
print("Found value '{}'. Deleting it...".format(v)) | ||
chartFound['override'][k].remove(v) | ||
numChanged += 1 | ||
else: | ||
print("The value {} doesn't exist.".format(v)) | ||
commit_msg = "delete items for {} chart in '{}' cluster".format(chartName, clusterName) | ||
else: | ||
sys.exit("Wrong action type") | ||
|
||
if numChanged == 0: | ||
print("Nothing updated. Exiting task..") | ||
sys.exit(0) | ||
|
||
############################### | ||
# Commit and push the changed # | ||
############################### | ||
|
||
with open(siteFileNameFull, 'w') as f: | ||
ruamel.yaml.round_trip_dump(config, f) | ||
|
||
diff = repo.git.diff(repo.head.commit.tree) | ||
print(diff) | ||
|
||
# Provide a list of the files to stage | ||
repo.index.add([siteFileName]) | ||
|
||
# Provide a commit message | ||
repo.index.commit(commit_msg) | ||
res = repo.remotes.origin.push()[0] | ||
|
||
# flag '256' means successful fast-forward | ||
if res.flags != 256: | ||
print(res.summary) | ||
sys.exit("Push failed!") | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
가독성을 위해 true, false flag 도 괜찮을 것 같습니다. 물론 중요하진 않습니다 ㅎㅎ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그렇네요. 굳이 수정된 갯수까진 알 필요 없으니 boolean 값으로 바꾸는게 좋겠네요