@@ -147,7 +147,7 @@ public void doContainerLog(@QueryParameter String containerId, StaplerRequest2 r
147147 if (slave != null ) {
148148 KubernetesCloud cloud = slave .getKubernetesCloud ();
149149 String namespace = StringUtils .defaultIfBlank (slave .getNamespace (), cloud .getNamespace ());
150- PodResource resource = cloud .getPodResource (namespace , containerId );
150+ PodResource resource = cloud .getPodResource (namespace , slave . getPodName () );
151151
152152 // check if pod exists
153153 Pod pod = resource .get ();
@@ -158,29 +158,22 @@ public void doContainerLog(@QueryParameter String containerId, StaplerRequest2 r
158158 return ;
159159 }
160160
161- // Check if container exists and is running (maybe terminated if ephemeral )
161+ // Check if container exists (ephemeral containers are not included )
162162 Optional <ContainerStatus > status = PodContainerSource .lookupContainerStatus (pod , containerId );
163- if (status .isPresent ()) {
164- ContainerStatus cs = status .get ();
165- if (cs .getState ().getTerminated () != null ) {
166- outputStream .write ("Container terminated" .getBytes (StandardCharsets .UTF_8 ));
167- text .markAsComplete ();
168- text .doProgressText (req , rsp );
169- return ;
170- }
171- } else {
163+ if (!status .isPresent ()) {
172164 outputStream .write ("Container not found" .getBytes (StandardCharsets .UTF_8 ));
173165 text .markAsComplete ();
174166 text .doProgressText (req , rsp );
175167 return ;
176168 }
177169
178- // Get logs
179- try (LogWatch ignore =
180- resource .inContainer (containerId ).tailingLines (20 ).watchLog (outputStream )) {
170+ // Get logs, the state of the container should not matter
171+ try (LogWatch ignore = resource .inContainer (containerId ).watchLog (outputStream )) {
172+ // without Thread.sleep logs are not shown
173+ Thread .sleep (5000L );
181174 text .doProgressText (req , rsp );
182- } catch (KubernetesClientException kce ) {
183- LOGGER .log (Level .WARNING , "Failed getting container logs for " + containerId , kce );
175+ } catch (KubernetesClientException | InterruptedException e ) {
176+ LOGGER .log (Level .WARNING , "Failed getting container logs for " + containerId , e );
184177 }
185178 } else {
186179 outputStream .write ("Node not available" .getBytes (StandardCharsets .UTF_8 ));
0 commit comments