Skip to content
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 8 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions scripts/updateEndpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/python3

import argparse
import git
import ruamel.yaml
import os
import sys

print("Entering updateEndpoint script..")

parser = argparse.ArgumentParser()
parser.add_argument('--action', required=True, type=str,
help="action to take: 'add' or 'delete'")
parser.add_argument('--cluster_name', required=True, type=str,
help="cluster name to which the endpoint is added")
parser.add_argument('--endpoint', required=True, type=str,
help="endpoint to add")

args = parser.parse_args()
action = args.action
clusterName = args.cluster_name
endpoint = args.endpoint
repo = None
config = {}
commit_msg = ''

sitePath = './decapod-site'
siteFileName = "{}/lma/site-values.yaml".format(clusterName)
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('https://github.com/robertchoi80/decapod-site', '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:
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"]
thanosChart = [chart for chart in charts if chart['name'] == "thanos"][0]

if action == 'add':
if (endpoint in thanosChart['override']['querier.stores']):
print("The endpoint already exists.")
sys.exit(0)
else:
#print("Before insertion: {}".format(thanosChart))
thanosChart['override']['querier.stores'].append(endpoint)
#print("After insertion: {}".format(thanosChart))
commit_msg = "add new thanos-sidecar endpoint to '{}' cluster".format(clusterName)
elif action == 'delete':
if (endpoint in thanosChart['override']['querier.stores']):
print("Found endpoint. Deleting it...")
thanosChart['override']['querier.stores'].remove(endpoint)
commit_msg = "delete thanos-sidecar endpoint from '{}' cluster".format(clusterName)
else:
print("The endpoint {} doesn't exist. Exiting script...".format(endpoint))
sys.exit(0)
else:
sys.exit("Wrong action type")

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!")

print("Exiting updateEndpoint script..")
2 changes: 1 addition & 1 deletion templates/argo-cd/createapp-wftpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
- name: repository_url
value: "https://github.com/openinfradev/decapod-manifests"
- name: revision
value: main
value: "main"
templates:
- name: createApp
inputs:
Expand Down
Loading