Skip to content

Commit 69597b8

Browse files
authored
fix(resources): after resources instance update, could not delete (#111)
1 parent 4bfc8e6 commit 69597b8

6 files changed

Lines changed: 41 additions & 13 deletions

File tree

charts/controller/templates/_helpers.tpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ env:
3232
- name: "DRYCC_APP_POD_EXEC_TIMEOUT"
3333
value: "{{ .Values.appPodExecTimeout }}"
3434
{{- end }}
35-
3635
- name: "TZ"
37-
value: {{ .Values.time_zone | default "UTC" | quote }}
36+
value: {{ .Values.timezone | default "UTC" | quote }}
3837
- name: "DJANGO_SETTINGS_MODULE"
3938
value: "api.settings.production"
4039
{{- if (.Values.deployHookUrls) }}

charts/controller/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ appImagePullPolicy: "Always"
66
# A comma-separated list of URLs to send app release information to
77
# See https://www.drycc.cc/managing-workflow/deploy-hooks/
88
deployHookUrls: ""
9+
timezone: "UTC"
910
# limitsCpu: "100m"
1011
# limitsMemory: "50Mi"
1112
# Possible values are:

rootfs/api/models/resource.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ def attach(self, *args, **kwargs):
9292
@transaction.atomic
9393
def delete(self, *args, **kwargs):
9494
if self.binding == "Ready":
95-
raise DryccException("the plan is still binding")
95+
raise DryccException("the resource instance is still binding")
96+
if self.status == "Provisioning":
97+
raise DryccException("the resource instance is provisioning")
9698
# Deatch ServiceInstance, updates k8s
9799
self.detach(*args, **kwargs)
98100
# Delete from DB
@@ -119,9 +121,9 @@ def log(self, message, level=logging.INFO):
119121

120122
def bind(self, *args, **kwargs):
121123
if self.status != "Ready":
122-
raise DryccException("the resource is not ready")
124+
raise DryccException("the resource instance is not ready")
123125
if self.binding == "Ready":
124-
raise DryccException("the resource is binding")
126+
raise DryccException("the resource instance is binding")
125127
self.binding = "Binding"
126128
self.save()
127129
try:
@@ -141,7 +143,7 @@ def bind(self, *args, **kwargs):
141143

142144
def unbind(self, *args, **kwargs):
143145
if not self.binding:
144-
raise DryccException("the resource is not binding")
146+
raise DryccException("the resource instance is not binding")
145147
try:
146148
# We raise an exception when a resource doesn't exist
147149
self._scheduler.svcat.get_binding(self.app.id, self.name)
@@ -168,7 +170,7 @@ def attach_update(self, *args, **kwargs):
168170
"parameters": self.options,
169171
"external_id": data["spec"]["externalID"]
170172
}
171-
self._scheduler.svcat.put_instance(
173+
self._scheduler.svcat.patch_instance(
172174
self.app.id, self.name, version, **kwargs
173175
)
174176
except KubeException as e:

rootfs/api/serializers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,9 @@ class Meta:
615615

616616
def update(self, instance, validated_data):
617617
if instance.plan.split(':')[0] != validated_data.get('plan', '').split(':')[0]: # noqa
618-
raise DryccException("the resource cann't changed")
618+
raise DryccException("the resource instance cann't changed")
619+
if instance.state == "Provisioning":
620+
raise DryccException("this resource instance is in progress")
619621
instance.plan = validated_data.get('plan')
620622
instance.options.update(validated_data.get('options', {}))
621623
instance.attach_update()

rootfs/api/tests/test_resource.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from django.conf import settings
1010
from rest_framework.authtoken.models import Token
1111
from api.tests import adapter, DryccTransactionTestCase
12+
from api.exceptions import DryccException
1213
import requests_mock
1314

1415
User = get_user_model()
@@ -112,9 +113,11 @@ def test_resource_bind(self, mock_requests):
112113
# bind
113114
url = '/v2/apps/{app_id}/resources/mysql/binding/'.format(app_id=app_id)
114115
data = {"bind_action": "bind"}
115-
response = self.client.patch(url, data=data)
116-
# expected = response.data['path']
117-
self.assertEqual(response.status_code, 400)
116+
self.client.patch(url, data=data)
117+
self.assertRaises(
118+
DryccException,
119+
msg='the resource instance is not ready'
120+
)
118121

119122
def test_resource_unbind(self, mock_requests):
120123
# create
@@ -124,9 +127,12 @@ def test_resource_unbind(self, mock_requests):
124127
# unbind
125128
url = '/v2/apps/{app_id}/resources/mysql/binding/'.format(app_id=app_id)
126129
data = {"bind_action": "unbind"}
127-
response = self.client.patch(url, data=data)
130+
self.client.patch(url, data=data)
128131
# expected = response.data['path']
129-
self.assertEqual(response.status_code, 400)
132+
self.assertRaises(
133+
DryccException,
134+
msg='the resource instance is not binding'
135+
)
130136

131137
def call_command(self, *args, **kwargs):
132138
from io import StringIO

rootfs/scheduler/resources/svcat.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def service_instance_manifest(self, namespace, name, version=None, **kwargs):
1414
data = {
1515
"apiVersion": self.api_version,
1616
"kind": "ServiceInstance",
17+
"finalizers": [
18+
"kubernetes-incubator/service-catalog",
19+
],
1720
"metadata": {
1821
"name": name,
1922
"namespace": namespace,
@@ -98,6 +101,21 @@ def put_instance(self, namespace, name, version, **kwargs):
98101
"update serviceinstances {}".format(namespace))
99102
return response
100103

104+
def patch_instance(self, namespace, name, version, ignore_exception=False, **kwargs):
105+
"""
106+
Patch serviceinstances
107+
"""
108+
url = self.api('/namespaces/{}/serviceinstances/{}', namespace, name)
109+
data = self.service_instance_manifest(namespace, name, version, **kwargs)
110+
response = self.http_patch(
111+
url,
112+
json=data,
113+
headers={"Content-Type": "application/merge-patch+json"}
114+
)
115+
if not ignore_exception and self.unhealthy(response.status_code):
116+
raise KubeHTTPException(response, "patch serviceinstances {}".format(namespace))
117+
return response
118+
101119
def delete_instance(self, namespace, name):
102120
"""
103121
Delete serviceinstances

0 commit comments

Comments
 (0)