Skip to content

Commit de72ec5

Browse files
author
lijianguo
committed
chore(helmbroker): fixup binding
1 parent f03c66e commit de72ec5

3 files changed

Lines changed: 18 additions & 15 deletions

File tree

rootfs/helmbroker/broker.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,20 @@ def bind(self,
6666
async_allowed: bool,
6767
**kwargs
6868
) -> Binding:
69-
is_addon_bindable = get_addon_bindable(instance_id)
69+
is_addon_bindable = get_addon_bindable(details.service_id)
7070
if not is_addon_bindable:
7171
raise ErrBadRequest(msg="Instance %s does not bindable" % instance_id) # noqa
7272
instance_meta = load_instance_meta(instance_id)
7373
if not (instance_meta and
7474
instance_meta['last_operation']['state'] == 'succeeded'):
7575
raise ErrBadRequest(msg="This instance %s is not ready" % instance_id) # noqa
76-
if not async_allowed:
77-
raise ErrAsyncRequired()
76+
# if not async_allowed:
77+
# raise ErrAsyncRequired()
7878
instance_path = get_instance_path(instance_id)
7979
if os.path.exists(f'{instance_path}/bind.yaml'):
8080
raise ErrBindingAlreadyExists()
8181
chart_path, plan_path = get_chart_path(instance_id), get_plan_path(instance_id) # noqa
82-
# addon_name = get_addon_name(details.service_id)
83-
shutil.copy(f'{plan_path}/bind.yaml', f'{chart_path}/templates') # noqa
82+
shutil.copy(f'{plan_path}/bind.yaml', f'{chart_path}/templates')
8483
bind.delay(instance_id, binding_id, details, async_allowed, **kwargs)
8584
return Binding(state=BindState.IS_ASYNC)
8685

@@ -92,8 +91,8 @@ def unbind(self,
9291
**kwargs
9392
) -> UnbindSpec:
9493
instance_path = get_instance_path(instance_id)
95-
bind_yaml = f'{instance_path}/bind.yaml'
96-
shutil.rmtree(bind_yaml, ignore_errors=True)
94+
binding_info = f'{instance_path}/binding.json'
95+
shutil.rmtree(binding_info, ignore_errors=True)
9796
return UnbindSpec(is_async=False)
9897

9998
def update(self,

rootfs/helmbroker/tasks.py

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

99
from .celery import app
10-
from .config import INSTANCES_PATH
1110
from .utils import command, get_plan_path, get_chart_path, get_cred_value
1211
from .meta import dump_instance_meta, dump_binding_meta, load_instance_meta
1312

@@ -124,7 +123,9 @@ def bind(instance_id: str,
124123
details.context["instance_name"],
125124
chart_path,
126125
"-f",
127-
values_file
126+
values_file,
127+
"--set",
128+
f"fullnameOverride={details.context['instance_name']}"
128129
]
129130
status, templates = command("helm", *args) # output: templates.yaml
130131
if status != 0:
@@ -135,11 +136,12 @@ def bind(instance_id: str,
135136
success_flag = True
136137
errors = []
137138
for _ in credential_template['credential']:
138-
status, val = get_cred_value(details.context["namespace"], _['ValueFrom']) # noqa
139+
status, val = get_cred_value(details.context["namespace"], _['valueFrom']) # noqa
139140
if status != 0:
140141
success_flag = False
141142
errors.append(val)
142-
data[_['name']] = val
143+
else:
144+
data['credential'][_['name']] = val
143145
if success_flag:
144146
data['last_operation'] = {
145147
'state': OperationState.SUCCEEDED.value,
@@ -151,6 +153,8 @@ def bind(instance_id: str,
151153
'description': "binding %s failed: %s" % (instance_id, ','.join(errors)) # noqa
152154
}
153155
dump_binding_meta(instance_id, data)
156+
bind_yaml = f'{chart_path}/templates/bind.yaml'
157+
shutil.rmtree(bind_yaml, ignore_errors=True)
154158

155159

156160
@app.task()

rootfs/helmbroker/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,25 @@ def get_cred_value(ns, source):
6262
return get_config_map_key_value(ns, source['configMapRef'])
6363
if source.get('secretKeyRef'):
6464
return get_secret_key_value(ns, source['secretKeyRef'])
65-
return -1, 'invalid ValueFrom'
65+
return -1, 'invalid valueFrom'
6666

6767

6868
def get_service_key_value(ns, service_ref):
6969
args = [
70-
"get", "svc", service_ref['name'], "-n", ns, '-o', f'jsonpath="{service_ref["jsonpath"]}"', # noqa
70+
"get", "svc", service_ref['name'], "-n", ns, '-o', f"jsonpath=\'{service_ref['jsonpath']}\'", # noqa
7171
]
7272
return command("kubectl", *args)
7373

7474

7575
def get_config_map_key_value(ns, config_map_ref):
7676
args = [
77-
"get", "cm", config_map_ref['name'], "-n", ns, '-o', f'jsonpath="{config_map_ref["jsonpath"]}"', # noqa
77+
"get", "cm", config_map_ref['name'], "-n", ns, '-o', f"jsonpath=\'{config_map_ref['jsonpath']}\'", # noqa
7878
]
7979
return command("kubectl", *args)
8080

8181

8282
def get_secret_key_value(ns, secret_ref):
8383
args = [
84-
"get", "secret", secret_ref['name'], "-n", ns, '-o', f'jsonpath="{secret_ref["jsonpath"]}"', # noqa
84+
"get", "secret", secret_ref['name'], "-n", ns, '-o', f"jsonpath=\'{secret_ref['jsonpath']}\'", # noqa
8585
]
8686
return command("kubectl", *args)

0 commit comments

Comments
 (0)