Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ class K8sClient {
log.warn1("Job $jobName already completed and Pod is gone")
final dummyPodStatus = [
terminated: [
exitcode: 0,
reason: "Completed",
startedAt: jobStatus.startTime,
finishedAt: jobStatus.completionTime,
Expand Down
43 changes: 43 additions & 0 deletions plugins/nf-k8s/src/test/nextflow/k8s/client/K8sClientTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1059,4 +1059,47 @@ class K8sClientTest extends Specification {
def e = thrown(PodUnschedulableException)
e.message == "K8s pod in Failed state"
}

def 'should fallback to job status when pod is gone and not return hardcoded exit code' () {
given:
def JOB_STATUS_JSON = '''
{
"apiVersion": "batch/v1",
"kind": "Job",
"metadata": {
"name": "test-job"
},
"status": {
"succeeded": 1,
"startTime": "2025-01-15T10:00:00Z",
"completionTime": "2025-01-15T10:05:00Z",
"conditions": [
{
"type": "Complete",
"status": "True",
"lastProbeTime": "2025-01-15T10:05:00Z",
"lastTransitionTime": "2025-01-15T10:05:00Z"
}
]
}
}
'''
def client = Spy(K8sClient)
final JOB_NAME = 'test-job'

when:
def result = client.jobStateFallback0(JOB_NAME)

then:
1 * client.jobStatus(JOB_NAME) >> new K8sResponseJson(JOB_STATUS_JSON)

and:
result.terminated != null
result.terminated.reason == 'Completed'
result.terminated.startedAt == '2025-01-15T10:00:00Z'
result.terminated.finishedAt == '2025-01-15T10:05:00Z'
// The key assertion: exitCode should not be present (null) so fallback to .exitcode file works
result.terminated.exitCode == null
result.terminated.exitcode == null
}
}
Loading