Skip to content

Commit 44f754f

Browse files
committed
chore: integrate and apply spotless
1 parent f043818 commit 44f754f

5 files changed

Lines changed: 146 additions & 133 deletions

File tree

src/main/java/io/kestra/plugin/kubernetes/core/PodCreate.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,6 @@ public PodCreate.Output run(RunContext runContext) throws Exception {
429429
// This ensures we proceed with log collection regardless of pod outcome
430430
pod = PodService.waitForContainersStartedOrCompleted(client, pod, rWaitUntilRunning);
431431

432-
433432
// Only start log streaming if pod is actually running
434433
// For pods that complete quickly, fetchFinalLogs will handle log collection
435434
if (pod.getStatus() != null && PodService.PodPhase.RUNNING.value().equals(pod.getStatus().getPhase())) {

src/main/java/io/kestra/plugin/kubernetes/services/PodLogService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ public void fetchFinalLogs(KubernetesClient client, Pod pod, RunContext runConte
169169

170170
PodResource podResource = PodService.podRef(client, pod);
171171

172-
if (pod.getSpec().getContainers().stream().noneMatch(container -> {
172+
if (pod.getSpec().getContainers().stream().noneMatch(container ->
173+
{
173174
try {
174175
String logs = podResource
175176
.inContainer(container.getName())

src/main/java/io/kestra/plugin/kubernetes/services/PodService.java

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
package io.kestra.plugin.kubernetes.services;
22

3-
import io.fabric8.kubernetes.api.model.*;
4-
import io.fabric8.kubernetes.client.Config;
5-
import io.fabric8.kubernetes.client.KubernetesClient;
6-
import io.fabric8.kubernetes.client.KubernetesClientException;
7-
import io.fabric8.kubernetes.client.dsl.PodResource;
8-
import io.kestra.core.exceptions.IllegalVariableEvaluationException;
9-
import io.kestra.core.models.tasks.retrys.Exponential;
10-
import io.kestra.core.models.tasks.runners.AbstractLogConsumer;
11-
import io.kestra.core.runners.RunContext;
12-
import io.kestra.core.utils.RetryUtils;
13-
import io.kestra.plugin.kubernetes.models.Connection;
14-
import org.slf4j.Logger;
15-
163
import java.io.File;
174
import java.io.IOException;
185
import java.nio.file.Path;
@@ -28,6 +15,7 @@
2815

2916
import io.kestra.core.exceptions.IllegalVariableEvaluationException;
3017
import io.kestra.core.models.tasks.retrys.Exponential;
18+
import io.kestra.core.models.tasks.runners.AbstractLogConsumer;
3119
import io.kestra.core.runners.RunContext;
3220
import io.kestra.core.utils.RetryUtils;
3321
import io.kestra.plugin.kubernetes.models.Connection;
@@ -72,25 +60,24 @@ public static Pod waitForPodReady(KubernetesClient client, Pod pod, Duration wai
7260
return PodService.podRef(client, pod)
7361
.waitUntilCondition(
7462
j -> j != null &&
75-
j.getStatus() != null && (
76-
PodPhase.FAILED.value().equals(j.getStatus().getPhase()) ||
77-
(j.getStatus().getContainerStatuses() != null &&
78-
j.getStatus().getContainerStatuses().stream()
79-
.anyMatch(cs -> cs.getState() != null &&
63+
j.getStatus() != null && (PodPhase.FAILED.value().equals(j.getStatus().getPhase()) ||
64+
(j.getStatus().getContainerStatuses() != null &&
65+
j.getStatus().getContainerStatuses().stream()
66+
.anyMatch(
67+
cs -> cs.getState() != null &&
8068
cs.getState().getWaiting() != null &&
8169
cs.getState().getWaiting().getReason() != null &&
8270
!TransientWaitingReason.contains(cs.getState().getWaiting().getReason())
83-
)
84-
) ||
71+
))
72+
||
8573
j.getStatus()
8674
.getConditions()
8775
.stream()
88-
.anyMatch(podCondition ->
89-
("ContainersReady".equals(podCondition.getType()) &&
76+
.anyMatch(
77+
podCondition -> ("ContainersReady".equals(podCondition.getType()) &&
9078
(hasSidecar || "True".equals(podCondition.getStatus()))) ||
9179
("PodCompleted".equals(podCondition.getReason()))
92-
)
93-
),
80+
)),
9481
waitUntilRunning.toSeconds(),
9582
TimeUnit.SECONDS
9683
);
@@ -100,11 +87,10 @@ public static Pod waitForContainersStartedOrCompleted(KubernetesClient client, P
10087
return PodService.podRef(client, pod)
10188
.waitUntilCondition(
10289
j -> j != null &&
103-
j.getStatus() != null && (
104-
(PodPhase.RUNNING.value().equals(j.getStatus().getPhase()) &&
105-
j.getStatus().getContainerStatuses() != null &&
106-
j.getStatus().getContainerStatuses().stream()
107-
.anyMatch(c -> c.getState().getRunning() != null))
90+
j.getStatus() != null && ((PodPhase.RUNNING.value().equals(j.getStatus().getPhase()) &&
91+
j.getStatus().getContainerStatuses() != null &&
92+
j.getStatus().getContainerStatuses().stream()
93+
.anyMatch(c -> c.getState().getRunning() != null))
10894
||
10995
COMPLETED_PHASES.contains(j.getStatus().getPhase())),
11096
waitUntilRunning.toSeconds(),
@@ -201,12 +187,15 @@ public static IllegalStateException failedMessage(Pod pod) throws IllegalStateEx
201187
.filter(containerStatus -> containerStatus.getState() != null && containerStatus.getState().getTerminated() != null)
202188
.map(containerStatus -> containerStatus.getState().getTerminated())
203189
.findFirst()
204-
.map(containerStateTerminated -> new IllegalStateException(
205-
"Pods terminated with status '" + pod.getStatus().getPhase() + "', " +
206-
"exitcode '" + containerStateTerminated.getExitCode() + "' & " +
207-
"message '" + containerStateTerminated.getMessage() + "'"
208-
))
209-
.orElseGet(() -> {
190+
.map(
191+
containerStateTerminated -> new IllegalStateException(
192+
"Pods terminated with status '" + pod.getStatus().getPhase() + "', " +
193+
"exitcode '" + containerStateTerminated.getExitCode() + "' & " +
194+
"message '" + containerStateTerminated.getMessage() + "'"
195+
)
196+
)
197+
.orElseGet(() ->
198+
{
210199
if (pod.getStatus().getContainerStatuses() != null) {
211200
Optional<String> waitingReason = pod.getStatus().getContainerStatuses().stream()
212201
.filter(cs -> cs.getState() != null && cs.getState().getWaiting() != null)
@@ -324,11 +313,14 @@ public static void logPodEvents(KubernetesClient client, Pod pod, Logger logger,
324313
.getItems()
325314
.stream()
326315
.filter(event -> "Warning".equals(event.getType()))
327-
.sorted(Comparator.comparing(
328-
Event::getLastTimestamp,
329-
Comparator.nullsLast(Comparator.naturalOrder())
330-
))
331-
.forEach(event -> {
316+
.sorted(
317+
Comparator.comparing(
318+
Event::getLastTimestamp,
319+
Comparator.nullsLast(Comparator.naturalOrder())
320+
)
321+
)
322+
.forEach(event ->
323+
{
332324
String reason = event.getReason() == null ? "" : event.getReason();
333325
String message = event.getMessage() == null ? "" : event.getMessage();
334326

@@ -348,8 +340,9 @@ public static boolean hasAnyContainerStarted(Pod pod) {
348340
return false;
349341
}
350342
return pod.getStatus().getContainerStatuses().stream()
351-
.anyMatch(cs -> cs.getState() != null &&
352-
(cs.getState().getRunning() != null || cs.getState().getTerminated() != null)
343+
.anyMatch(
344+
cs -> cs.getState() != null &&
345+
(cs.getState().getRunning() != null || cs.getState().getTerminated() != null)
353346
);
354347
}
355348

@@ -358,10 +351,11 @@ public static boolean hasNonTransientWaitingContainer(Pod pod) {
358351
return false;
359352
}
360353
return pod.getStatus().getContainerStatuses().stream()
361-
.anyMatch(cs -> cs.getState() != null &&
362-
cs.getState().getWaiting() != null &&
363-
cs.getState().getWaiting().getReason() != null &&
364-
!TransientWaitingReason.contains(cs.getState().getWaiting().getReason())
354+
.anyMatch(
355+
cs -> cs.getState() != null &&
356+
cs.getState().getWaiting() != null &&
357+
cs.getState().getWaiting().getReason() != null &&
358+
!TransientWaitingReason.contains(cs.getState().getWaiting().getReason())
365359
);
366360
}
367361

@@ -398,8 +392,12 @@ public enum PodPhase {
398392

399393
private final String value;
400394

401-
PodPhase(String value) { this.value = value; }
395+
PodPhase(String value) {
396+
this.value = value;
397+
}
402398

403-
public String value() { return value; }
399+
public String value() {
400+
return value;
401+
}
404402
}
405403
}

src/test/java/io/kestra/plugin/kubernetes/core/PodCreateTest.java

Lines changed: 89 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,19 @@ void failedWithOutputFiles() throws Exception {
220220
.namespace(Property.ofValue("default"))
221221
.outputFiles(Property.ofValue(List.of("results.json")))
222222
.waitForLogInterval(Property.ofValue(Duration.ofSeconds(1)))
223-
.spec(TestUtils.convert(
224-
ObjectMeta.class,
225-
"containers:",
226-
"- name: unittest",
227-
" image: debian:stable-slim",
228-
" command: ",
229-
" - 'bash' ",
230-
" - '-c'",
231-
" - 'echo \"Container failing\" && sleep 1 && exit 1'",
232-
"restartPolicy: Never"
233-
))
223+
.spec(
224+
TestUtils.convert(
225+
ObjectMeta.class,
226+
"containers:",
227+
"- name: unittest",
228+
" image: debian:stable-slim",
229+
" command: ",
230+
" - 'bash' ",
231+
" - '-c'",
232+
" - 'echo \"Container failing\" && sleep 1 && exit 1'",
233+
"restartPolicy: Never"
234+
)
235+
)
234236
.build();
235237

236238
Flow flow = TestsUtils.mockFlow();
@@ -678,18 +680,20 @@ void sidecarResources() throws Exception {
678680
)
679681
)
680682
.outputFiles(Property.ofValue(List.of("out.txt")))
681-
.spec(TestUtils.convert(
682-
ObjectMeta.class,
683-
"containers:",
684-
"- name: in-out-files",
685-
" image: busybox",
686-
" command: [\"/bin/sh\"]",
687-
" args:",
688-
" - -c",
689-
" - >-",
690-
" cat {{ workingDir }}/in.txt > {{ workingDir }}/out.txt",
691-
"restartPolicy: Never"
692-
))
683+
.spec(
684+
TestUtils.convert(
685+
ObjectMeta.class,
686+
"containers:",
687+
"- name: in-out-files",
688+
" image: busybox",
689+
" command: [\"/bin/sh\"]",
690+
" args:",
691+
" - -c",
692+
" - >-",
693+
" cat {{ workingDir }}/in.txt > {{ workingDir }}/out.txt",
694+
"restartPolicy: Never"
695+
)
696+
)
693697
.build();
694698

695699
Flow flow = TestsUtils.mockFlow();
@@ -917,17 +921,19 @@ void successWithOutputFiles() throws Exception {
917921
.namespace(Property.ofValue("default"))
918922
.outputFiles(Property.ofValue(List.of("result.txt")))
919923
.waitForLogInterval(Property.ofValue(Duration.ofSeconds(1)))
920-
.spec(TestUtils.convert(
921-
ObjectMeta.class,
922-
"containers:",
923-
"- name: unittest",
924-
" image: debian:stable-slim",
925-
" command: ",
926-
" - 'bash' ",
927-
" - '-c'",
928-
" - 'echo \"Task succeeded\" > {{ workingDir }}/result.txt && sleep 1 && exit 0'",
929-
"restartPolicy: Never"
930-
))
924+
.spec(
925+
TestUtils.convert(
926+
ObjectMeta.class,
927+
"containers:",
928+
"- name: unittest",
929+
" image: debian:stable-slim",
930+
" command: ",
931+
" - 'bash' ",
932+
" - '-c'",
933+
" - 'echo \"Task succeeded\" > {{ workingDir }}/result.txt && sleep 1 && exit 0'",
934+
"restartPolicy: Never"
935+
)
936+
)
931937
.build();
932938

933939
Flow flow = TestsUtils.mockFlow();
@@ -953,23 +959,25 @@ void multipleContainersOneFailsWithOutputFiles() throws Exception {
953959
.namespace(Property.ofValue("default"))
954960
.outputFiles(Property.ofValue(List.of("result.txt")))
955961
.waitForLogInterval(Property.ofValue(Duration.ofSeconds(1)))
956-
.spec(TestUtils.convert(
957-
ObjectMeta.class,
958-
"containers:",
959-
"- name: container-success",
960-
" image: debian:stable-slim",
961-
" command: ",
962-
" - 'bash' ",
963-
" - '-c'",
964-
" - 'echo \"First container succeeded\" && sleep 1 && exit 0'",
965-
"- name: container-failure",
966-
" image: debian:stable-slim",
967-
" command: ",
968-
" - 'bash' ",
969-
" - '-c'",
970-
" - 'echo \"Second container failing\" && sleep 1 && exit 1'",
971-
"restartPolicy: Never"
972-
))
962+
.spec(
963+
TestUtils.convert(
964+
ObjectMeta.class,
965+
"containers:",
966+
"- name: container-success",
967+
" image: debian:stable-slim",
968+
" command: ",
969+
" - 'bash' ",
970+
" - '-c'",
971+
" - 'echo \"First container succeeded\" && sleep 1 && exit 0'",
972+
"- name: container-failure",
973+
" image: debian:stable-slim",
974+
" command: ",
975+
" - 'bash' ",
976+
" - '-c'",
977+
" - 'echo \"Second container failing\" && sleep 1 && exit 1'",
978+
"restartPolicy: Never"
979+
)
980+
)
973981
.build();
974982

975983
Flow flow = TestsUtils.mockFlow();
@@ -1000,17 +1008,19 @@ void completeLogCollectionAfterQuickTermination() throws Exception {
10001008
.namespace(Property.ofValue("default"))
10011009
.outputFiles(Property.ofValue(List.of("result.txt")))
10021010
.waitForLogInterval(Property.ofValue(Duration.ofSeconds(1)))
1003-
.spec(TestUtils.convert(
1004-
ObjectMeta.class,
1005-
"containers:",
1006-
"- name: unittest",
1007-
" image: debian:stable-slim",
1008-
" command:",
1009-
" - 'bash'",
1010-
" - '-c'",
1011-
" - 'seq 1 20 | while read i; do echo \"Quick termination log line $i\"; done; echo \"FINAL\" && sleep 1 && exit 1'",
1012-
"restartPolicy: Never"
1013-
))
1011+
.spec(
1012+
TestUtils.convert(
1013+
ObjectMeta.class,
1014+
"containers:",
1015+
"- name: unittest",
1016+
" image: debian:stable-slim",
1017+
" command:",
1018+
" - 'bash'",
1019+
" - '-c'",
1020+
" - 'seq 1 20 | while read i; do echo \"Quick termination log line $i\"; done; echo \"FINAL\" && sleep 1 && exit 1'",
1021+
"restartPolicy: Never"
1022+
)
1023+
)
10141024
.build();
10151025

10161026
Flow flow = TestsUtils.mockFlow();
@@ -1627,21 +1637,23 @@ void containerDefaultSpecMultipleFields() throws Exception {
16271637
)
16281638
.inputFiles(Map.of("in.txt", "test content"))
16291639
.outputFiles(Property.ofValue(List.of("out.txt")))
1630-
.spec(TestUtils.convert(
1631-
ObjectMeta.class,
1632-
"volumes:",
1633-
" - name: shared-tmp",
1634-
" emptyDir: {}",
1635-
"containers:",
1636-
"- name: main",
1637-
" image: busybox",
1638-
" command: [\"/bin/sh\"]",
1639-
" args:",
1640-
" - -c",
1641-
" - >-",
1642-
" cat {{ workingDir }}/in.txt > {{ workingDir }}/out.txt",
1643-
"restartPolicy: Never"
1644-
))
1640+
.spec(
1641+
TestUtils.convert(
1642+
ObjectMeta.class,
1643+
"volumes:",
1644+
" - name: shared-tmp",
1645+
" emptyDir: {}",
1646+
"containers:",
1647+
"- name: main",
1648+
" image: busybox",
1649+
" command: [\"/bin/sh\"]",
1650+
" args:",
1651+
" - -c",
1652+
" - >-",
1653+
" cat {{ workingDir }}/in.txt > {{ workingDir }}/out.txt",
1654+
"restartPolicy: Never"
1655+
)
1656+
)
16451657
.build();
16461658

16471659
Flow flow = TestsUtils.mockFlow();

0 commit comments

Comments
 (0)