Skip to content

Commit ce32842

Browse files
committed
feat(limits): add runtime class name to plans
1 parent 7cb6bfa commit ce32842

11 files changed

Lines changed: 188 additions & 117 deletions

File tree

charts/controller/templates/_helpers.tpl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ env:
2626
- name: "DRYCC_APP_STORAGE_CLASS"
2727
value: "{{ (tpl .Values.appStorageClass .) }}"
2828
{{- end }}
29-
{{- if (.Values.appRuntimeClass) }}
30-
- name: "DRYCC_APP_RUNTIME_CLASS"
31-
value: "{{ .Values.appRuntimeClass }}"
32-
{{- end }}
3329
{{- if (.Values.appDNSPolicy) }}
3430
- name: "DRYCC_APP_DNS_POLICY"
3531
value: "{{ .Values.appDNSPolicy }}"
@@ -260,6 +256,7 @@ resources:
260256
kubernetes.io/egress-bandwidth: 100M
261257
kubernetes.io/ingress-bandwidth: 100M
262258
node_selector: {}
259+
runtime_class_name: ""
263260
pod_security_context: {}
264261
container_security_context: {}
265262
created: {{ now | date "2006-01-02T15:04:05.000Z" }}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.2.17 on 2024-12-25 08:53
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('api', '0020_remove_config_typed_values_alter_config_values'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='limitplan',
15+
name='runtime_class_name',
16+
field=models.CharField(default='', max_length=63),
17+
),
18+
]

