public RootPaths getRootPaths() { try { URL requestUrl = new URL(config.getMasterUrl()); Request.Builder req = new Request.Builder().get().url(requestUrl); return handleResponse(req, RootPaths.class); } catch (KubernetesClientException e) { if (e.getCode() != 404) { throw e; } return null; } catch (InterruptedException | ExecutionException | IOException e) { throw KubernetesClientException.launderThrowable(e); } }
public void run() { try { T res = resources().inNamespace(namespace).withName(name).get(); if (res == null) { countDownLatch.countDown(); } } catch (KubernetesClientException e) { if (e.getCode() == 404) { countDownLatch.countDown(); } } } };
@Override public T get() { try { T answer = getMandatory(); if (answer instanceof HasMetadata) { HasMetadata hasMetadata = (HasMetadata) answer; updateApiVersion(hasMetadata); } else if (answer instanceof KubernetesResourceList) { KubernetesResourceList list = (KubernetesResourceList) answer; updateApiVersion(list); } return answer; } catch (KubernetesClientException e) { if (e.getCode() != 404) { throw e; } return null; } }
caught = e; if (e.getCode() != 409) { break;
@Override public Boolean delete(List<T> items) { boolean deleted = true; if (items != null) { for (T item : items) { updateApiVersionResource(item); try { R op = createItemOperation(item); deleted &= op.delete(); } catch (KubernetesClientException e) { if (e.getCode() != 404) { throw e; } return false; } catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) { throw KubernetesClientException.launderThrowable(forOperationType("delete"), e); } } } return deleted; }
caught = e; if (e.getCode() != 409 || fixedResourceVersion != null) { break;
@Override public String getURL(Service service, String portName, String namespace, KubernetesClient client) { String serviceName = service.getMetadata().getName(); ServicePort port = URLFromServiceUtil.getServicePortByName(service, portName); if(port != null && port.getName() != null && isOpenShift(client)) { try { String serviceProtocol = port.getProtocol(); OpenShiftClient openShiftClient = client.adapt(OpenShiftClient.class); Route route = openShiftClient.routes().inNamespace(namespace).withName(service.getMetadata().getName()).get(); if (route != null) { return (serviceProtocol + "://" + route.getSpec().getHost()).toLowerCase(); } } catch (KubernetesClientException e) { if(e.getCode() == HttpURLConnection.HTTP_FORBIDDEN) { logger.warn("Could not lookup route:" + serviceName + " in namespace:"+ namespace +", due to: " + e.getMessage()); } } } return null; }
} catch (KubernetesClientException ke) { if (ke.getCode() != 200) { if(watch != null){
public RootPaths getRootPaths() { try { URL requestUrl = new URL(config.getMasterUrl()); Request.Builder req = new Request.Builder().get().url(requestUrl); return handleResponse(req, RootPaths.class); } catch (KubernetesClientException e) { if (e.getCode() != 404) { throw e; } return null; } catch (InterruptedException | ExecutionException | IOException e) { throw KubernetesClientException.launderThrowable(e); } }
public void run() { try { T res = resources().inNamespace(namespace).withName(name).get(); if (res == null) { countDownLatch.countDown(); } } catch (KubernetesClientException e) { if (e.getCode() == 404) { countDownLatch.countDown(); } } } };
@VisibleForTesting void doRemoveProject(String projectName) throws InfrastructureException { try { clientFactory.createOC(projectName).projects().withName(projectName).delete(); } catch (KubernetesClientException e) { if (!(e.getCode() == 403)) { throw new KubernetesInfrastructureException(e); } // project doesn't exist } } }
private Project get(String projectName, OpenShiftClient client) throws InfrastructureException { try { return client.projects().withName(projectName).get(); } catch (KubernetesClientException e) { if (e.getCode() == 403) { // project is foreign or doesn't exist return null; } else { throw new KubernetesInfrastructureException(e); } } } }
private void deleteSecret(Secret secret) { LOG.info("[AUDIT] Deleting service account {} secret {}", serviceAccount(secret), secret.getMetadata().getName()); try { client.secrets().delete(secret); } catch (KubernetesClientException e) { if (e.getCode() == 404) { LOG.debug("Couldn't find secret to delete {}", secret.getMetadata().getName()); } else { LOG.warn("[AUDIT] Failed to delete secret {}", secret.getMetadata().getName()); throw e; } } }
@Override public void onClose(KubernetesClientException cause) { if (cause != null) { log.error("Error while watching for build to finish: %s [%d]", cause.getMessage(), cause.getCode()); Status status = cause.getStatus(); if (status != null) { log.error("%s [%s]", status.getReason(), status.getStatus()); } } latch.countDown(); } };
private void reportDockerOperationError(String operation, long durationMillis, Throwable e, Stats stats) { final KubernetesClientException kubernetesClientException = findCause(e, KubernetesClientException.class); if (kubernetesClientException != null) { final String type = (kubernetesClientException instanceof KubernetesClientTimeoutException) ? "kubernetes-client-timeout" : "kubernetes-client"; stats.recordDockerOperationError(operation, type, kubernetesClientException.getCode(), durationMillis); } else { final InvalidExecutionException invalidExecutionException = findCause(e, InvalidExecutionException.class); if (invalidExecutionException != null) { stats.recordDockerOperationError(operation, "invalid-execution", 0, durationMillis); } else { stats.recordDockerOperationError(operation, "unknown", 0, durationMillis); } } } }
public void restartPod(String podName) throws ApolloKubernetesException { // Deleting a pod, which created with a deployment is basically restarting since the replica set will create a new one immediately try { kubernetesClient .pods() .inNamespace(environment.getKubernetesNamespace()) .withName(podName) .delete(); } catch (KubernetesClientException e) { // Async deletion throws KubernetesClientException with code 202, but it's working and actually deleting the pod if (e.getCode() != HttpStatus.ACCEPTED) { throw new ApolloKubernetesException(); } } }
@Override public StateUpdate execute(IntegrationDeployment integrationDeployment) { try { openShiftService().scale(integrationDeployment.getName(), 0); logInfo(integrationDeployment,"Deactivated"); } catch (KubernetesClientException e) { // Ignore 404 errors, means the deployment does not exist for us // to scale down if( e.getCode() != 404 ) { throw e; } } IntegrationDeploymentState currentState = openShiftService().isScaled(integrationDeployment.getName(), 0) ? IntegrationDeploymentState.Inactive : IntegrationDeploymentState.Pending; return new StateUpdate(currentState); }
@Override public Boolean delete(List<T> items) { boolean deleted = true; if (items != null) { for (T item : items) { try { R op = (R) getClass() .getConstructor(OkHttpClient.class, getConfigType(), String.class, String.class, String.class, Boolean.class, getType(), String.class, Boolean.class, long.class, Map.class, Map.class, Map.class, Map.class, Map.class) .newInstance(client, getConfig(), getAPIVersion(), getNamespace(), getName(), isCascading(), item, getResourceVersion(), true, getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); deleted &= op.delete(); } catch (KubernetesClientException e) { if (e.getCode() != 404) { throw e; } return false; } catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) { throw KubernetesClientException.launderThrowable(e); } } } return deleted; }
@Override public String getURL(Service service, String portName, String namespace, KubernetesClient client) { String serviceName = service.getMetadata().getName(); ServicePort port = URLFromServiceUtil.getServicePortByName(service, portName); if(port != null && port.getName() != null && isOpenShift(client)) { try { String serviceProtocol = port.getProtocol(); OpenShiftClient openShiftClient = client.adapt(OpenShiftClient.class); Route route = openShiftClient.routes().inNamespace(namespace).withName(service.getMetadata().getName()).get(); if (route != null) { return (serviceProtocol + "://" + route.getSpec().getHost()).toLowerCase(); } } catch (KubernetesClientException e) { if(e.getCode() == HttpURLConnection.HTTP_FORBIDDEN) { logger.warn("Could not lookup route:" + serviceName + " in namespace:"+ namespace +", due to: " + e.getMessage()); } } } return null; }