io.fabric8.kubernetes.client.KubernetesClientTimeoutException Java Examples

The following examples show how to use io.fabric8.kubernetes.client.KubernetesClientTimeoutException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MeteredFabric8KubernetesClientProxy.java    From styx with Apache License 2.0 5 votes vote down vote up
private void reportOperationError(String operation, Throwable e, Stats stats) {
  var kubernetesClientException = findCause(e, KubernetesClientException.class);
  if (kubernetesClientException != null) {
    final String type = (kubernetesClientException instanceof KubernetesClientTimeoutException)
                        ? "kubernetes-client-timeout"
                        : "kubernetes-client";
    stats.recordKubernetesOperationError(operation, type, kubernetesClientException.getCode());
  } else {
    stats.recordKubernetesOperationError(operation, "unknown", 0);
  }
}
 
Example #2
Source File: MeteredFabric8KubernetesClientProxyTest.java    From styx with Apache License 2.0 5 votes vote down vote up
@Test
public void reportKubernetesClientTimeoutException() {
  doThrow(new KubernetesClientTimeoutException(List.of(), 10L, TimeUnit.SECONDS))
      .when(fabric8KubernetesClient).listPods();

  try {
    proxy.listPods();
    fail("Expected exception");
  } catch (Exception ignored) {
  }

  verify(stats).recordKubernetesOperationError("listPods", "kubernetes-client-timeout", 0);
}
 
Example #3
Source File: AllContainersRunningPodWatcher.java    From kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Wait until all pod containers are running
 * 
 * @return the pod
 * @throws IllegalStateException
 *             if pod or containers are no longer running
 * @throws KubernetesClientTimeoutException
 *             if time ran out
 */
public Pod await(long amount, TimeUnit timeUnit) {
    long started = System.currentTimeMillis();
    long alreadySpent = System.currentTimeMillis() - started;
    long remaining = timeUnit.toMillis(amount) - alreadySpent;
    if (remaining <= 0) {
        return periodicAwait(0, System.currentTimeMillis(), 0, 0);
    }
    try {
        return periodicAwait(10, System.currentTimeMillis(), Math.max(remaining / 10, 1000L), remaining);
    } catch (KubernetesClientTimeoutException e) {
        // Wrap using the right timeout
        throw new KubernetesClientTimeoutException(pod, amount, timeUnit);
    }
}
 
Example #4
Source File: AllContainersRunningPodWatcher.java    From kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
private Pod awaitWatcher(long amount, TimeUnit timeUnit) {
    try {
        if (latch.await(amount, timeUnit)) {
            return reference.get();
        }
        throw new KubernetesClientTimeoutException(pod, amount, timeUnit);
    } catch (InterruptedException e) {
        throw new KubernetesClientTimeoutException(pod, amount, timeUnit);
    }
}
 
Example #5
Source File: AllContainersRunningPodWatcher.java    From kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Wait until all pod containers are running
 * 
 * @return the pod
 * @throws IllegalStateException
 *             if pod or containers are no longer running
 * @throws KubernetesClientTimeoutException
 *             if time ran out
 */
private Pod periodicAwait(int i, long started, long interval, long amount) {
    Pod pod = client.pods().inNamespace(this.pod.getMetadata().getNamespace())
            .withName(this.pod.getMetadata().getName()).get();
    if (pod == null) {
        throw new IllegalStateException(String.format("Pod is no longer available: %s/%s",
                this.pod.getMetadata().getNamespace(), this.pod.getMetadata().getName()));
    } else {
        LOGGER.finest(() -> "Updating pod for " + this.pod.getMetadata().getNamespace() + "/" + this.pod.getMetadata().getName() + " : " + Serialization.asYaml(pod));
        this.pod = pod;
    }
    List<ContainerStatus> terminatedContainers = PodUtils.getTerminatedContainers(pod);
    if (!terminatedContainers.isEmpty()) {
        throw new IllegalStateException(String.format("Pod has terminated containers: %s/%s (%s)",
                this.pod.getMetadata().getNamespace(),
                this.pod.getMetadata().getName(),
                terminatedContainers.stream()
                        .map(ContainerStatus::getName)
                        .collect(joining(", ")
                        )));
    }
    if (areAllContainersRunning(pod)) {
        return pod;
    }
    try {
        return awaitWatcher(interval, TimeUnit.MILLISECONDS);
    } catch (KubernetesClientTimeoutException e) {
        if (i <= 0) {
            throw e;
        }
    }

    long remaining = (started + amount) - System.currentTimeMillis();
    long next = Math.max(0, Math.min(remaining, interval));
    return periodicAwait(i - 1, started, next, amount);
}
 
Example #6
Source File: ReadinessWatcher.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
public T await(long amount, TimeUnit timeUnit) {
  try {
    if (latch.await(amount, timeUnit)) {
      return reference.get();
    }
    throw new KubernetesClientTimeoutException(resource, amount, timeUnit);
  } catch (InterruptedException e) {
    Thread.currentThread().interrupt();
    throw new KubernetesClientTimeoutException(resource, amount, timeUnit);
  }
}