Search in sources :

Example 1 with KubeApiException

use of com.netflix.titus.runtime.connector.kubernetes.KubeApiException in project titus-control-plane by Netflix.

the class DefaultDirectKubeApiServerIntegrator method terminateTask.

@Override
public Mono<Void> terminateTask(Task task) {
    String taskId = task.getId();
    return Mono.<Void>fromRunnable(() -> {
        Stopwatch timer = Stopwatch.createStarted();
        try {
            logger.info("Deleting pod: {}", taskId);
            kubeApiFacade.deleteNamespacedPod(KUBERNETES_NAMESPACE, taskId, DELETE_GRACE_PERIOD_SECONDS);
            metrics.terminateSuccess(task, timer.elapsed(TimeUnit.MILLISECONDS));
        } catch (JsonSyntaxException e) {
            // this is probably successful. the generated client has the wrong response type
            metrics.terminateSuccess(task, timer.elapsed(TimeUnit.MILLISECONDS));
        } catch (KubeApiException e) {
            metrics.terminateError(task, e, timer.elapsed(TimeUnit.MILLISECONDS));
            if (e.getErrorCode() == KubeApiException.ErrorCode.NOT_FOUND && task.getStatus().getState() == TaskState.Accepted) {
                sendEvent(PodEvent.onPodNotFound(task, TaskStatus.newBuilder().withState(TaskState.Finished).withReasonCode(TaskStatus.REASON_TASK_LOST).withReasonMessage("Task terminate requested, but its container is not found").withTimestamp(titusRuntime.getClock().wallTime()).build()));
            } else {
                logger.error("Failed to kill task: {} with error: {}", taskId, KubeUtil.toErrorDetails(e), e);
            }
        } catch (Exception e) {
            logger.error("Failed to kill task: {} with error: {}", taskId, KubeUtil.toErrorDetails(e), e);
            metrics.terminateError(task, e, timer.elapsed(TimeUnit.MILLISECONDS));
        }
    }).subscribeOn(apiClientScheduler).timeout(Duration.ofMillis(configuration.getKubeApiClientTimeoutMs()));
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) KubeApiException(com.netflix.titus.runtime.connector.kubernetes.KubeApiException) Stopwatch(com.google.common.base.Stopwatch) TimeoutException(java.util.concurrent.TimeoutException) JsonSyntaxException(com.google.gson.JsonSyntaxException) KubeApiException(com.netflix.titus.runtime.connector.kubernetes.KubeApiException)

Aggregations

Stopwatch (com.google.common.base.Stopwatch)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 KubeApiException (com.netflix.titus.runtime.connector.kubernetes.KubeApiException)1 TimeoutException (java.util.concurrent.TimeoutException)1