Skip to content

Commit

Permalink
Use switch
Browse files Browse the repository at this point in the history
Signed-off-by: Lehmann-Fabian <[email protected]>
  • Loading branch information
Lehmann-Fabian committed Sep 27, 2022
1 parent 93723cd commit db9e30f
Showing 1 changed file with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -503,16 +503,12 @@ class K8sClient {
def msg = "K8s pod '$podName' execution failed"
if( status.reason ) msg += " - reason: ${status.reason}"
if( status.message ) msg += " - message: ${status.message}"
if ( 'OutOfcpu' == status.reason && (status.message as String).startsWith("Pod Node didn't have enough resource: cpu,")) {
throw new K8sOutOfCpuException(msg)
switch ( status.reason ) {
case 'OutOfcpu': throw new K8sOutOfCpuException(msg)
case 'OutOfmemory': throw new K8sOutOfMemoryException(msg)
case 'Shutdown': throw new NodeTerminationException(msg)
default: throw new ProcessFailedException(msg)
}
if ( 'OutOfmemory' == status.reason && (status.message as String).startsWith("Pod Node didn't have enough resource: memory,") ) {
throw new K8sOutOfMemoryException(msg)
}
final err = status.reason == 'Shutdown'
? new NodeTerminationException(msg)
: new ProcessFailedException(msg)
throw err
}

throw new K8sResponseException("K8s undetermined status conditions for pod $podName", resp)
Expand Down

0 comments on commit db9e30f

Please sign in to comment.