From 1e1db29ff51a57858c51438a23bf198261a52f5f Mon Sep 17 00:00:00 2001 From: John Kasper Svergja Date: Wed, 21 Aug 2024 20:25:21 +0200 Subject: [PATCH] Implement support for specifying container when getting logs If a pod have more than one container the current call will fail. This commit fix that issue, while perserving backward compability in the api by making the container id parameter optional. The get logs call will behave as before if container id is null or empty --- .../api/controller/api/mylab/MyLabController.java | 10 ++++++++-- .../java/fr/insee/onyxia/api/services/AppsService.java | 8 +++++++- .../onyxia/api/services/impl/HelmAppsService.java | 8 +++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/onyxia-api/src/main/java/fr/insee/onyxia/api/controller/api/mylab/MyLabController.java b/onyxia-api/src/main/java/fr/insee/onyxia/api/controller/api/mylab/MyLabController.java index 8451c222..75f0591f 100644 --- a/onyxia-api/src/main/java/fr/insee/onyxia/api/controller/api/mylab/MyLabController.java +++ b/onyxia-api/src/main/java/fr/insee/onyxia/api/controller/api/mylab/MyLabController.java @@ -298,10 +298,16 @@ public String getLogs( @Parameter(hidden = true) Region region, @Parameter(hidden = true) Project project, @RequestParam("serviceId") String serviceId, - @RequestParam("taskId") String taskId) { + @RequestParam("taskId") String taskId, + @RequestParam("containerId") Optional containerId) { if (Service.ServiceType.KUBERNETES.equals(region.getServices().getType())) { return helmAppsService.getLogs( - region, project, userProvider.getUser(region), serviceId, taskId); + region, + project, + userProvider.getUser(region), + serviceId, + taskId, + containerId.orElse(null)); } return null; } diff --git a/onyxia-api/src/main/java/fr/insee/onyxia/api/services/AppsService.java b/onyxia-api/src/main/java/fr/insee/onyxia/api/services/AppsService.java index 0ff23075..336cb46c 100644 --- a/onyxia-api/src/main/java/fr/insee/onyxia/api/services/AppsService.java +++ b/onyxia-api/src/main/java/fr/insee/onyxia/api/services/AppsService.java @@ -49,7 +49,13 @@ Service getUserService(Region region, Project project, User user, String service UninstallService destroyService( Region region, Project project, User user, String path, boolean bulk) throws Exception; - String getLogs(Region region, Project project, User user, String serviceId, String taskId); + String getLogs( + Region region, + Project project, + User user, + String serviceId, + String taskId, + String containerId); Watch getEvents(Region region, Project project, User user, Watcher watcher) throws HelmInstallService.MultipleServiceFound, ParseException; diff --git a/onyxia-api/src/main/java/fr/insee/onyxia/api/services/impl/HelmAppsService.java b/onyxia-api/src/main/java/fr/insee/onyxia/api/services/impl/HelmAppsService.java index 5be9b072..06f0fc5e 100644 --- a/onyxia-api/src/main/java/fr/insee/onyxia/api/services/impl/HelmAppsService.java +++ b/onyxia-api/src/main/java/fr/insee/onyxia/api/services/impl/HelmAppsService.java @@ -198,13 +198,19 @@ public CompletableFuture getUserServices( @Override public String getLogs( - Region region, Project project, User user, String serviceId, String taskId) { + Region region, + Project project, + User user, + String serviceId, + String taskId, + String containerId) { KubernetesClient client = kubernetesClientProvider.getUserClient(region, user); return client.pods() .inNamespace( kubernetesService.determineNamespaceAndCreateIfNeeded( region, project, user)) .withName(taskId) + .inContainer(containerId) .getLog(); }