Skip to content

Commit b621d34

Browse files
committed
chore(config): unify lifecycle interface
1 parent 3846c3a commit b621d34

7 files changed

Lines changed: 46 additions & 64 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 5.2.8 on 2025-12-05 13:39
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('api', '0026_app_suspended_state'),
10+
]
11+
12+
operations = [
13+
migrations.RenameField(
14+
model_name='config',
15+
old_name='lifecycle_post_start',
16+
new_name='lifecycle',
17+
),
18+
migrations.RemoveField(
19+
model_name='config',
20+
name='lifecycle_pre_stop',
21+
),
22+
]

rootfs/api/models/app.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,6 @@ def _gather_app_settings(self, release, app_settings, ptype, replicas, volumes=N
12271227
routable = True if (
12281228
ptype == PTYPE_WEB and app_settings.routable) else False
12291229

1230-
healthcheck = config.healthcheck.get(ptype, {})
12311230
volumes, volume_mounts = self._get_volumes_and_mounts(ptype, volumes)
12321231
volumes.extend(limit_plan.pod_volumes)
12331232
volume_mounts.extend(limit_plan.container_volume_mounts)
@@ -1241,11 +1240,10 @@ def _gather_app_settings(self, release, app_settings, ptype, replicas, volumes=N
12411240
'resources': {"limits": limit_plan.limits, "requests": limit_plan.requests},
12421241
'build_type': release.build.type,
12431242
'annotations': limit_plan.annotations,
1244-
'healthcheck': healthcheck,
1243+
'lifecycle': config.lifecycle.get(ptype, {}),
1244+
'healthcheck': config.healthcheck.get(ptype, {}),
12451245
'runtime_class_name': limit_plan.runtime_class_name,
12461246
'dns_policy': settings.DRYCC_APP_DNS_POLICY,
1247-
'lifecycle_post_start': config.lifecycle_post_start.get(ptype, {}),
1248-
'lifecycle_pre_stop': config.lifecycle_pre_stop.get(ptype, {}),
12491247
'routable': routable,
12501248
'deploy_batches': batches,
12511249
'restart_policy': "Always",

rootfs/api/models/config.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,18 @@ class Config(UuidAuditedModel):
1616
Set of configuration values applied as environment variables
1717
during runtime execution of the Application.
1818
"""
19-
ptype_fields = ("lifecycle_post_start", "lifecycle_pre_stop", "tags", "limits",
20-
"values_refs", "healthcheck", "termination_grace_period", "registry")
19+
ptype_fields = ("lifecycle", "tags", "limits", "values_refs", "healthcheck",
20+
"termination_grace_period", "registry")
2121
allof_fields = ("values", ) + ptype_fields
2222

2323
owner = models.ForeignKey(User, on_delete=models.PROTECT)
2424
app = models.ForeignKey('App', on_delete=models.CASCADE)
2525
values = models.JSONField(default=list, blank=True)
2626
values_refs = models.JSONField(default=dict, blank=True)
27-
lifecycle_post_start = models.JSONField(default=dict, blank=True)
28-
lifecycle_pre_stop = models.JSONField(default=dict, blank=True)
2927
tags = models.JSONField(default=dict, blank=True)
3028
limits = models.JSONField(default=dict, blank=True)
3129
registry = models.JSONField(default=dict, blank=True)
30+
lifecycle = models.JSONField(default=dict, blank=True)
3231
healthcheck = models.JSONField(default=dict, blank=True)
3332
termination_grace_period = models.JSONField(default=dict, blank=True)
3433

rootfs/api/serializers/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ class ConfigSerializer(serializers.ModelSerializer):
280280
owner = serializers.ReadOnlyField(source='owner.username')
281281
values = JSONFieldSerializer(required=False, binary=True)
282282
limits = JSONFieldSerializer(required=False, binary=True)
283-
lifecycle_post_start = JSONFieldSerializer(required=False, binary=True)
284-
lifecycle_pre_stop = JSONFieldSerializer(required=False, binary=True)
283+
lifecycle = JSONFieldSerializer(required=False, binary=True)
285284
tags = JSONFieldSerializer(required=False, binary=True)
286285
registry = JSONFieldSerializer(required=False, binary=True)
287286
healthcheck = JSONFieldSerializer(convert_to_str=False, required=False, binary=True)

rootfs/api/serializers/schemas/healthcheck.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
"type": "object",
55
"properties": {
6-
# Exec specifies the action to take.
7-
# More info: http://kubernetes.io/docs/api-reference/v1/definitions/#_v1_execaction
86
"exec": {
97
"type": "object",
108
"properties": {
@@ -16,8 +14,14 @@
1614
},
1715
"required": ["command"]
1816
},
19-
# HTTPGet specifies the http request to perform.
20-
# More info: http://kubernetes.io/docs/api-reference/v1/definitions/#_v1_httpgetaction
17+
"grpc": {
18+
"type": "object",
19+
"properties": {
20+
"port": {"type": "integer"},
21+
"service": {"type": "string"},
22+
},
23+
"required": ["port"]
24+
},
2125
"httpGet": {
2226
"type": "object",
2327
"properties": {
@@ -39,28 +43,23 @@
3943
},
4044
"required": ["port"]
4145
},
42-
# TCPSocket specifies an action involving a TCP port.
43-
# More info: http://kubernetes.io/docs/api-reference/v1/definitions/#_v1_tcpsocketaction
4446
"tcpSocket": {
4547
"type": "object",
4648
"properties": {
4749
"port": {"type": "integer"},
4850
},
4951
"required": ["port"]
5052
},
51-
# Number of seconds after the container has started before liveness probes are initiated.
52-
# More info: http://releases.k8s.io/HEAD/docs/user-guide/pod-states.md#container-probes
5353
"initialDelaySeconds": {"type": "integer"},
54-
# Number of seconds after which the probe times out.
55-
# More info: http://releases.k8s.io/HEAD/docs/user-guide/pod-states.md#container-probes
5654
"timeoutSeconds": {"type": "integer"},
57-
# How often (in seconds) to perform the probe.
5855
"periodSeconds": {"type": "integer"},
59-
# Minimum consecutive successes for the probe to be considered successful
60-
# after having failed.
6156
"successThreshold": {"type": "integer"},
62-
# Minimum consecutive failures for the probe to be considered
63-
# failed after having succeeded.
6457
"failureThreshold": {"type": "integer"},
65-
}
58+
},
59+
"oneOf": [
60+
{"required": ["exec"]},
61+
{"required": ["grpc"]},
62+
{"required": ["httpGet"]},
63+
{"required": ["tcpSocket"]},
64+
]
6665
}

rootfs/api/tests/test_config.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,7 @@ def test_response_data(self, mock_requests):
368368
for key in response.data:
369369
self.assertIn(key, ['uuid', 'owner', 'created', 'updated', 'app', 'values',
370370
'values_refs', 'limits', 'tags', 'registry', 'healthcheck',
371-
'lifecycle_post_start', 'lifecycle_pre_stop',
372-
'termination_grace_period'])
371+
'lifecycle', 'termination_grace_period'])
373372
expected = {
374373
'owner': self.user.username,
375374
'app': app_id,
@@ -400,8 +399,7 @@ def test_response_data_types_converted(self, mock_requests):
400399
for key in response.data:
401400
self.assertIn(key, ['uuid', 'owner', 'created', 'updated', 'app', 'values', 'limits',
402401
'values_refs', 'tags', 'registry', 'healthcheck',
403-
'lifecycle_post_start', 'lifecycle_pre_stop',
404-
'termination_grace_period'])
402+
'lifecycle', 'termination_grace_period'])
405403
expected = {
406404
'owner': self.user.username,
407405
'app': app_id,

rootfs/scheduler/resources/pod.py

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from collections import defaultdict
21
from datetime import datetime, timedelta, timezone
32
import operator
43
import os
@@ -236,8 +235,8 @@ def _set_container(self, namespace, container_name, data, **kwargs):
236235
self._set_container_default_env(data)
237236
# list sorted by dict key name
238237
data['env'].sort(key=operator.itemgetter('name'))
238+
data['lifecycle'] = data.get('lifecycle', {})
239239
self._set_health_checks(data, env, **kwargs)
240-
self._set_lifecycle_hooks(data, env, **kwargs)
241240

242241
def _set_container_default_env(self, data):
243242
# set fields env
@@ -286,38 +285,6 @@ def _set_health_checks(self, container, env, **kwargs):
286285
container.update(
287286
self._default_container_readiness_probe(env.get('PORT', DEFAULT_CONTAINER_PORT)))
288287

289-
@staticmethod
290-
def _set_lifecycle_hooks(container, env, **kwargs):
291-
app_type = kwargs.get("app_type")
292-
lifecycle_post_start = kwargs.get('lifecycle_post_start', {})
293-
lifecycle_post_start = lifecycle_post_start.get(app_type)
294-
lifecycle_pre_stop = kwargs.get('lifecycle_pre_stop', {})
295-
lifecycle_pre_stop = lifecycle_pre_stop.get(app_type)
296-
if lifecycle_post_start or lifecycle_pre_stop:
297-
lifecycle = defaultdict(dict)
298-
299-
if lifecycle_post_start:
300-
lifecycle["postStart"] = {
301-
'exec': {
302-
"command": [
303-
"/bin/bash",
304-
"-c",
305-
"{0}".format(lifecycle_post_start)
306-
]
307-
}
308-
}
309-
if lifecycle_pre_stop:
310-
lifecycle["preStop"] = {
311-
'exec': {
312-
"command": [
313-
"/bin/bash",
314-
"-c",
315-
"{0}".format(lifecycle_pre_stop)
316-
]
317-
}
318-
}
319-
container["lifecycle"] = dict(lifecycle)
320-
321288
@staticmethod
322289
def _default_container_readiness_probe(port, delay=5, timeout=5, period_seconds=5,
323290
success_threshold=1, failure_threshold=1):

0 commit comments

Comments
 (0)