rootfs/api/models/app.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ def pipeline(self, release, ptypes, force_deploy=False):
289289
self.log(f"{prefix} starts running pipeline.run {run['image']}")
290290
job_name = self.run(
291291
self.owner, run['image'], command=run['command'],
292-
args=run['args'], timeout=run['timeout'], expires=run['timeout']
292+
args=run['args'], timeout=run['timeout'], expires=run['timeout'],
293+
envs=self._build_env_vars(release, run['ptype']),
293294
)
294295
state, labels = 'initializing', {'job-name': job_name}
295296
for count, state in enumerate(self.scheduler().pod.watch(
@@ -1240,7 +1241,7 @@ def _gather_app_settings(self, release, app_settings, ptype, replicas, volumes=N
12401241
'build_type': release.build.type,
12411242
'annotations': limit_plan.annotations,
12421243
'healthcheck': healthcheck,
1243-
'runtime_class_name': settings.DRYCC_APP_RUNTIME_CLASS,
1244+
'runtime_class_name': limit_plan.runtime_class_name,
12441245
'dns_policy': settings.DRYCC_APP_DNS_POLICY,
12451246
'lifecycle_post_start': config.lifecycle_post_start,
12461247
'lifecycle_pre_stop': config.lifecycle_pre_stop,

rootfs/api/models/build.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,10 @@ def _get_or_create_config(self):
110110
"""
111111
dryccfile to config
112112
"""
113-
config_values, config_values_ref, config_healthcheck, changed_fields = [], {}, {}, set()
113+
config_values, config_values_ref, config_healthcheck, changed_fields = (
114+
self.dryccfile.get('config', []), {}, {}, set())
114115
if 'config' in self.dryccfile:
115-
for group, values in self.dryccfile.get('config', {}).items():
116-
for value in values:
117-
value['group'] = group
118-
config_values.append(value)
119116
changed_fields.update(["values", "values_refs"])
120-
121117
replace_values_ptypes, replace_healthcheck_ptypes = set(), set()
122118
for ptype, values in self.dryccfile.get('deploy', {}).items():
123119
if 'config' in values:
@@ -132,7 +128,6 @@ def _get_or_create_config(self):
132128
config_values_ref[ptype].append(config_ref)
133129
replace_values_ptypes.add(ptype)
134130
changed_fields.update(["values", "values_refs"])
135-
136131
if 'healthcheck' in values:
137132
config_healthcheck[ptype] = values.get('healthcheck')
138133
changed_fields.add("healthcheck")

rootfs/api/models/limit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class LimitPlan(AuditedModel):
115115
requests = models.JSONField(default=dict)
116116
annotations = models.JSONField(default=dict)
117117
node_selector = models.JSONField(default=dict)
118+
runtime_class_name = models.CharField(max_length=63, default="")
118119
pod_security_context = models.JSONField(default=dict)
119120
container_security_context = models.JSONField(default=dict)
120121

rootfs/api/models/release.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,16 @@ def version_name(self):
6767
def get_runners(self, ptypes):
6868
results = []
6969
ptypes = self.ptypes if not ptypes else ptypes
70-
for run in self.build.dryccfile.get('run', []):
71-
for ptype in ptypes:
72-
when_ptypes = run.get('when', {}).get('ptypes', [])
73-
if not when_ptypes or ptype in when_ptypes:
74-
image = run.get('image', self.build.get_image(ptype))
75-
results.append({
76-
'image': self.build.get_image(image, default_image=image),
77-
'args': run.get('args', []),
78-
'command': run.get('command', []),
79-
'timeout': run.get('timeout', settings.DRYCC_PILELINE_RUN_TIMEOUT),
80-
})
81-
break
70+
for ptype, run in self.build.dryccfile.get('run', {}).items():
71+
if ptype in ptypes:
72+
image = run.get('image', self.build.get_image(ptype))
73+
results.append({
74+
'ptype': ptype,
75+
'image': self.build.get_image(image, default_image=image),
76+
'args': run.get('args', []),
77+
'command': run.get('command', []),
78+
'timeout': run.get('timeout', settings.DRYCC_PILELINE_RUN_TIMEOUT),
79+
})
8280
return results
8381

8482
def add_condition(self, **kwargs):

rootfs/api/serializers/schemas/dryccfile.py

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
PROCTYPE_REGEX = r'^(?P<type>[a-z0-9]+(\-[a-z0-9]+)*)$'
2-
32
SCHEMA = {
43
"$schema": "http://json-schema.org/schema#",
54
"type": "object",
@@ -14,25 +13,71 @@
1413
},
1514
"additionalProperties": False,
1615
},
17-
"config": {"type": "object"}
16+
"config": {
17+
"oneOf": [
18+
{
19+
"type": "object",
20+
"patternProperties": {
21+
PROCTYPE_REGEX: {
22+
"type": "array",
23+
"items": {
24+
"type": "object",
25+
"properties": {
26+
"name": {"type": "string"},
27+
"value": {"type": "string"},
28+
},
29+
"additionalProperties": False,
30+
},
31+
},
32+
},
33+
"minProperties": 1,
34+
"additionalProperties": False,
35+
},
36+
{
37+
"type": "array",
38+
"items": {
39+
"type": "object",
40+
"properties": {
41+
"name": {"type": "string"},
42+
"value": {"type": "string"},
43+
},
44+
"additionalProperties": False,
45+
},
46+
},
47+
]
48+
}
1849
},
1950
},
20-
"run": {
51+
"config": {
2152
"type": "array",
2253
"items": {
2354
"type": "object",
2455
"properties": {
25-
"image": {"type": "string"},
26-
"command": {
27-
"type": "array",
28-
"items": {"type": "string"},
29-
},
30-
"args": {
31-
"type": "array",
32-
"items": {"type": "string"},
56+
"name": {"type": "string"},
57+
"group": {"type": "string"},
58+
"value": {"type": "string"},
59+
},
60+
"additionalProperties": False,
61+
},
62+
},
63+
"run": {
64+
"type": "object",
65+
"patternProperties": {
66+
PROCTYPE_REGEX: {
67+
"properties": {
68+
"image": {"type": "string"},
69+
"command": {
70+
"type": "array",
71+
"items": {"type": "string"},
72+
},
73+
"args": {
74+
"type": "array",
75+
"items": {"type": "string"},
76+
}
3377
}
3478
},
3579
},
80+
"additionalProperties": False,
3681
},
3782
"deploy": {
3883
"type": "object",
@@ -48,6 +93,23 @@
4893
"type": "array",
4994
"items": {"type": "string"},
5095
},
96+
"config": {
97+
"env": {
98+
"type": "array",
99+
"items": {
100+
"type": "object",
101+
"properties": {
102+
"name": {"type": "string"},
103+
"value": {"type": "string"},
104+
},
105+
"additionalProperties": False,
106+
},
107+
},
108+
"ref": {
109+
"type": "array",
110+
"items": {"type": "string"},
111+
}
112+
},
51113
}
52114
},
53115
},

rootfs/api/settings/production.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,6 @@
332332

333333
DRYCC_APP_STORAGE_CLASS = os.environ.get('DRYCC_APP_STORAGE_CLASS', "")
334334

335-
DRYCC_APP_RUNTIME_CLASS = os.environ.get('DRYCC_APP_RUNTIME_CLASS', "")
336-
337335
DRYCC_APP_DNS_POLICY = os.environ.get('DRYCC_APP_DNS_POLICY', "")
338336

339337
DRYCC_APP_POD_EXEC_TIMEOUT = int(os.environ.get('DRYCC_APP_POD_EXEC_TIMEOUT', "3600"))

