Skip to content

Commit d0b799c

Browse files
author
lijianguo
committed
chore(helmbroker): add helm config
1 parent 1d92ded commit d0b799c

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

rootfs/helmbroker/tasks.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
UpdateDetails, BindDetails
88

99
from .celery import app
10-
from .utils import command, get_plan_path, get_chart_path, get_cred_value, \
10+
from .utils import get_plan_path, get_chart_path, get_cred_value, \
1111
InstanceLock, dump_instance_meta, dump_binding_meta, load_instance_meta, \
12-
get_instance_file
12+
get_instance_file, helm
1313

1414

1515
@app.task(serializer='pickle')
@@ -25,7 +25,7 @@ def provision(instance_id: str, details: ProvisionDetails):
2525
"update",
2626
chart_path,
2727
]
28-
command("helm", *args)
28+
helm(instance_id, *args)
2929
values_file = os.path.join(get_plan_path(instance_id), "values.yaml")
3030
args = [
3131
"install",
@@ -43,7 +43,7 @@ def provision(instance_id: str, details: ProvisionDetails):
4343
f"fullnameOverride=helmbroker-{details.context['instance_name']}"
4444
]
4545

46-
status, output = command("helm", *args)
46+
status, output = helm(instance_id, *args)
4747
data = load_instance_meta(instance_id)
4848
if status != 0:
4949
data["last_operation"]["state"] = OperationState.FAILED.value
@@ -91,7 +91,7 @@ def update(instance_id: str, details: UpdateDetails):
9191
f"fullnameOverride=helmbroker-{details.context['instance_name']}"
9292
]
9393

94-
status, output = command("helm", *args)
94+
status, output = helm(instance_id, *args)
9595
if status != 0:
9696
data["last_operation"]["state"] = OperationState.FAILED.value
9797
data["last_operation"]["description"] = (
@@ -131,7 +131,7 @@ def bind(instance_id: str,
131131
"--set",
132132
f"fullnameOverride=helmbroker-{details.context['instance_name']}"
133133
]
134-
status, templates = command("helm", *args) # output: templates.yaml
134+
status, templates = helm(instance_id, *args) # output: templates.yaml
135135
if status != 0:
136136
data["last_operation"]["state"] = OperationState.FAILED.value
137137
data["last_operation"]["description"] = "binding %s failed: %s" % (instance_id, templates) # noqa
@@ -179,8 +179,8 @@ def deprovision(instance_id: str):
179179
data["last_operation"]["description"] = (
180180
"deprovision %s in progress at %s" % (instance_id, time.time()))
181181
dump_instance_meta(instance_id, data)
182-
status, output = command(
183-
"helm",
182+
status, output = helm(
183+
instance_id,
184184
"uninstall",
185185
data["details"]["context"]["instance_name"],
186186
"--namespace",

rootfs/helmbroker/utils.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
import time
77

88
from jsonschema import validate
9-
109
from .config import INSTANCES_PATH, ADDONS_PATH
1110

1211

12+
REGISTRY_CONFIG_SUFFIX = '.config/helm/registry.json'
13+
REPOSITORY_CACHE_SUFFIX = '.cache/helm/repository'
14+
REPOSITORY_CONFIG_SUFFIX = '.config/helm/repository'
15+
16+
1317
def command(cmd, *args, output_type="text"):
1418
status, output = subprocess.getstatusoutput("%s %s" % (cmd, " ".join(args))) # noqa
1519
if output_type == "yaml":
@@ -25,6 +29,21 @@ def command(cmd, *args, output_type="text"):
2529
get_plan_path = lambda instance_id: os.path.join(get_instance_path(instance_id), "plan") # noqa
2630

2731

32+
def helm(instance_id, *args, output_type="text"):
33+
instance_path = get_instance_path(instance_id)
34+
new_args = []
35+
new_args.extend(args)
36+
new_args.extend([
37+
"--registry-config",
38+
os.path.join(instance_path, REGISTRY_CONFIG_SUFFIX),
39+
"--repository-cache",
40+
os.path.join(instance_path, REPOSITORY_CACHE_SUFFIX),
41+
"--repository-config",
42+
os.path.join(instance_path, REPOSITORY_CONFIG_SUFFIX),
43+
])
44+
return command("helm", *args, output_type=output_type)
45+
46+
2847
INSTANCE_META_SCHEMA = {
2948
"type": "object",
3049
"properties": {

0 commit comments

Comments
 (0)