Refine search
private void revoke(ConfigMap configMap) { LOGGER.debug("Trying to revoke leadership for '{}'", candidate); try { String leaderKey = getLeaderKey(); removeConfigMapEntry(configMap, leaderKey); handleLeaderChange(null); } catch (KubernetesClientException e) { LOGGER.warn("Failure when revoking leadership for '{}': {}", candidate, e.getMessage()); } }
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 BaseClient(final OkHttpClient httpClient, Config config) throws KubernetesClientException { try { this.httpClient = httpClient; this.namespace = config.getNamespace(); this.configuration = config; this.apiVersion = config.getApiVersion(); if (config.getMasterUrl() == null) { throw new KubernetesClientException("Unknown Kubernetes master URL - " + "please set with the builder, or set with either system property \"" + Config.KUBERNETES_MASTER_SYSTEM_PROPERTY + "\"" + " or environment variable \"" + Utils.convertSystemPropertyNameToEnvVar(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY) + "\""); } this.masterUrl = new URL(config.getMasterUrl()); } catch (Exception e) { throw KubernetesClientException.launderThrowable(e); } }
public static RuntimeException launderThrowable(OperationInfo spec, Throwable cause) { if (cause instanceof KubernetesClientException) { return launderThrowable(spec, ((KubernetesClientException)cause).getStatus(), cause); } return launderThrowable(describeOperation(spec)+ " failed.", cause); }
@Override public void onClose(KubernetesClientException e) { if (e != null) { e.printStackTrace(); logger.error(e.getMessage(), e); } } })) {
public static RuntimeException launderThrowable(OperationInfo spec, Status status, Throwable cause) { StringBuilder sb = new StringBuilder(); sb.append(describeOperation(spec)+ " failed."); if (status != null && Utils.isNotNullOrEmpty(status.getMessage())) { sb.append("Reason: ").append(status.getMessage()); } return launderThrowable(sb.toString(), cause); }
@Override public Build instantiate(BuildRequest request) { try { updateApiVersion(request); URL instantiationUrl = new URL(URLUtils.join(getResourceUrl().toString(), "instantiate")); RequestBody requestBody = RequestBody.create(JSON, BaseOperation.JSON_MAPPER.writer().writeValueAsString(request)); Request.Builder requestBuilder = new Request.Builder().post(requestBody).url(instantiationUrl); return handleResponse(requestBuilder, Build.class); } catch (Exception e) { throw KubernetesClientException.launderThrowable(e); } }
@Override public URL getRootUrl() { try { return new URL(OpenShiftConfig.wrap(getConfig()).getOpenShiftUrl()); } catch (MalformedURLException e) { throw KubernetesClientException.launderThrowable(e); } }
public DefaultOpenShiftClient(final OpenShiftConfig config) throws KubernetesClientException { super(config); try { this.httpClient = clientWithOpenShiftOAuthInterceptor(this.httpClient); this.delegate = new DefaultKubernetesClient(this.httpClient, config); this.openShiftUrl = new URL(config.getOpenShiftUrl()); } catch (MalformedURLException e) { throw new KubernetesClientException("Could not create client", e); } }
public URL getRootUrl() { try { if (!Utils.isNullOrEmpty(apiGroupName)) { return new URL(URLUtils.join(config.getMasterUrl().toString(), "apis", apiGroupName, apiGroupVersion)); } return new URL(URLUtils.join(config.getMasterUrl().toString(), "api", apiGroupVersion)); } catch (MalformedURLException e) { throw KubernetesClientException.launderThrowable(e); } }
@Override public R load(URL url) { try (InputStream inputStream = url.openStream()) { return load(inputStream); } catch (IOException e) { throw KubernetesClientException.launderThrowable(e); } }
@Override public Void trigger(WebHookTrigger trigger) { try { //TODO: This needs some attention. String triggerUrl = URLUtils.join(getResourceUrl().toString(), "webhooks", secret, triggerType); RequestBody requestBody = RequestBody.create(JSON, BaseOperation.JSON_MAPPER.writer().writeValueAsBytes(trigger)); Request.Builder requestBuilder = new Request.Builder() .post(requestBody) .url(triggerUrl) .addHeader("X-Github-Event", "push"); handleResponse(requestBuilder, null); } catch (Exception e) { throw KubernetesClientException.launderThrowable(e); } return null; }
T rollUpdate(T oldObj, T newObj) { try { String namespace = oldObj.getMetadata().getNamespace(); String oldName = oldObj.getMetadata().getName(); pods().inNamespace(namespace).withName(pod.getMetadata().getName()) .edit() .editMetadata().addToLabels(DEPLOYMENT_KEY, oldDeploymentHash) .and().done(); } catch (KubernetesClientException e) { LOG.warn("Unable to add deployment key to pod: {}", e.getMessage()); String newName = newObj.getMetadata().getName(); if (newName == null || newName.equals(oldName)) { newName = newName + "-" + newDeploymentHash; throw new KubernetesClientException("Could not calculate MD5 of RC", e);
@Override public boolean replaceAddressSpace(AddressSpace addressSpace) { ConfigMap newMap = null; try { String name = getConfigMapName(addressSpace.getMetadata().getNamespace(), addressSpace.getMetadata().getName()); newMap = create(addressSpace); ConfigMap result; if (addressSpace.getMetadata().getResourceVersion() != null) { result = client.configMaps() .withName(name) .lockResourceVersion(addressSpace.getMetadata().getResourceVersion()) .replace(newMap); } else { result = client.configMaps() .withName(name) .replace(newMap); } cache.replace(newMap); return result != null; } catch (KubernetesClientException e) { if (e.getStatus().getCode() == 404) { return false; } else { throw e; } } }
@Override protected <T> String checkNamespace(T item) { String operationNs = getNamespace(); String itemNs = (item instanceof HasMetadata && ((HasMetadata)item).getMetadata() != null) ? ((HasMetadata) item).getMetadata().getNamespace() : null; if (Utils.isNullOrEmpty(operationNs) && Utils.isNullOrEmpty(itemNs)) { return null; } else if (Utils.isNullOrEmpty(itemNs)) { return operationNs; } else if (Utils.isNullOrEmpty(operationNs)) { return itemNs; } else if (itemNs.equals(operationNs)) { return itemNs; } throw new KubernetesClientException("Namespace mismatch. Item namespace:" + itemNs + ". Operation namespace:" + operationNs + "."); }
protected <T> String checkName(T item) { String operationName = getName(); String itemName = item instanceof HasMetadata ? ((HasMetadata) item).getMetadata().getName() : null; if (Utils.isNullOrEmpty(operationName) && Utils.isNullOrEmpty(itemName)) { return null; } else if (Utils.isNullOrEmpty(itemName)) { return operationName; } else if (Utils.isNullOrEmpty(operationName)) { return itemName; } else if (itemName.equals(operationName)) { return itemName; } throw new KubernetesClientException("Name mismatch. Item name:" + itemName + ". Operation name:" + operationName + "."); }
} catch (KubernetesClientException e) { String message = e.getCause() == null ? e.getMessage() : e.getCause().getMessage(); if (message.contains("\n")) { Map<String, Secret> secrets = new HashMap<>(); for (HasMetadata object : list) { checkNotNull(object.getKind(), "Environment contains object without specified kind field"); checkNotNull(object.getMetadata(), "%s metadata must not be null", object.getKind()); checkNotNull(object.getMetadata().getName(), "%s name must not be null", object.getKind()); } else if (object instanceof Pod) { Pod pod = (Pod) object; pods.put(pod.getMetadata().getName(), pod); } else if (object instanceof Deployment) { Deployment deployment = (Deployment) object; deployments.put(deployment.getMetadata().getName(), deployment); } else if (object instanceof Service) { Service service = (Service) object;
public KubernetesList processLocally(Map<String, String> valuesMap) { String namespace = getItem() != null ? getItem().getMetadata().getNamespace() : getNamespace(); if (namespace == null) { namespace = getConfig().getNamespace(); String name = getItem() != null ? getItem().getMetadata().getName() : getName(); if (valuesMap.containsKey(parameterName)) { parameterValue = valuesMap.get(parameterName); } else if (Utils.isNotNullOrEmpty(parameter.getValue())) { parameterValue = parameter.getValue(); } else if (EXPRESSION.equals(parameter.getGenerate())) { throw KubernetesClientException.launderThrowable(e);
NonNamespaceOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> pods = client.pods().inNamespace(namespace); Pod result = pods.create(pod); System.out.println("Created pod " + result.getMetadata().getName()); } else { System.err.println("Loaded resource is not a Pod! " + resource); logger.error(e.getMessage(), e); } catch (Exception e) { logger.error(e.getMessage(), e);
for (HasMetadata meta : acceptVisitors(asHasMetadata(item, true), visitors)) { ResourceHandler<HasMetadata, HasMetadataVisitiableBuilder> h = handlerOf(meta); HasMetadata r = h.reload(client, config, meta.getMetadata().getNamespace(), meta); String namespaceToUse = meta.getMetadata().getNamespace(); Boolean deleted = h.delete(client, config, namespaceToUse, meta); if (!deleted) { throw new KubernetesClientException("Failed to delete existing item:" + meta);