Skip to content

Commit

Permalink
Bugfix/admin action reset applimits (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzaimran08 authored Feb 7, 2024
1 parent 839a56e commit 96facb4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
3 changes: 3 additions & 0 deletions apps/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ def create_app_instance(user, project, app, app_settings, data=[], wait=False):
status.info = app_instance.parameters["release"]
if "appconfig" in app_instance.parameters:
if "path" in app_instance.parameters["appconfig"]:
# remove trailing / in all cases
if app_instance.parameters["appconfig"]["path"] != "/":
app_instance.parameters["appconfig"]["path"] = app_instance.parameters["appconfig"]["path"].rstrip("/")
if app_deps:
if not created_by_admin:
app_instance.parameters["appconfig"]["path"] = (
Expand Down
10 changes: 6 additions & 4 deletions apps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ def post(self, request, user, project):
try:
url = settings.LOKI_SVC + "/loki/api/v1/query_range"
app_params = app.parameters
if app.app.slug == "customapp":
log_query = '{release="' + app_params["release"] + '",container="' + container + '"}'
if app.app.slug == "shinyproxyapp":
log_query = '{release="' + app_params["release"] + '",container="' + "serve" + '"}'
else:
log_query = '{release="' + app_params["release"] + '"}'
log_query = '{release="' + app_params["release"] + '",container="' + container + '"}'
print(log_query)
query = {
"query": log_query,
Expand Down Expand Up @@ -255,7 +255,6 @@ def post(self, request, user, project, ai_id):

app = appinstance.app
app_settings = app.settings
print("SETTINGSSS: ", appinstance.parameters["appconfig"])
body = request.POST.copy()

if not app.user_can_edit:
Expand Down Expand Up @@ -307,6 +306,9 @@ def update_app_instance(self, request, project, appinstance, app_settings, body)
appinstance.app_dependencies.set(app_deps)
appinstance.model_dependencies.set(model_deps)
if "appconfig" in appinstance.parameters and appinstance.app.slug == "customapp":
# remove trailing / in all cases
if appinstance.parameters["appconfig"]["path"] != "/":
appinstance.parameters["appconfig"]["path"] = appinstance.parameters["appconfig"]["path"].rstrip("/")
appinstance.parameters["created_by_admin"] = created_by_admin
# if app is created by admin but admin user is not updating it dont change path.
if created_by_admin:
Expand Down
9 changes: 8 additions & 1 deletion charts/apps/custom-app/chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ spec:
command:
- /bin/sh
- -c
- cp -r -n {{ $.Values.appconfig.path }}/* /tmp
- |
if [ -n "$(ls -A {{ $.Values.appconfig.path }})" ]; then
echo "Copying data..." && cp -r -n {{ $.Values.appconfig.path }}/* /tmp && echo "Done Copying";
elif [ -d "{{ $.Values.appconfig.path }}" ]; then
echo "Empty directory. Nothing to copy.";
else
echo "Directory does not exist" && cp -r -n {{ $.Values.appconfig.path }}/* /tmp;
fi
volumeMounts:
{{- range $key, $value := .Values.apps.volumeK8s }}
- name: {{ $key }}
Expand Down
6 changes: 6 additions & 0 deletions projects/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.conf import settings
from django.contrib import admin

from .models import (
Expand Down Expand Up @@ -27,6 +28,11 @@
class ProjectAdmin(admin.ModelAdmin):
list_display = ("name", "owner", "status", "updated_at")
list_filter = ["owner", "status"]
actions = ["update_app_limits"]

@admin.action(description="Reset app limits")
def update_app_limits(self, request, queryset):
queryset.update(apps_per_project=settings.APPS_PER_PROJECT_LIMIT)


@admin.register(Flavor)
Expand Down

0 comments on commit 96facb4

Please sign in to comment.