use of io.kubernetes.client.extended.kubectl.exception.KubectlException in project java by kubernetes-client.
the class KubectlCopy method execute.
@Override
public Boolean execute() throws KubectlException {
validate();
Copy cp = new Copy(apiClient);
try {
if (toPod) {
cp.copyFileToPod(namespace, name, container, Paths.get(from), Paths.get(to));
} else {
if (this.dir) {
cp.copyDirectoryFromPod(namespace, name, container, from, Paths.get(to));
} else {
cp.copyFileFromPod(namespace, name, container, from, Paths.get(to));
}
}
return true;
} catch (ApiException | IOException | CopyNotSupportedException ex) {
throw new KubectlException(ex);
}
}
use of io.kubernetes.client.extended.kubectl.exception.KubectlException in project java by kubernetes-client.
the class KubectlDelete method execute.
@Override
public ApiType execute() throws KubectlException {
verifyArguments();
refreshDiscovery();
if (isNamespaced(apiTypeClass)) {
try {
return getGenericApi().delete(namespace, name).throwsApiException().getObject();
} catch (ApiException e) {
throw new KubectlException(e);
}
} else {
try {
return getGenericApi().delete(name).throwsApiException().getObject();
} catch (ApiException e) {
throw new KubectlException(e);
}
}
}
use of io.kubernetes.client.extended.kubectl.exception.KubectlException in project java by kubernetes-client.
the class KubectlPatch method execute.
@Override
public ApiType execute() throws KubectlException {
refreshDiscovery();
GenericKubernetesApi genericKubernetesApi = getGenericApi();
try {
if (ModelMapper.isNamespaced(apiTypeClass)) {
return (ApiType) genericKubernetesApi.patch(namespace, name, patchType, patchContent).throwsApiException().getObject();
} else {
return (ApiType) genericKubernetesApi.patch(name, patchType, patchContent).throwsApiException().getObject();
}
} catch (ApiException e) {
throw new KubectlException(e);
}
}
use of io.kubernetes.client.extended.kubectl.exception.KubectlException in project java by kubernetes-client.
the class KubectlScale method execute.
@Override
public ApiType execute() throws KubectlException {
validate();
String jsonPatchStr = String.format("[{\"op\":\"replace\",\"path\":\"/spec/replicas\",\"value\":%d}]", replicas);
AppsV1Api api = new AppsV1Api(this.apiClient);
try {
if (apiTypeClass.equals(V1Deployment.class)) {
return PatchUtils.patch(apiTypeClass, () -> api.patchNamespacedDeploymentCall(name, namespace, new V1Patch(jsonPatchStr), null, null, null, // field-manager is optional
null, null, null), V1Patch.PATCH_FORMAT_JSON_PATCH, this.apiClient);
} else if (apiTypeClass.equals(V1ReplicaSet.class)) {
return PatchUtils.patch(apiTypeClass, () -> api.patchNamespacedReplicaSetCall(name, namespace, new V1Patch(jsonPatchStr), null, null, null, null, null, null), V1Patch.PATCH_FORMAT_JSON_PATCH, this.apiClient);
} else if (apiTypeClass.equals(V1StatefulSet.class)) {
return PatchUtils.patch(apiTypeClass, () -> api.patchNamespacedStatefulSetCall(name, namespace, new V1Patch(jsonPatchStr), null, null, null, null, null, null), V1Patch.PATCH_FORMAT_JSON_PATCH, this.apiClient);
} else {
throw new KubectlException("Unsupported class for scale: " + apiTypeClass);
}
} catch (ApiException ex) {
throw new KubectlException(ex);
}
}
use of io.kubernetes.client.extended.kubectl.exception.KubectlException in project java by kubernetes-client.
the class KubernetesKubectlCreateProcessor method postProcessAfterInitialization.
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (!(bean instanceof KubernetesObject)) {
// no-op
return bean;
}
KubectlCreate create = beanFactory.findAnnotationOnBean(beanName, KubectlCreate.class);
if (create == null) {
return bean;
}
Class<? extends KubernetesObject> apiTypeClass = (Class<? extends KubernetesObject>) bean.getClass();
try {
log.info("@KubectlCreate ensuring resource upon bean {}", beanName);
return create(apiTypeClass, bean);
} catch (KubectlException e) {
if (e.getCause() instanceof ApiException) {
ApiException apiException = (ApiException) e.getCause();
if (HttpURLConnection.HTTP_CONFLICT == apiException.getCode()) {
// already exists
log.info("Skipped processing {} @KubectlCreate resource already exists", beanName);
return bean;
}
}
log.error("Failed ensuring resource from @KubectlCreate", e);
throw new BeanCreationException("Failed ensuring resource from @KubectlCreate", e);
}
}
Aggregations