Skip to content

Commit

Permalink
Implement support for specifying container when getting logs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
johnksv committed Aug 26, 2024
1 parent 5e48651 commit 1e1db29
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event> watcher)
throws HelmInstallService.MultipleServiceFound, ParseException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,19 @@ public CompletableFuture<ServicesListing> 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();
}

Expand Down

0 comments on commit 1e1db29

Please sign in to comment.