Skip to content

Commit 96d9eee

Browse files
committed
refactor deploy.py
1 parent 2db74c3 commit 96d9eee

File tree

1 file changed

+12
-27
lines changed

1 file changed

+12
-27
lines changed

src/warnet/deploy.py

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,17 @@
44
import click
55
import yaml
66

7-
from .k8s import get_default_namespace
8-
from .namespaces import (
9-
BITCOIN_CHART_LOCATION as NAMESPACES_CHART_LOCATION,
10-
)
11-
from .namespaces import (
12-
DEFAULTS_FILE as NAMESPACES_DEFAULTS_FILE,
13-
)
14-
from .namespaces import (
15-
NAMESPACES_FILE,
16-
)
17-
from .network import (
18-
BITCOIN_CHART_LOCATION as NETWORK_CHART_LOCATION,
19-
)
20-
from .network import (
21-
DEFAULTS_FILE as NETWORK_DEFAULTS_FILE,
22-
)
23-
24-
# Import necessary functions and variables from network.py and namespaces.py
25-
from .network import (
7+
from .constants import (
8+
BITCOIN_CHART_LOCATION,
9+
DEFAULTS_FILE,
2610
FORK_OBSERVER_CHART,
11+
HELM_COMMAND,
12+
NAMESPACES_FILE,
2713
NETWORK_FILE,
2814
)
15+
from .k8s import get_default_namespace
2916
from .process import stream_command
3017

31-
HELM_COMMAND = "helm upgrade --install --create-namespace"
32-
3318

3419
def validate_directory(ctx, param, value):
3520
directory = Path(value)
@@ -82,7 +67,6 @@ def deploy_fork_observer(directory: Path, debug: bool):
8267
override_string = ""
8368

8469
# Add an entry for each node in the graph
85-
# TODO: should this be moved into a chart, and only have substituted name and rpc_host values
8670
for i, node in enumerate(network_file["nodes"]):
8771
node_name = node.get("name")
8872
node_config = f"""
@@ -97,7 +81,6 @@ def deploy_fork_observer(directory: Path, debug: bool):
9781
"""
9882

9983
override_string += node_config
100-
# End loop
10184

10285
# Create yaml string using multi-line string format
10386
override_string = override_string.strip()
@@ -119,7 +102,7 @@ def deploy_fork_observer(directory: Path, debug: bool):
119102

120103
def deploy_network(directory: Path, debug: bool = False):
121104
network_file_path = directory / NETWORK_FILE
122-
defaults_file_path = directory / NETWORK_DEFAULTS_FILE
105+
defaults_file_path = directory / DEFAULTS_FILE
123106

124107
with network_file_path.open() as f:
125108
network_file = yaml.safe_load(f)
@@ -133,7 +116,7 @@ def deploy_network(directory: Path, debug: bool = False):
133116
node_name = node.get("name")
134117
node_config_override = {k: v for k, v in node.items() if k != "name"}
135118

136-
cmd = f"{HELM_COMMAND} {node_name} {NETWORK_CHART_LOCATION} --namespace {namespace} -f {defaults_file_path}"
119+
cmd = f"{HELM_COMMAND} {node_name} {BITCOIN_CHART_LOCATION} --namespace {namespace} -f {defaults_file_path}"
137120
if debug:
138121
cmd += " --debug"
139122

@@ -158,7 +141,7 @@ def deploy_network(directory: Path, debug: bool = False):
158141

159142
def deploy_namespaces(directory: Path):
160143
namespaces_file_path = directory / NAMESPACES_FILE
161-
defaults_file_path = directory / NAMESPACES_DEFAULTS_FILE
144+
defaults_file_path = directory / DEFAULTS_FILE
162145

163146
with namespaces_file_path.open() as f:
164147
namespaces_file = yaml.safe_load(f)
@@ -178,7 +161,9 @@ def deploy_namespaces(directory: Path):
178161
namespace_name = namespace.get("name")
179162
namespace_config_override = {k: v for k, v in namespace.items() if k != "name"}
180163

181-
cmd = f"{HELM_COMMAND} {namespace_name} {NAMESPACES_CHART_LOCATION} -f {defaults_file_path}"
164+
cmd = (
165+
f"{HELM_COMMAND} {namespace_name} {BITCOIN_CHART_LOCATION} -f {defaults_file_path}"
166+
)
182167

183168
if namespace_config_override:
184169
with tempfile.NamedTemporaryFile(

0 commit comments

Comments
 (0)