Skip to content

Commit 4545a8e

Browse files
Merge branch 'develop' into staging
2 parents 8abdf88 + 96facb4 commit 4545a8e

File tree

7 files changed

+53
-7
lines changed

7 files changed

+53
-7
lines changed

api/views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,8 +854,13 @@ def update_app_status(request):
854854

855855
# Required input
856856
release = request.data["release"]
857+
857858
new_status = request.data["new-status"]
858859

860+
if len(new_status) > 15:
861+
print(f"DEBUG: Status code is longer than 15 chars so shortening: {new_status}")
862+
new_status = new_status[:15]
863+
859864
event_ts = datetime.strptime(request.data["event-ts"], "%Y-%m-%dT%H:%M:%S.%fZ")
860865
event_ts = utc.localize(event_ts)
861866

apps/helpers.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ def create_app_instance(user, project, app, app_settings, data=[], wait=False):
192192
status.info = app_instance.parameters["release"]
193193
if "appconfig" in app_instance.parameters:
194194
if "path" in app_instance.parameters["appconfig"]:
195+
# remove trailing / in all cases
196+
if app_instance.parameters["appconfig"]["path"] != "/":
197+
app_instance.parameters["appconfig"]["path"] = app_instance.parameters["appconfig"]["path"].rstrip("/")
195198
if app_deps:
196199
if not created_by_admin:
197200
app_instance.parameters["appconfig"]["path"] = (
@@ -235,17 +238,21 @@ def handle_update_status_request(
235238
request should be performed or ignored.
236239
237240
:param release str: The release id of the app instance, stored in the AppInstance.parameters dict.
238-
:param new_status str: The new status code.
241+
:param new_status str: The new status code. Trimmed to max 15 chars if needed.
239242
:param event_ts timestamp: A JSON-formatted timestamp in UTC, e.g. 2024-01-25T16:02:50.00Z.
240243
:param event_msg json dict: An optional json dict containing pod-msg and/or container-msg.
241244
:returns: A value from the HandleUpdateStatusResponseCode enum.
242245
Raises an ObjectDoesNotExist exception if the app instance does not exist.
243246
"""
244247

248+
if len(new_status) > 15:
249+
new_status = new_status[:15]
250+
245251
try:
246252
# Begin by verifying that the requested app instance exists
247253
# We wrap the select and update tasks in a select_for_update lock
248254
# to avoid race conditions.
255+
249256
with transaction.atomic():
250257
app_instance = (
251258
AppInstance.objects.select_for_update().filter(parameters__contains={"release": release}).last()

apps/tests/test_update_status_handler.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,25 @@ def test_handle_missing_app_status_should_create_and_update_status(self):
139139
assert actual_appstatus.status_type == new_status
140140
assert actual_appstatus.time == newer_ts
141141

142+
def test_handle_long_status_text_should_trim_status(self):
143+
newer_ts = self.INITIAL_EVENT_TS + timedelta(seconds=1)
144+
new_status = "LongStatusText-ThisPartLongerThan15Chars"
145+
expected_status_text = new_status[:15]
146+
assert len(expected_status_text) == 15
147+
actual = handle_update_status_request(self.ACTUAL_RELEASE_NAME, new_status, newer_ts)
148+
149+
assert actual == HandleUpdateStatusResponseCode.CREATED_FIRST_STATUS
150+
151+
# Fetch the app instance and status objects and verify values
152+
actual_app_instance = AppInstance.objects.filter(
153+
parameters__contains={"release": self.ACTUAL_RELEASE_NAME}
154+
).last()
155+
156+
assert actual_app_instance.state == expected_status_text
157+
actual_appstatus = actual_app_instance.status.latest()
158+
assert actual_appstatus.status_type == expected_status_text
159+
assert actual_appstatus.time == newer_ts
160+
142161

143162
@pytest.mark.skip(
144163
reason="This test requires a modification to the handle_update_status_request function to add a delay parameter."

apps/views.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ def post(self, request, user, project):
7777
try:
7878
url = settings.LOKI_SVC + "/loki/api/v1/query_range"
7979
app_params = app.parameters
80-
if app.app.slug == "customapp":
81-
log_query = '{release="' + app_params["release"] + '",container="' + container + '"}'
80+
if app.app.slug == "shinyproxyapp":
81+
log_query = '{release="' + app_params["release"] + '",container="' + "serve" + '"}'
8282
else:
83-
log_query = '{release="' + app_params["release"] + '"}'
83+
log_query = '{release="' + app_params["release"] + '",container="' + container + '"}'
8484
print(log_query)
8585
query = {
8686
"query": log_query,
@@ -255,7 +255,6 @@ def post(self, request, user, project, ai_id):
255255

256256
app = appinstance.app
257257
app_settings = app.settings
258-
print("SETTINGSSS: ", appinstance.parameters["appconfig"])
259258
body = request.POST.copy()
260259

261260
if not app.user_can_edit:
@@ -307,6 +306,9 @@ def update_app_instance(self, request, project, appinstance, app_settings, body)
307306
appinstance.app_dependencies.set(app_deps)
308307
appinstance.model_dependencies.set(model_deps)
309308
if "appconfig" in appinstance.parameters and appinstance.app.slug == "customapp":
309+
# remove trailing / in all cases
310+
if appinstance.parameters["appconfig"]["path"] != "/":
311+
appinstance.parameters["appconfig"]["path"] = appinstance.parameters["appconfig"]["path"].rstrip("/")
310312
appinstance.parameters["created_by_admin"] = created_by_admin
311313
# if app is created by admin but admin user is not updating it dont change path.
312314
if created_by_admin:

charts/apps/custom-app/chart/templates/deployment.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ spec:
4848
command:
4949
- /bin/sh
5050
- -c
51-
- cp -r -n {{ $.Values.appconfig.path }}/* /tmp
51+
- |
52+
if [ -n "$(ls -A {{ $.Values.appconfig.path }})" ]; then
53+
echo "Copying data..." && cp -r -n {{ $.Values.appconfig.path }}/* /tmp && echo "Done Copying";
54+
elif [ -d "{{ $.Values.appconfig.path }}" ]; then
55+
echo "Empty directory. Nothing to copy.";
56+
else
57+
echo "Directory does not exist" && cp -r -n {{ $.Values.appconfig.path }}/* /tmp;
58+
fi
5259
volumeMounts:
5360
{{- range $key, $value := .Values.apps.volumeK8s }}
5461
- name: {{ $key }}

charts/apps/minio/chart/templates/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ spec:
8282
sleep 5
8383
mc alias set local http://127.0.0.1:9000 ${MINIO_ROOT_USER} ${MINIO_ROOT_PASSWORD}
8484
mc admin user add local {{ .Values.credentials.access_key }} {{ .Values.credentials.secret_key }}
85-
mc mb local/data-bucket
85+
mc mb local/data-bucket || true
8686
mc admin policy attach local readwrite --user {{ .Values.credentials.access_key }} || true
8787
hostname: {{ .Release.Name }}-minio
8888
restartPolicy: Always

projects/admin.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from django.conf import settings
12
from django.contrib import admin
23

34
from .models import (
@@ -27,6 +28,11 @@
2728
class ProjectAdmin(admin.ModelAdmin):
2829
list_display = ("name", "owner", "status", "updated_at")
2930
list_filter = ["owner", "status"]
31+
actions = ["update_app_limits"]
32+
33+
@admin.action(description="Reset app limits")
34+
def update_app_limits(self, request, queryset):
35+
queryset.update(apps_per_project=settings.APPS_PER_PROJECT_LIMIT)
3036

3137

3238
@admin.register(Flavor)

0 commit comments

Comments
 (0)