Skip to content

Commit e4e3ffd

Browse files
authored
helm chart seperations for sandbox (#55)
* helm chart seperations for sandbox * fix key file export
1 parent 543f79e commit e4e3ffd

File tree

4 files changed

+98
-40
lines changed

4 files changed

+98
-40
lines changed

application/service/k3s_service.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ def _initialize_k3s_control(
7777
try:
7878
external_ip = control_input.hostname
7979
disable_components = "traefik"
80-
install_exec = (
81-
f"--disable={disable_components} --flannel-backend=none --disable-network-policy --cluster-init"
82-
)
80+
install_exec = f"--disable={disable_components} --flannel-backend=none --disable-network-policy --cluster-init"
8381

8482
internal_ip, _ = run_ssh_command(
8583
ssh_client, self.INTERNAL_IP_CMD, task_id=task_id

application/service/provider_service.py

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,19 @@ def _install_helm(self, ssh_client, task_id: str):
4141

4242
def _setup_helm_repos(self, ssh_client, task_id: str):
4343
log.info("Setting up Helm repositories...")
44+
repo_name = "akash" if Config.CHAIN_ID == "akashnet-2" else "akash-dev"
45+
repo_url = ("https://akash-network.github.io/helm-charts" if repo_name == "akash"
46+
else "https://akash-network.github.io/helm-charts/dev")
47+
4448
commands = [
45-
"helm repo remove akash 2>/dev/null || true",
46-
"helm repo add akash https://akash-network.github.io/helm-charts",
47-
"helm repo update",
49+
f"helm repo remove {repo_name} 2>/dev/null || true",
50+
f"helm repo add {repo_name} {repo_url}",
4851
]
52+
53+
if repo_name == "akash-dev":
54+
commands.append("helm search repo akash-dev --devel")
55+
56+
commands.append("helm repo update")
4957
for cmd in commands:
5058
time.sleep(2)
5159
run_ssh_command(ssh_client, cmd, task_id=task_id)
@@ -55,14 +63,23 @@ def _install_akash_services(
5563
self, ssh_client, chain_id, provider_version, node_version, task_id: str
5664
):
5765
log.info("Installing Akash services...")
66+
# Define base helm commands based on chain ID
67+
repo_prefix = "akash" if chain_id == "akashnet-2" else "akash-dev"
68+
devel_flag = "" if chain_id == "akashnet-2" else " --devel"
69+
70+
# Common helm install parameters
71+
namespace = "-n akash-services"
72+
version_tag = f"--set image.tag={provider_version}"
73+
5874
commands = [
59-
f"helm install akash-hostname-operator akash/akash-hostname-operator -n akash-services --set image.tag={provider_version}",
60-
f"helm install inventory-operator akash/akash-inventory-operator -n akash-services --set image.tag={provider_version}",
75+
f"helm install akash-hostname-operator {repo_prefix}/akash-hostname-operator {namespace} {version_tag}{devel_flag}",
76+
f"helm install inventory-operator {repo_prefix}/akash-inventory-operator {namespace} {version_tag}{devel_flag}",
6177
]
62-
if chain_id != "sandbox-01":
63-
commands.append(
64-
f"helm install akash-node akash/akash-node -n akash-services --set image.tag={node_version}"
65-
)
78+
79+
# Add akash-node installation only for mainnet
80+
if chain_id == "akashnet-2":
81+
node_version_tag = f"--set image.tag={node_version}"
82+
commands.append(f"helm install akash-node akash/akash-node {namespace} {node_version_tag}")
6683
for cmd in commands:
6784
time.sleep(2)
6885
run_ssh_command(ssh_client, cmd, task_id=task_id)
@@ -90,7 +107,7 @@ def _prepare_provider_config(
90107
key: "{self._get_base64_encoded_key(ssh_client)}"
91108
keysecret: "{base64.b64encode(key_password.encode()).decode()}"
92109
domain: "{domain}"
93-
node: "http://akash-node-1:26657"
110+
node: "{f'http://akash-node-1:26657' if chain_id == 'akashnet-2' else 'https://rpc.sandbox-2.aksh.pw:443'}"
94111
withdrawalperiod: 12h
95112
chainid: "{chain_id}"
96113
organization: "{organization}"
@@ -144,7 +161,15 @@ def _install_akash_provider(self, ssh_client, provider_version, task_id: str):
144161
)
145162

146163
# Prepare the Helm install command
147-
install_cmd = f"helm install akash-provider akash/provider -n akash-services -f ~/provider/provider.yaml --set image.tag={provider_version}"
164+
# Determine helm repo and flags based on chain ID
165+
helm_repo = "akash" if Config.CHAIN_ID == "akashnet-2" else "akash-dev"
166+
devel_flag = "" if Config.CHAIN_ID == "akashnet-2" else "--devel"
167+
168+
install_cmd = (
169+
f"helm install akash-provider {helm_repo}/provider "
170+
f"-n akash-services -f ~/provider/provider.yaml "
171+
f"--set image.tag={provider_version} {devel_flag}".strip()
172+
)
148173

149174
if pricing_script_b64:
150175
install_cmd += f" --set bidpricescript='{pricing_script_b64}'"
@@ -582,7 +607,17 @@ async def restart_provider_service(self, ssh_client):
582607
provider_version = Config.PROVIDER_SERVICES_VERSION.replace("v", "")
583608

584609
# Upgrade helm chart with the pricing script
585-
command = f'helm upgrade --install akash-provider akash/provider -n akash-services -f ~/provider/provider.yaml --set bidpricescript="{pricing_script_b64}" --set image.tag={provider_version}'
610+
# Determine helm repo and flags based on chain ID
611+
helm_repo = "akash" if Config.CHAIN_ID == "akashnet-2" else "akash-dev"
612+
devel_flag = "" if Config.CHAIN_ID == "akashnet-2" else "--devel"
613+
614+
# Build helm upgrade command with consistent parameters
615+
command = (
616+
f'helm upgrade --install akash-provider {helm_repo}/provider '
617+
f'-n akash-services -f ~/provider/provider.yaml '
618+
f'--set bidpricescript="{pricing_script_b64}" '
619+
f'--set image.tag={provider_version} {devel_flag}'
620+
).strip()
586621
run_ssh_command(ssh_client, command)
587622

588623
time.sleep(10)

application/service/upgrade_service.py

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,21 @@ async def check_upgrade_status(self, ssh_client) -> Dict:
6868
"""
6969

7070
def get_versions():
71-
node_app_version, node_chart_version = self._get_helm_release_versions(
72-
ssh_client, "node"
73-
)
71+
# For mainnet (akashnet-2), get versions from helm release
72+
# For other networks, use configured versions since node is not deployed
73+
is_mainnet = Config.CHAIN_ID == "akashnet-2"
74+
75+
# Get node versions
76+
if is_mainnet:
77+
node_app_version, node_chart_version = self._get_helm_release_versions(
78+
ssh_client, "node"
79+
)
80+
else:
81+
# For non-mainnet, use configured versions since node is not deployed
82+
node_app_version = Config.AKASH_VERSION
83+
node_chart_version = Config.AKASH_NODE_HELM_CHART_VERSION
84+
85+
# Get provider versions
7486
provider_app_version, provider_chart_version = (
7587
self._get_helm_release_versions(ssh_client, "provider")
7688
)
@@ -175,17 +187,19 @@ async def upgrade_network(self, ssh_client, task_id: str) -> Dict:
175187
# Delete the pod to trigger upgrade
176188
# Update Helm repositories
177189
log.info("Updating Helm repositories...")
190+
helm_repo_cmd = "helm repo update akash" if Config.CHAIN_ID == "akashnet-2" else "helm repo update akash-dev"
178191
stdout, stderr = run_ssh_command(
179192
ssh_client,
180-
"helm repo update akash",
193+
helm_repo_cmd,
181194
True,
182195
task_id=task_id,
183196
)
184197
# Update Helm repositories
185198
log.info("Verifying akash-node chart availability...")
199+
helm_search_cmd = "helm search repo akash-node" if Config.CHAIN_ID == "akashnet-2" else "helm search repo akash-dev --devel"
186200
stdout, stderr = run_ssh_command(
187201
ssh_client,
188-
"helm search repo akash-node",
202+
helm_search_cmd,
189203
True,
190204
task_id=task_id,
191205
)
@@ -204,7 +218,10 @@ async def upgrade_network(self, ssh_client, task_id: str) -> Dict:
204218
# Upgrade akash-node deployment
205219
log.info(f"Upgrading akash-node to version {app_version}...")
206220
if app_needs_upgrade:
207-
upgrade_command = f"helm upgrade --install akash-node akash/akash-node -n akash-services --set image.tag={app_version}"
221+
if Config.CHAIN_ID == "akashnet-2":
222+
upgrade_command = f"helm upgrade --install akash-node akash/akash-node -n akash-services --set image.tag={app_version}"
223+
else:
224+
upgrade_command = f"helm upgrade --install akash-node akash-dev/akash-node -n akash-services --set image.tag={app_version} --devel"
208225
else:
209226
upgrade_command = (
210227
"kubectl delete pod -n akash-services -l app=akash-node"
@@ -267,17 +284,19 @@ async def upgrade_provider(self, ssh_client, task_id: str) -> Dict:
267284

268285
# Update Helm repositories
269286
log.info("Updating Helm repositories...")
287+
helm_repo_cmd = "helm repo update akash" if Config.CHAIN_ID == "akashnet-2" else "helm repo update akash-dev"
270288
stdout, stderr = run_ssh_command(
271289
ssh_client,
272-
"helm repo update akash",
290+
helm_repo_cmd,
273291
True,
274292
task_id=task_id,
275293
)
276294

277295
log.info(f"Upgrading provider to version {app_version}...")
296+
helm_search_cmd = "helm search repo provider" if Config.CHAIN_ID == "akashnet-2" else "helm search repo provider --devel"
278297
stdout, stderr = run_ssh_command(
279298
ssh_client,
280-
"helm search repo provider",
299+
helm_search_cmd,
281300
True,
282301
task_id=task_id,
283302
)
@@ -294,26 +313,18 @@ async def upgrade_provider(self, ssh_client, task_id: str) -> Dict:
294313

295314
# Backup existing values
296315
log.info("Backing up helm values...")
297-
backup_cmd = "cd /root/provider && for i in $(helm list -n akash-services -q | grep -vw akash-node); do helm -n akash-services get values $i > ${i}.pre-v0.8.2.values; done"
316+
backup_cmd = "cd /root/provider && for i in $(helm list -n akash-services -q | grep -vw akash-node); do helm -n akash-services get values $i > ${i}.old.values; done"
298317
run_ssh_command(ssh_client, backup_cmd, True, task_id=task_id)
299318

300319
# Upgrade hostname operator
301320
log.info("Upgrading hostname operator...")
302-
run_ssh_command(
303-
ssh_client,
304-
f"helm -n akash-services upgrade akash-hostname-operator akash/akash-hostname-operator --set image.tag={app_version}",
305-
True,
306-
task_id=task_id,
307-
)
321+
akash_hostname_operator_cmd = f"helm -n akash-services upgrade akash-hostname-operator akash/akash-hostname-operator --set image.tag={app_version}" if Config.CHAIN_ID == "akashnet-2" else f"helm -n akash-services upgrade akash-hostname-operator akash-dev/akash-hostname-operator --set image.tag={app_version} --devel"
322+
run_ssh_command(ssh_client, akash_hostname_operator_cmd, True, task_id=task_id)
308323

309324
# Upgrade inventory operator
310325
log.info("Upgrading inventory operator...")
311-
run_ssh_command(
312-
ssh_client,
313-
f"helm -n akash-services upgrade inventory-operator akash/akash-inventory-operator --set image.tag={app_version}",
314-
True,
315-
task_id=task_id,
316-
)
326+
akash_inventory_operator_cmd = f"helm -n akash-services upgrade inventory-operator akash/akash-inventory-operator --set image.tag={app_version}" if Config.CHAIN_ID == "akashnet-2" else f"helm -n akash-services upgrade inventory-operator akash-dev/akash-inventory-operator --set image.tag={app_version} --devel"
327+
run_ssh_command(ssh_client, akash_inventory_operator_cmd, True, task_id=task_id)
317328

318329
# Update price script
319330
log.info("Updating price script...")
@@ -327,10 +338,14 @@ async def upgrade_provider(self, ssh_client, task_id: str) -> Dict:
327338

328339
# Upgrade provider chart
329340
log.info("Upgrading provider chart...")
330-
provider_upgrade_cmd = (
331-
"helm upgrade akash-provider akash/provider -n akash-services -f ~/provider/provider.yaml "
332-
'--set bidpricescript="$(cat ~/provider/price_script_generic.sh | openssl base64 -A)"'
333-
)
341+
if Config.CHAIN_ID == "akashnet-2":
342+
provider_upgrade_cmd = (
343+
f"helm upgrade akash-provider akash/provider -n akash-services -f ~/provider/provider.yaml --set bidpricescript=\"$(cat ~/provider/price_script_generic.sh | openssl base64 -A)\" --set image.tag={app_version}"
344+
)
345+
else:
346+
provider_upgrade_cmd = (
347+
f"helm upgrade akash-provider akash-dev/provider -n akash-services -f ~/provider/provider.yaml --set bidpricescript=\"$(cat ~/provider/price_script_generic.sh | openssl base64 -A)\" --set image.tag={app_version} --devel"
348+
)
334349
run_ssh_command(ssh_client, provider_upgrade_cmd, True, task_id=task_id)
335350

336351
# Verify pod versions

application/service/wallet_service.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,15 @@ def _export_and_store_key(self, key_id: str) -> None:
188188
watchers=[passphrase_prompt, export_passphrase_prompt],
189189
hide=True,
190190
)
191+
192+
lines = exported_key.strip().splitlines()
193+
try:
194+
begin = next(i for i, l in enumerate(lines) if l.startswith("-----BEGIN "))
195+
end = next(i for i, l in reversed(list(enumerate(lines))) if l.startswith("-----END "))
196+
exported_key = "\n".join(lines[begin : end + 1]) + "\n"
197+
except StopIteration:
198+
# Fallback: preserve original content with a single trailing newline
199+
exported_key = exported_key.strip() + "\n"
191200

192201
if not exported_key:
193202
raise ApplicationError(
@@ -202,6 +211,7 @@ def _export_and_store_key(self, key_id: str) -> None:
202211
run_ssh_command(self.ssh_client, "rm -f ~/key.pem")
203212
store_command = f"cat > ~/key.pem << EOF\n{exported_key}\nEOF"
204213
run_ssh_command(self.ssh_client, store_command)
214+
run_ssh_command(self.ssh_client, "chmod 600 ~/key.pem")
205215
log.info("Key exported and stored successfully in ~/key.pem")
206216

207217
except Exception as e:

0 commit comments

Comments
 (0)