Skip to content

Commit 848084b

Browse files
committed
chore(controller): review pvc code
1 parent 5d7b851 commit 848084b

8 files changed

Lines changed: 26 additions & 23 deletions

File tree

charts/controller/templates/controller-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ spec:
7777
- name: "IMAGE_PULL_POLICY"
7878
value: "{{ .Values.app_pull_policy }}"
7979
{{- if (.Values.app_storage_class) }}
80-
- name: "DRYCC_APP_KUBERNETES_STORAGE_CLASS"
80+
- name: "DRYCC_APP_STORAGE_CLASS"
8181
value: "{{ .Values.app_storage_class }}"
8282
{{- end }}
8383
- name: "TZ"

charts/controller/values.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ app_storage_class: ""
2424
# this is usually a non required setting.
2525
environment:
2626
RESERVED_NAMES: "drycc, drycc-builder, drycc-monitor-grafana"
27-
KUBERNETES_POD_DEFAULT_RESOURCES: "{}"
28-
KUBERNETES_NAMESPACE_DEFAULT_QUOTA_SPEC: "{}"
2927

3028
nsqd:
3129
replicas: 1

rootfs/api/models/volume.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __str__(self):
2929
def save(self, *args, **kwargs):
3030
# Attach volume, updates k8s
3131
if self.created == self.updated:
32-
self.attach(*args, **kwargs)
32+
self.attach()
3333
# Save to DB
3434
return super(Volume, self).save(*args, **kwargs)
3535

@@ -38,11 +38,11 @@ def delete(self, *args, **kwargs):
3838
if self.path:
3939
raise DryccException("the volume is not unmounted")
4040
# Deatch volume, updates k8s
41-
self.detach(*args, **kwargs)
41+
self.detach()
4242
# Delete from DB
4343
return super(Volume, self).delete(*args, **kwargs)
4444

45-
def attach(self, *args, **kwargs):
45+
def attach(self):
4646
try:
4747
self._scheduler.pvc.get(self.app.id, self.name)
4848
err = "Volume {} already exists in this namespace".format(self.name) # noqa
@@ -52,15 +52,16 @@ def attach(self, *args, **kwargs):
5252
logger.info(e)
5353
try:
5454
kwargs = {
55-
"size": self.size
55+
"size": self.size,
56+
"storage_class": settings.DRYCC_APP_STORAGE_CLASS,
5657
}
5758
self._scheduler.pvc.create(self.app.id, self.name, **kwargs)
5859
except KubeException as e:
5960
msg = 'There was a problem creating the volume ' \
6061
'{} for {}'.format(self.name, self.app_id)
6162
raise ServiceUnavailable(msg) from e
6263

63-
def detach(self, *args, **kwargs):
64+
def detach(self):
6465
try:
6566
# We raise an exception when a volume doesn't exist
6667
self._scheduler.pvc.get(self.app.id, self.name)

rootfs/api/settings/production.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@
326326

327327
DRYCC_DEPLOY_HOOK_SECRET_KEY = os.environ.get('DRYCC_DEPLOY_HOOK_SECRET_KEY', None)
328328

329-
DRYCC_APP_KUBERNETES_STORAGE_CLASS = os.environ.get('DRYCC_APP_KUBERNETES_STORAGE_CLASS', "") # noqa
329+
DRYCC_APP_STORAGE_CLASS = os.environ.get('DRYCC_APP_STORAGE_CLASS', "")
330330

331331
KUBERNETES_DEPLOYMENTS_REVISION_HISTORY_LIMIT = os.environ.get('KUBERNETES_DEPLOYMENTS_REVISION_HISTORY_LIMIT', None) # noqa
332332

@@ -340,12 +340,14 @@
340340
'KUBERNETES_POD_DEFAULT_RESOURCES',
341341
json.dumps({
342342
"requests": {
343-
"cpu": "256m",
344-
"memory": "256Mi"
343+
"cpu": "200m",
344+
"memory": "256Mi",
345+
"ephemeral-storage": "1Gi"
345346
},
346347
"limits": {
347-
"cpu": "512m",
348-
"memory": "512Mi"
348+
"cpu": "500m",
349+
"memory": "512Mi",
350+
"ephemeral-storage": "2Gi"
349351
},
350352
})
351353
)
@@ -355,11 +357,11 @@
355357
'KUBERNETES_NAMESPACE_DEFAULT_QUOTA_SPEC',
356358
json.dumps({
357359
"hard": {
358-
"cpu": "8",
359-
"pods": "16",
360-
"memory": "32Gi",
361-
"ephemeral-storage": "1Gi",
362-
"requests.storage": "10Gi",
360+
"cpu": "64",
361+
"pods": "64",
362+
"memory": "128Gi",
363+
"ephemeral-storage": "64Gi",
364+
"requests.storage": "256Gi",
363365
"persistentvolumeclaims": 8,
364366
}
365367
})

rootfs/api/settings/testing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
DRYCC_DEFAULT_CONFIG_TAGS = os.environ.get('DRYCC_DEFAULT_CONFIG_TAGS', '')
4444

45-
DRYCC_APP_KUBERNETES_STORAGE_CLASS = os.environ.get('DRYCC_APP_KUBERNETES_STORAGE_CLASS', '') # noqa
45+
DRYCC_APP_STORAGE_CLASS = os.environ.get('DRYCC_APP_STORAGE_CLASS', '')
4646

4747

4848
class DisableMigrations(object):

rootfs/api/tests/test_volume.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ def test_volumecreate(self, mock_requests):
3636

3737
response = self.client.post(
3838
'/v2/apps/{}/volumes'.format(app_id),
39-
data={'name': 'myvolume', 'size': '500M'}
39+
data={
40+
'name': 'myvolume', 'size': '500M'
41+
}
4042
)
4143
self.assertEqual(response.status_code, 201, response.data)
4244

rootfs/scheduler/resources/pvc.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from api.settings.production import DRYCC_APP_KUBERNETES_STORAGE_CLASS
21
from scheduler.resources import Resource
32
from scheduler.exceptions import KubeHTTPException
43

@@ -28,7 +27,7 @@ def manifest(namespace, name, version=None, **kwargs):
2827
"storage": kwargs.get('size')
2928
},
3029
},
31-
"storageClassName": DRYCC_APP_KUBERNETES_STORAGE_CLASS,
30+
"storageClassName": kwargs.get("storage_class"),
3231
"volumeMode": "Filesystem",
3332
}
3433
}

rootfs/scheduler/tests/test_pvc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def create(self, namespace=None, name=generate_random_name(), **kwargs):
1818
namespace = self.namespace if namespace is None else namespace
1919
# these are all required even if it is kwargs...
2020
kwargs = {
21-
'size': '500M'
21+
'size': '500M',
22+
'storage_class': 'default'
2223
}
2324
pvc = self.scheduler.pvc.create(namespace, name, **kwargs)
2425
self.assertEqual(pvc.status_code, 201, pvc.json())

0 commit comments

Comments
 (0)