public FormValidation doTestConnection(@QueryParameter String name, @QueryParameter String serverUrl, @QueryParameter String credentialsId, @QueryParameter String serverCertificate, @QueryParameter boolean skipTlsVerify, @QueryParameter String namespace, @QueryParameter int connectionTimeout, @QueryParameter int readTimeout) throws Exception { if (StringUtils.isBlank(name)) return FormValidation.error("name is required"); try { KubernetesClient client = new KubernetesFactoryAdapter(serverUrl, namespace, Util.fixEmpty(serverCertificate), Util.fixEmpty(credentialsId), skipTlsVerify, connectionTimeout, readTimeout).createClient(); // test listing pods client.pods().list(); return FormValidation.ok("Connection test successful"); } catch (KubernetesClientException e) { LOGGER.log(Level.FINE, String.format("Error testing connection %s", serverUrl), e); return FormValidation.error("Error testing connection %s: %s", serverUrl, e.getCause() == null ? e.getMessage() : String.format("%s: %s", e.getCause().getClass().getName(), e.getCause().getMessage())); } catch (Exception e) { LOGGER.log(Level.FINE, String.format("Error testing connection %s", serverUrl), e); return FormValidation.error("Error testing connection %s: %s", serverUrl, e.getMessage()); } }
public static void handleKubernetesClientException(KubernetesClientException e, Logger logger) throws MojoExecutionException { Throwable cause = e.getCause(); if (cause instanceof UnknownHostException) { logger.error("Could not connect to kubernetes cluster!"); logger.error("Have you started a local cluster via `mvn fabric8:cluster-start` or connected to a remote cluster via `kubectl`?"); logger.info("For more help see: http://fabric8.io/guide/getStarted/"); logger.error("Connection error: %s", cause); String message = "Could not connect to kubernetes cluster. Have you started a cluster via `mvn fabric8:cluster-start` or connected to a remote cluster via `kubectl`? Error: " + cause; throw new MojoExecutionException(message, e); } else { throw new MojoExecutionException(e.getMessage(), e); } }
Throwable cause = e.getCause(); if (cause instanceof SocketTimeoutException || cause instanceof ConnectException || cause instanceof UnknownHostException) { LOGGER.log(Level.WARNING, "Failed to connect to Kubernetes at {0}: {1}",
public boolean isOpenShift(Logger log) { try { return this.client == null ? OpenshiftHelper.isOpenShift(createKubernetesClient()) : OpenshiftHelper.isOpenShift(this.client); } catch (KubernetesClientException exp) { Throwable cause = exp.getCause(); String prefix = cause instanceof UnknownHostException ? "Unknown host " : ""; log.warn("Cannot access cluster for detecting mode: %s%s", prefix, cause != null ? cause.getMessage() : exp.getMessage()); } return false; }
private Build startBuild(OpenShiftClient client, File dockerTar, String buildName) { log.info("Starting Build %s", buildName); try { return client.buildConfigs().withName(buildName) .instantiateBinary() .fromFile(dockerTar); } catch (KubernetesClientException exp) { Status status = exp.getStatus(); if (status != null) { log.error("OpenShift Error: [%d %s] [%s] %s", status.getCode(), status.getStatus(), status.getReason(), status.getMessage()); } if (exp.getCause() instanceof IOException && exp.getCause().getMessage().contains("Stream Closed")) { log.error("Build for %s failed: %s", buildName, exp.getCause().getMessage()); logBuildFailedDetails(client, buildName); } throw exp; } }
/** * Checks if Excpetion can be retried and if retries are left. * @param e * @param retries */ private static void checkRetryPolicy(KubernetesClientException e, int retries) { if (retries == 0) { throw new KubernetesClientException("Retries exhausted.", e); } else if (e.getCause() instanceof IOException) { LOGGER.warn("Got: {}. Retrying", e.getMessage()); } else if (e.getStatus() != null && (e.getStatus().getCode() == 500 || e.getStatus().getCode() == 503)) { LOGGER.warn("Received HTTP {} from server. Retrying", e.getStatus().getCode()); } else { throw e; } }
watch = execable.exec(getShell()); } catch (KubernetesClientException e) { if (e.getCause() instanceof InterruptedException) { throw new IOException("JENKINS-40825: interrupted while starting websocket connection", e); } else {