-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchart-updater.py
executable file
·107 lines (95 loc) · 2.5 KB
/
chart-updater.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python3
import logging
import os
import threading
import click
from flask import Flask
from waitress import serve
from chart_updater.git import Git
from chart_updater.helm_repo import HelmRepo
from chart_updater.updater import Updater
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(message)s")
log = logging.getLogger("chart-updater")
app = Flask(__name__)
event = threading.Event()
@app.route("/api/v1/sync-git", methods=["POST"])
def refresh():
event.set()
log.info("Sync-git triggered")
return "Sync-git triggered."
@app.route("/")
def healthz():
return "", 204
@click.command()
@click.option("--git-url", required=True, help="Git config repo URL.")
@click.option(
"--git-branch", default="master", show_default=True, help="Git config repo ref."
)
@click.option("--git-path", default=".", show_default=True, help="Git config path.")
@click.option(
"--git-user",
default="Chart Sync",
show_default=True,
help="Git commit author's name.",
)
@click.option(
"--git-email",
default="[email protected]",
show_default=True,
help="Git commit author's email.",
)
@click.option(
"--git-timeout",
default=30,
show_default=True,
help="Git operations timeout (seconds).",
)
@click.option("--git-ssh-identity", help="Git config SSH identity file (key).")
@click.option("--helm-repo-url", required=True, help="Helm repo URL.")
@click.option("--helm-repo-user", help="Helm repo HTTP Auth user.")
@click.option(
"--helm-repo-password",
help="Helm repo HTTP Auth password.",
default=lambda: os.environ.get("HELM_REPO_PASSWORD", ""),
)
@click.option(
"--sync-interval",
default=60,
show_default=True,
help="Period of git sync (seconds).",
)
@click.option(
"--annotation-prefix",
default="rossum.ai",
show_default=True,
help="Prefix of k8s annotations.",
)
def chart_updater(
git_url,
git_branch,
git_path,
git_user,
git_email,
git_timeout,
git_ssh_identity,
helm_repo_url,
helm_repo_user,
helm_repo_password,
sync_interval,
annotation_prefix,
):
git = Git(
git_url,
git_branch,
git_path,
git_user,
git_email,
git_timeout,
git_ssh_identity,
)
chart = HelmRepo(helm_repo_url, helm_repo_user, helm_repo_password)
updater = Updater(git, chart, sync_interval, annotation_prefix, event=event)
updater.start()
serve(app, host="0.0.0.0", port=3030)
if __name__ == "__main__":
chart_updater()