forked from softwarefactory-project/sf-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-kazoo.py
More file actions
executable file
·60 lines (46 loc) · 1.46 KB
/
setup-kazoo.py
File metadata and controls
executable file
·60 lines (46 loc) · 1.46 KB
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
#!/usr/bin/env python3
# Copyright (C) 2026 Red Hat
# SPDX-License-Identifier: Apache-2.0
"""
A script to provide access to ZooKeeper through localhost.
Usage:
sudo mkdir -p /etc/zuul /var/lib/zuul
sudo chown $USER /etc/zuul /var/lib/zuul
python3 setup-kazoo.py
"""
import os, base64, subprocess
from kubernetes import client, config
config.load_kube_config()
v1 = client.CoreV1Api()
ns = config.list_kube_config_contexts()[1]["context"]["namespace"]
def setup_zuul_conf():
os.makedirs("/etc/zuul", exist_ok=True)
open("/etc/zuul/zuul.conf", "w").write(
base64.b64decode(
v1.read_namespaced_secret("zuul-config", ns).data["zuul.conf"]
).decode("utf-8")
)
def setup_zk_tls():
os.makedirs("/tls/client", exist_ok=True)
secret = v1.read_namespaced_secret("zookeeper-client-tls", ns)
for fp in ("ca.crt", "tls.crt", "tls.key"):
open("/tls/client/" + fp, "w").write(
base64.b64decode(secret.data[fp]).decode("utf-8")
)
def ensure_portforward():
# It's fine if it is already running
subprocess.Popen(["kubectl", "port-forward", "pod/zookeeper-0", "2281:2281"])
def read_tenant_config():
os.makedirs("/var/lib/zuul", exist_ok=True)
subprocess.Popen(
[
"kubectl",
"cp",
"zuul-scheduler-0:/var/lib/zuul/main.yaml",
"/var/lib/zuul/main.yaml",
]
).wait()
setup_zuul_conf()
setup_zk_tls()
read_tenant_config()
ensure_portforward()