Search in sources :

Example 1 with KubectlException

use of io.kubernetes.client.extended.kubectl.exception.KubectlException in project java by kubernetes-client.

the class KubectlReplace method execute.

@Override
public ApiType execute() throws KubectlException {
    verifyArguments();
    refreshDiscovery();
    if (isNamespaced(apiTypeClass)) {
        try {
            return getGenericApi().update(updateObject, options).throwsApiException().getObject();
        } catch (ApiException e) {
            throw new KubectlException(e);
        }
    } else {
        try {
            return getGenericApi().update(updateObject, options).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 2 with KubectlException

use of io.kubernetes.client.extended.kubectl.exception.KubectlException in project java by kubernetes-client.

the class KubectlGet method execute.

@Override
public List<ApiType> execute() throws KubectlException {
    refreshDiscovery();
    GenericKubernetesApi<ApiType, ? extends KubernetesListObject> api = apiTypeListClass == null ? getGenericApi(apiTypeClass) : getGenericApi(apiTypeClass, apiTypeListClass);
    try {
        if (isNamespaced()) {
            return (List<ApiType>) api.list(namespace, listOptions).throwsApiException().getObject().getItems();
        } else {
            return (List<ApiType>) api.list(listOptions).throwsApiException().getObject().getItems();
        }
    } catch (ApiException e) {
        throw new KubectlException(e);
    }
}
Also used : List(java.util.List) KubectlException(io.kubernetes.client.extended.kubectl.exception.KubectlException) ApiException(io.kubernetes.client.openapi.ApiException)

Example 3 with KubectlException

use of io.kubernetes.client.extended.kubectl.exception.KubectlException in project java by kubernetes-client.

the class KubectlPortForward method executeInternal.

private void executeInternal() throws ApiException, KubectlException, IOException, InterruptedException {
    PortForward pf = new PortForward(apiClient);
    PortForward.PortForwardResult result = pf.forward(namespace, name, targetPorts);
    if (result == null) {
        throw new KubectlException("PortForward failed!");
    }
    // TODO: Convert this to NIO to reduce the number of threads?
    List<Thread> threads = new ArrayList<>();
    for (int i = 0; i < localPorts.size(); i++) {
        int targetPort = targetPorts.get(i);
        threads.add(portForward(new ServerSocket(localPorts.get(i)), result.getInputStream(targetPort), result.getOutboundStream(targetPort)));
    }
    for (Thread t : threads) {
        t.join();
    }
}
Also used : ArrayList(java.util.ArrayList) PortForward(io.kubernetes.client.PortForward) ServerSocket(java.net.ServerSocket) KubectlException(io.kubernetes.client.extended.kubectl.exception.KubectlException)

Example 4 with KubectlException

use of io.kubernetes.client.extended.kubectl.exception.KubectlException in project java by kubernetes-client.

the class KubectlApply method executeServerSideApply.

private ApiType executeServerSideApply() throws KubectlException {
    refreshDiscovery();
    GenericKubernetesApi<ApiType, KubernetesListObject> api = getGenericApi();
    PatchOptions patchOptions = new PatchOptions();
    patchOptions.setForce(this.forceConflict);
    patchOptions.setFieldManager(this.fieldManager);
    if (ModelMapper.isNamespaced(this.targetObj.getClass())) {
        String targetNamespace = namespace != null ? namespace : Strings.isNullOrEmpty(targetObj.getMetadata().getNamespace()) ? Namespaces.NAMESPACE_DEFAULT : targetObj.getMetadata().getNamespace();
        KubernetesApiResponse<KubernetesObject> response = null;
        try {
            return api.patch(targetNamespace, targetObj.getMetadata().getName(), V1Patch.PATCH_FORMAT_APPLY_YAML, new V1Patch(apiClient.getJSON().serialize(targetObj)), patchOptions).throwsApiException().getObject();
        } catch (ApiException e) {
            throw new KubectlException(e);
        }
    } else {
        try {
            return api.patch(targetObj.getMetadata().getName(), V1Patch.PATCH_FORMAT_APPLY_YAML, new V1Patch(apiClient.getJSON().serialize(targetObj)), patchOptions).throwsApiException().getObject();
        } catch (ApiException e) {
            throw new KubectlException(e);
        }
    }
}
Also used : KubernetesListObject(io.kubernetes.client.common.KubernetesListObject) PatchOptions(io.kubernetes.client.util.generic.options.PatchOptions) KubernetesObject(io.kubernetes.client.common.KubernetesObject) V1Patch(io.kubernetes.client.custom.V1Patch) KubectlException(io.kubernetes.client.extended.kubectl.exception.KubectlException) ApiException(io.kubernetes.client.openapi.ApiException)

Example 5 with KubectlException

use of io.kubernetes.client.extended.kubectl.exception.KubectlException in project java by kubernetes-client.

the class KubectlExec method execute.

@Override
public Integer execute() throws KubectlException {
    V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().name(name).namespace(namespace));
    Exec exec = new Exec(apiClient);
    try {
        Process proc = exec.exec(pod, command, container, stdin, tty);
        copyAsync(proc.getInputStream(), System.out);
        copyAsync(proc.getErrorStream(), System.err);
        if (stdin) {
            copyAsync(System.in, proc.getOutputStream());
        }
        return proc.waitFor();
    } catch (InterruptedException | ApiException | IOException ex) {
        throw new KubectlException(ex);
    }
}
Also used : Exec(io.kubernetes.client.Exec) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Pod(io.kubernetes.client.openapi.models.V1Pod) IOException(java.io.IOException) KubectlException(io.kubernetes.client.extended.kubectl.exception.KubectlException) 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