Skip to content

Commit 2565d7b

Browse files
committed
fix: isTerminal(Pod) logic works with Monopod (#13854)
1 parent 3824ae2 commit 2565d7b

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

airbyte-workload-launcher/src/main/kotlin/pods/KubePodLauncher.kt

+32-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import io.airbyte.featureflag.UseCustomK8sInitCheck
88
import io.airbyte.metrics.lib.MetricAttribute
99
import io.airbyte.metrics.lib.MetricClient
1010
import io.airbyte.metrics.lib.OssMetricsRegistry
11-
import io.airbyte.workers.process.KubePodResourceHelper
11+
import io.airbyte.workers.pod.ContainerConstants
1212
import io.airbyte.workload.launcher.pods.KubePodLauncher.Constants.FABRIC8_COMPLETED_REASON_VALUE
1313
import io.airbyte.workload.launcher.pods.KubePodLauncher.Constants.KUBECTL_COMPLETED_VALUE
1414
import io.airbyte.workload.launcher.pods.KubePodLauncher.Constants.KUBECTL_PHASE_FIELD_NAME
@@ -199,7 +199,7 @@ class KubePodLauncher(
199199
.waitUntilCondition(
200200
{ p: Pod? ->
201201
Objects.nonNull(p) &&
202-
(Readiness.getInstance().isReady(p) || KubePodResourceHelper.isTerminal(p))
202+
(Readiness.getInstance().isReady(p) || isTerminal(p))
203203
},
204204
waitDuration.toMinutes(),
205205
TimeUnit.MINUTES,
@@ -220,7 +220,7 @@ class KubePodLauncher(
220220
.waitUntilCondition(
221221
{ p: Pod? ->
222222
Objects.nonNull(p) &&
223-
(Readiness.getInstance().isReady(p) || KubePodResourceHelper.isTerminal(p))
223+
(Readiness.getInstance().isReady(p) || isTerminal(p))
224224
},
225225
waitDuration.toMinutes(),
226226
TimeUnit.MINUTES,
@@ -240,7 +240,7 @@ class KubePodLauncher(
240240
.list()
241241
.items
242242
.stream()
243-
.filter { kubePod: Pod -> !KubePodResourceHelper.isTerminal(kubePod) && !PodStatusUtil.isInitializing(kubePod) }
243+
.filter { kubePod: Pod -> !isTerminal(kubePod) && !PodStatusUtil.isInitializing(kubePod) }
244244
.findAny()
245245
.isPresent
246246
},
@@ -292,6 +292,34 @@ class KubePodLauncher(
292292
)
293293
}
294294

295+
/**
296+
* Checks that the pod's main container(s) are in a terminal state.
297+
*/
298+
private fun isTerminal(pod: Pod?): Boolean {
299+
// if pod is null or there is no status default to false.
300+
if (pod?.status == null) {
301+
return false
302+
}
303+
304+
// Get statuses for all "non-init" containers.
305+
val mainContainerStatuses =
306+
pod.status
307+
.containerStatuses
308+
.stream()
309+
.filter { containerStatus -> (ContainerConstants.INIT_CONTAINER_NAME) != containerStatus.name }
310+
.toList()
311+
312+
// There should be at least 1 container with a status.
313+
if (mainContainerStatuses.size < 1) {
314+
logger.warn { "Unexpectedly no non-init container statuses found for pod: ${pod.fullResourceName}" }
315+
return false
316+
}
317+
318+
return mainContainerStatuses.all {
319+
it.state?.terminated != null
320+
}
321+
}
322+
295323
private fun listActivePods(labels: Map<String, String>): FilterWatchListDeletable<Pod, PodList, PodResource> {
296324
return kubernetesClient.pods()
297325
.inNamespace(namespace)

0 commit comments

Comments
 (0)