rootfs/api/tests/test_build.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -750,14 +750,15 @@ def test_dryccfile_ok(self, mock_requests):
750750
'dryccfile': {
751751
"build": {
752752
"docker": {"web": "Dockerfile", "worker": "worker/Dockerfile"},
753-
"config": {"RAILS_ENV": "development", "FOO": "bar"}
753+
"config": [
754+
{"name": "FOO", "value": "bar"},
755+
{"name": "RAILS_ENV", "value": "development"},
756+
],
757+
},
758+
"run": {
759+
"web": {"command": ["./deployment-tasks.sh"], "image": run_image},
760+
"worker": {"command": ["./deployment-tasks.sh"], "image": run_image},
754761
},
755-
"run": [
756-
{
757-
"command": ["./deployment-tasks.sh"],
758-
"image": run_image,
759-
}
760-
],
761762
"deploy": {
762763
"web": {
763764
"command": ["bash", "-c"],
@@ -803,7 +804,10 @@ def test_dryccfile_format(self, mock_requests):
803804
'dryccfile': {
804805
"build": {
805806
"docker": {"web": "Dockerfile", "worker": "worker/Dockerfile"},
806-
"config": {"RAILS_ENV": "development", "FOO": "bar"}
807+
"config": [
808+
{"name": "FOO", "value": "bar"},
809+
{"name": "RAILS_ENV", "value": "development"},
810+
],
807811
},
808812
}
809813
}
@@ -829,12 +833,10 @@ def test_dryccfile_format(self, mock_requests):
829833
response = self.client.post(url, body)
830834
self.assertEqual(response.status_code, 201, response.data)
831835

832-
body['dryccfile']['run'] = [
833-
{
834-
'command': ["bash", "-c"],
835-
'args': ["ls /"]
836-
}
837-
]
836+
body['dryccfile']['run'] = {
837+
"web": {'command': ["bash", "-c"], 'args': ["ls /"]},
838+
"web-new": {'command': ["bash", "-c"], 'args': ["ls /"]},
839+
}
838840
response = self.client.post(url, body)
839841
self.assertEqual(response.status_code, 201, response.data)
840842
body['dryccfile']['deploy'] = {}

rootfs/api/tests/test_config.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,10 @@ def test_config_from_dryccfile(self, mock_requests):
825825
'dryccfile': {
826826
"build": {
827827
"docker": {"web": "Dockerfile", "worker": "worker/Dockerfile"},
828-
"config": {"RAILS_ENV": "development", "FOO": "bar"}
828+
"config": [
829+
{"name": "FOO", "value": "bar"},
830+
{"name": "RAILS_ENV", "value": "development"},
831+
],
829832
},
830833
'deploy': {
831834
'web': {
@@ -848,16 +851,12 @@ def test_config_from_dryccfile(self, mock_requests):
848851
self.assertEqual(release.failed, False)
849852
self.assertEqual(release.config.envs("web"), {"WEBSITE": "www.drycc.cc"})
850853
# set env by dryccfile
851-
build_body['dryccfile']['config'] = {
852-
"mygroup1": [
853-
{"name": "GROUP", "value": "g1"},
854-
{"name": "DEBUG", "value": "tr"},
855-
],
856-
"mygroup2": [
857-
{"name": "TEST1", "value": "g1"},
858-
{"name": "TEST2", "value": "tr"},
859-
],
860-
}
854+
build_body['dryccfile']['config'] = [
855+
{"name": "GROUP", "group": "mygroup1", "value": "g1"},
856+
{"name": "DEBUG", "group": "mygroup1", "value": "tr"},
857+
{"name": "TEST1", "group": "mygroup2", "value": "g1"},
858+
{"name": "TEST2", "group": "mygroup2", "value": "tr"},
859+
]
861860
build_body['dryccfile']['deploy']['web']['config'] = {
862861
'env': [
863862
{'name': "PENV1", 'value': 'web'},
@@ -919,7 +918,7 @@ def test_config_from_dryccfile(self, mock_requests):
919918
self.assertEqual(release.config.values_refs, release.previous().config.values_refs)
920919
# set empty
921920
new_build_body = copy.deepcopy(build_body)
922-
new_build_body['dryccfile']['config'] = {}
921+
new_build_body['dryccfile']['config'] = []
923922
new_build_body['dryccfile']['deploy']['web']['config'] = {}
924923
new_build_body['dryccfile']['deploy']['web']['healthcheck'] = {}
925924
with mock.patch('scheduler.resources.pod.Pod.watch') as mock_kube:

0 commit comments

Comments
 (0)