Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: "invalid pod status" when running scrips with the kubernetes executor. #1242

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -244,20 +244,22 @@ class K8sClient {
return state
}

if( status?.phase == 'Pending' && status.conditions instanceof List ) {
final allConditions = status.conditions as List<Map>
final cond = allConditions.find { cond -> cond.type == 'PodScheduled' }
if( cond.reason == 'Unschedulable' ) {
def message = "K8s pod cannot be scheduled"
if( cond.message ) message += " -- $cond.message"
//def cause = new K8sResponseException(resp)
log.warn1(message)
if( status?.phase == 'Pending' ){
if( status.conditions instanceof List ) {
final allConditions = status.conditions as List<Map>
final cond = allConditions.find { cond -> cond.type == 'PodScheduled' }
if( cond.reason == 'Unschedulable' ) {
def message = "K8s pod cannot be scheduled"
if( cond.message ) message += " -- $cond.message"
//def cause = new K8sResponseException(resp)
log.warn1(message)
}
}
pditommaso marked this conversation as resolved.
Show resolved Hide resolved
// undetermined status -- return an empty response
return Collections.emptyMap()
}

throw new K8sResponseException("K8s invalid pod status (missing container status)", resp)
throw new K8sResponseException("K8s undetermined status conditions for pod $podName", resp)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frankly, I think the previous err message was a bit more informative.

Copy link
Contributor Author

@olifly olifly Jul 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pditommaso The previous message did not reflect why the Exception was being thrown anymore. The problem is not missing container status, but rather that K8s returned a set of phase and conditions that the code can not determine the pod state (end of function without any resolvement).

I can revert the change to the message, or insert a more informative message of your choice 😄 (I'm really bad at constructing error message btw 🙈)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, what about K8s undermined status conditions for pod $podName ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, what about K8s undermined status conditions for pod $podName ?

Sounds good to me. Will update pull request.


protected void checkInvalidWaitingState( Map waiting, K8sResponseJson resp ) {
Expand Down
Expand Up @@ -426,6 +426,46 @@ class K8sClientTest extends Specification {
result == [:]
}

def 'should return undetermined status when status conditions are missing' () {
given:
def JSON = '''
{
"kind": "Pod",
"apiVersion": "v1",
"metadata": {
"name": "nf-89b34d7c2d1dc11daad72b1fcf7e0540",
"namespace": "default",
"selfLink": "/api/v1/namespaces/default/pods/nf-89b34d7c2d1dc11daad72b1fcf7e0540/status",
"uid": "02c3a34d-7720-11e9-8e1a-0a8b849038f8",
"resourceVersion": "21753960",
"creationTimestamp": "2019-05-15T14:44:58Z",
"labels": {
"app": "nextflow",
"processName": "split_input_file",
"runName": "hopeful_lalande",
"sessionId": "uuid-6b10c771-1a70-4af0-92be-7c0280e0e17f",
"taskName": "split_input_file_variants.gord_chr11_72000001-78000000",
}
},

"status": {
"phase": "Pending",
"qosClass": "Guaranteed"
}
}
'''

def client = Spy(K8sClient)
final POD_NAME = 'nf-89b34d7c2d1dc11daad72b1fcf7e0540'

when:
def result = client.podState(POD_NAME)
then:
1 * client.podStatus(POD_NAME) >> new K8sResponseJson(JSON)

result == [:]
}

def 'should fail to get pod state' () {

given:
Expand All @@ -439,14 +479,14 @@ class K8sClientTest extends Specification {
then:
1 * client.podStatus(POD_NAME) >> new K8sResponseJson([:])
e = thrown(K8sResponseException)
e.message.startsWith('K8s invalid pod status (missing container status)')
e.message.startsWith('K8s undetermined status conditions for pod')

when:
client.podState(POD_NAME)
then:
1 * client.podStatus(POD_NAME) >> new K8sResponseJson([status:[containerStatuses: []]])
e = thrown(K8sResponseException)
e.message.startsWith('K8s invalid pod status (missing container status)')
e.message.startsWith('K8s undetermined status conditions for pod')

when:
client.podState(POD_NAME)
Expand Down