various changes

This commit is contained in:
2026-09-08 10:35:18 +02:00
parent 4188bea061
commit dfae78af71
2871 changed files with 280 additions and 732763 deletions

View File

@@ -21,6 +21,7 @@ import dev.failsafe.FailsafeException
import dev.failsafe.RetryPolicy
import dev.failsafe.event.EventListener
import dev.failsafe.event.ExecutionAttemptedEvent
import dev.failsafe.function.CheckedPredicate
import dev.failsafe.function.CheckedSupplier
import nextflow.exception.K8sOutOfCpuException
import nextflow.exception.K8sOutOfMemoryException
@@ -371,6 +372,32 @@ class K8sClient {
(resp?.spec as Map)?.nodeName as String
}
/**
* Get the external IP address of a node
* @param nodeName The node name
* @return The external IP address of the node, or internal IP if external is not available
*/
String getNodeExternalIp(String nodeName) {
assert nodeName
final K8sResponseJson resp = nodeDescribe(nodeName)
final status = resp.status as Map
final addresses = status?.addresses as List<Map>
// Try to find ExternalIP first
for (Map address : addresses) {
if (address.type == 'ExternalIP') {
return address.address as String
}
}
// Fall back to InternalIP
for (Map address : addresses) {
if (address.type == 'InternalIP') {
return address.address as String
}
}
return null
}
/**
* Get pod current state object
*
@@ -870,10 +897,17 @@ class K8sClient {
trace('GET', action, resp.text)
final podList = new K8sResponseJson(resp.text)
final items = podList.items as List<Map>
long totalAllocated = 0L
if (items) {
for (Map pod : items) {
// Skip terminated/succeeded pods
final status = pod.status as Map
final phase = status?.phase as String
if (phase in ['Succeeded', 'Failed', 'Unknown']) {
continue
}
final spec = pod.spec as Map
if (spec) {
final containers = spec.containers as List<Map>
@@ -936,6 +970,13 @@ class K8sClient {
long totalAllocated = 0L
if (items) {
for (Map pod : items) {
// Skip terminated/succeeded pods
final status = pod.status as Map
final phase = status?.phase as String
if (phase in ['Succeeded', 'Failed', 'Unknown']) {
continue
}
final spec = pod.spec as Map
if (spec) {
final containers = spec.containers as List<Map>
@@ -1192,12 +1233,12 @@ class K8sClient {
* @param cond A predicate that determines when a retry should be triggered
* @return The {@link dev.failsafe.RetryPolicy} instance
*/
protected <T> RetryPolicy<T> retryPolicy(Predicate<? extends Throwable> cond) {
protected <T> RetryPolicy<T> retryPolicy(CheckedPredicate<? extends Throwable> cond) {
final cfg = config.retryConfig
final listener = new EventListener<ExecutionAttemptedEvent<T>>() {
@Override
void accept(ExecutionAttemptedEvent<T> event) throws Throwable {
log.debug("K8s response error - attempt: ${event.attemptCount}; reason: ${event.lastFailure.message}")
log.debug("K8s response error - attempt: ${event.attemptCount}; reason: ${event.lastException?.message ?: 'unknown'}")
}
}
return RetryPolicy.<T>builder()
@@ -1219,9 +1260,8 @@ class K8sClient {
*/
protected <T> T apply(CheckedSupplier<T> action) {
// define the retry condition
final cond = new Predicate<? extends Throwable>() {
@Override
boolean test(Throwable t) {
final cond = [
test: { Throwable t ->
if ( t instanceof K8sResponseException && t.response.code in RETRY_CODES )
return true
if( t instanceof SocketException || t.cause instanceof SocketException )
@@ -1230,7 +1270,7 @@ class K8sClient {
return true
return false
}
}
] as CheckedPredicate<Throwable>
// create the retry policy object
final policy = retryPolicy(cond)
// apply the action with and throw the original cause