Search in sources :

Example 11 with KubectlException

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);
    }
}
Also used : Copy(io.kubernetes.client.Copy) IOException(java.io.IOException) KubectlException(io.kubernetes.client.extended.kubectl.exception.KubectlException) CopyNotSupportedException(io.kubernetes.client.util.exception.CopyNotSupportedException) ApiException(io.kubernetes.client.openapi.ApiException)

Example 12 with KubectlException

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);
        }
    }
}
Also used : KubectlException(io.kubernetes.client.extended.kubectl.exception.KubectlException) ApiException(io.kubernetes.client.openapi.ApiException)

Example 13 with KubectlException

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);
    }
}
Also used : GenericKubernetesApi(io.kubernetes.client.util.generic.GenericKubernetesApi) KubectlException(io.kubernetes.client.extended.kubectl.exception.KubectlException) ApiException(io.kubernetes.client.openapi.ApiException)

Example 14 with KubectlException

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);
    }
}
Also used : AppsV1Api(io.kubernetes.client.openapi.apis.AppsV1Api) V1Patch(io.kubernetes.client.custom.V1Patch) KubectlException(io.kubernetes.client.extended.kubectl.exception.KubectlException) V1ReplicaSet(io.kubernetes.client.openapi.models.V1ReplicaSet) ApiException(io.kubernetes.client.openapi.ApiException)

Example 15 with KubectlException

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);
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) KubernetesObject(io.kubernetes.client.common.KubernetesObject) KubectlException(io.kubernetes.client.extended.kubectl.exception.KubectlException) KubectlCreate(io.kubernetes.client.spring.extended.manifests.annotation.KubectlCreate) ApiException(io.kubernetes.client.openapi.ApiException)

Aggregations

KubectlException (io.kubernetes.client.extended.kubectl.exception.KubectlException)16 ApiException (io.kubernetes.client.openapi.ApiException)14 KubernetesObject (io.kubernetes.client.common.KubernetesObject)3 IOException (java.io.IOException)3 KubernetesListObject (io.kubernetes.client.common.KubernetesListObject)2 V1Patch (io.kubernetes.client.custom.V1Patch)2 V1Pod (io.kubernetes.client.openapi.models.V1Pod)2 BeanCreationException (org.springframework.beans.factory.BeanCreationException)2 Copy (io.kubernetes.client.Copy)1 Exec (io.kubernetes.client.Exec)1 PodLogs (io.kubernetes.client.PodLogs)1 PortForward (io.kubernetes.client.PortForward)1 AppsV1Api (io.kubernetes.client.openapi.apis.AppsV1Api)1 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)1 V1ReplicaSet (io.kubernetes.client.openapi.models.V1ReplicaSet)1 V1Status (io.kubernetes.client.openapi.models.V1Status)1 KubectlApply (io.kubernetes.client.spring.extended.manifests.annotation.KubectlApply)1 KubectlCreate (io.kubernetes.client.spring.extended.manifests.annotation.KubectlCreate)1 CopyNotSupportedException (io.kubernetes.client.util.exception.CopyNotSupportedException)1 GenericKubernetesApi (io.kubernetes.client.util.generic.GenericKubernetesApi)1