Skip to content

Commit f757395

Browse files
committed
Merge branch 'main' of github.com:drycc/helmbroker into main
2 parents c5c4d34 + eac2fe6 commit f757395

3 files changed

Lines changed: 69 additions & 6 deletions

File tree

rootfs/helmbroker/broker.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
from .meta import load_instance_meta, load_binding_meta, dump_binding_meta
99
from .utils import get_instance_path, get_chart_path, get_plan_path, \
10-
get_addon_path, get_addon_name
11-
from .tasks import provision, bind, deprovision
10+
get_addon_path, get_addon_name, get_addon_updateable
11+
from .tasks import provision, bind, deprovision, update
1212
from helmbroker.loader import read_addons_file
1313

1414

@@ -88,8 +88,22 @@ def update(self,
8888
async_allowed: bool,
8989
**kwargs
9090
) -> UpdateServiceSpec:
91-
# Update service instnce
92-
return ProvisionedServiceSpec()
91+
instance_path = get_instance_path(instance_id)
92+
if not os.path.exists(instance_path):
93+
raise ErrBadRequest("Instance %s does not exist" % instance_id)
94+
is_plan_updateable = get_addon_updateable(instance_id)
95+
if not is_plan_updateable:
96+
raise ErrBadRequest("Instance %s does not updateable" % instance_id)
97+
if not async_allowed:
98+
raise ErrAsyncRequired()
99+
plan_path = get_plan_path(instance_id)
100+
# delete the pre plan
101+
shutil.rmtree(plan_path)
102+
_, addon_plan_path = get_addon_path(details.service_id, details.plan_id)
103+
# add the new plan
104+
shutil.copy(addon_plan_path, plan_path)
105+
update.delay(instance_id, details)
106+
return UpdateServiceSpec(is_async=True)
93107

94108
def deprovision(self,
95109
instance_id: str,
@@ -103,7 +117,7 @@ def deprovision(self,
103117
raise ErrAsyncRequired()
104118

105119
deprovision.delay(instance_id, details)
106-
return DeprovisionServiceSpec(state=ProvisionState.IS_ASYNC)
120+
return DeprovisionServiceSpec(is_async=True)
107121

108122
def last_operation(self,
109123
instance_id: str,

rootfs/helmbroker/tasks.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,45 @@ def provision(instance_id: str, details: ProvisionDetails):
4646
data["last_operation"]["description"] = "provision succeeded at %s" % time.time()
4747

4848

49+
def update(instance_id: str, details: UpdateDetails):
50+
data = {
51+
"id": instance_id,
52+
"details": {
53+
"service_id": details.service_id,
54+
"plan_id" : details.plan_id,
55+
"context" : details.context,
56+
"parameters": details.parameters,
57+
},
58+
"last_operation": {
59+
"state": OperationState.IN_PROGRESS,
60+
"description": "%s in progress at %s" % (instance_id, time.time())
61+
}
62+
}
63+
dump_instance_meta(instance_id, data)
64+
chart_path = get_chart_path(instance_id)
65+
values_file = os.path.join(get_plan_path(instance_id), "values.yaml")
66+
args = [
67+
"upgrade",
68+
details.context["instance_name"],
69+
chart_path,
70+
"--namespace",
71+
details.context["namespace"],
72+
"--create-namespace",
73+
"--wait",
74+
"--timeout 30m0s"
75+
"-f",
76+
values_file
77+
]
78+
79+
status, output = command("helm", *args)
80+
if status != 0:
81+
data["last_operation"]["state"] = OperationState.FAILED
82+
data["last_operation"]["description"] = output
83+
else:
84+
data["last_operation"]["state"] = OperationState.SUCCEEDED
85+
data["last_operation"]["description"] = "succeeded at %s" % time.time()
86+
87+
4988
def bind(instance_id: str,
5089
binding_id: str,
5190
details: BindDetails,

rootfs/helmbroker/utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,23 @@ def get_addon_path(service_id, plan_id):
3333
return service_path, plan_path
3434

3535

36-
def get_addon_name(service_id):
36+
def get_addon_meta(service_id):
3737
services = read_addons_file()
3838
service = [addon for addon in [addons for _, addons in services.items()]
3939
if addon['id'] == service_id][0]
40+
return service
41+
42+
43+
def get_addon_name(service_id):
44+
service = get_addon_meta(service_id)
4045
return service['name']
4146

4247

48+
def get_addon_updateable(service_id):
49+
service = get_addon_meta(service_id)
50+
return service.get('plan_updateable', False)
51+
52+
4353
def get_cred_value(ns, source):
4454
if source.get('serviceRef'):
4555
return get_service_key_value(ns, source['serviceRef'])

0 commit comments

Comments
 (0)