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()));
}
Aggregations