Skip to content

Commit d1fa7f4

Browse files
authored
Add max duration option for platforms (#467)
1 parent 86f435b commit d1fa7f4

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

api/azimuth/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ class SchedulingSettings(SettingsObject):
215215
#: Indicates whether advanced scheduling should be enabled
216216
ENABLED = Setting(default=False)
217217

218+
# Maximum duration of platform in hours, unlimited if unset
219+
MAX_PLATFORM_DURATION_HOURS = Setting(default=None)
220+
218221

219222
class AzimuthSettings(SettingsObject):
220223
"""

api/azimuth/views.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import contextlib
66
import dataclasses
7+
import datetime
78
import functools
89
import logging
910
import math
@@ -1243,6 +1244,17 @@ def clusters(request, tenant):
12431244
context={"session": session, "cluster_manager": cluster_manager},
12441245
)
12451246
input_serializer.is_valid(raise_exception=True)
1247+
1248+
if not _check_max_platform_duration(input_serializer.validated_data):
1249+
return response.Response(
1250+
{
1251+
"detail": "Platform exceeds max duration of "
1252+
+ str(cloud_settings.SCHEDULING.MAX_PLATFORM_DURATION_HOURS)
1253+
+ " hours."
1254+
},
1255+
status=status.HTTP_409_CONFLICT,
1256+
)
1257+
12461258
# Check that the cluster fits within quota
12471259
calculator = scheduling.CaaSClusterCalculator(session)
12481260
resources = calculator.calculate(
@@ -1483,6 +1495,21 @@ def kubernetes_cluster_template_details(request, tenant, template):
14831495
return response.Response(serializer.data)
14841496

14851497

1498+
def _check_max_platform_duration(platform_data):
1499+
if (
1500+
cloud_settings.SCHEDULING.MAX_PLATFORM_DURATION_HOURS is None
1501+
or not cloud_settings.SCHEDULING.ENABLED
1502+
):
1503+
return True
1504+
end_time = platform_data["schedule"].end_time
1505+
now = datetime.datetime.now(tz=datetime.timezone.utc)
1506+
duration = (end_time - now).total_seconds() / 3600
1507+
if duration < cloud_settings.SCHEDULING.MAX_PLATFORM_DURATION_HOURS:
1508+
return True
1509+
else:
1510+
return False
1511+
1512+
14861513
def kubernetes_cluster_check_quotas(session, cluster, template, **data):
14871514
"""
14881515
Check the quotas for a Kubernetes cluster.
@@ -1642,6 +1669,15 @@ def kubernetes_clusters(request, tenant):
16421669
context={"session": session, "capi_session": capi_session},
16431670
)
16441671
input_serializer.is_valid(raise_exception=True)
1672+
if not _check_max_platform_duration(input_serializer.validated_data):
1673+
return response.Response(
1674+
{
1675+
"detail": "Platform exceeds max duration of "
1676+
+ str(cloud_settings.SCHEDULING.MAX_PLATFORM_DURATION_HOURS)
1677+
+ " hours."
1678+
},
1679+
status=status.HTTP_409_CONFLICT,
1680+
)
16451681
# Check that the cluster fits within quota
16461682
resources, fits, _ = kubernetes_cluster_check_quotas(
16471683
session, None, **input_serializer.validated_data
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
AZIMUTH:
22
SCHEDULING:
33
ENABLED: {{ ternary "true" "false" .Values.scheduling.enabled }}
4+
{{- with .Values.scheduling.maxPlatformDurationHours }}
5+
MAX_PLATFORM_DURATION_HOURS: {{ . }}
6+
{{- end }}

chart/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ sshKeyStore:
410410
scheduling:
411411
# Indicates whether scheduling should be enabled
412412
enabled: false
413+
# Maximum duration of platform in hours (int), unlimited if unset
414+
maxPlatformDurationHours:
413415

414416
# Settings for the Kubernetes apps provider
415417
appsProvider:

0 commit comments

Comments
 (0)