Search in sources :

Example 21 with ApiException

use of io.kubernetes.client.openapi.ApiException 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 22 with ApiException

use of io.kubernetes.client.openapi.ApiException 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)

Example 23 with ApiException

use of io.kubernetes.client.openapi.ApiException in project java by kubernetes-client.

the class KubectlLabel method execute.

@Override
public ApiType execute() throws KubectlException {
    verifyArguments();
    refreshDiscovery();
    final ApiType currentObj;
    if (isNamespaced(apiTypeClass)) {
        try {
            currentObj = getGenericApi().get(namespace, name).throwsApiException().getObject();
        } catch (ApiException e) {
            throw new KubectlException(e);
        }
    } else {
        try {
            currentObj = getGenericApi().get(name).throwsApiException().getObject();
        } catch (ApiException e) {
            throw new KubectlException(e);
        }
    }
    Labels.addLabels(currentObj, addingLabels);
    try {
        return getGenericApi().update(currentObj).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 24 with ApiException

use of io.kubernetes.client.openapi.ApiException 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 25 with ApiException

use of io.kubernetes.client.openapi.ApiException 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)

Aggregations

ApiException (io.kubernetes.client.openapi.ApiException)82 V1Pod (io.kubernetes.client.openapi.models.V1Pod)21 IOException (java.io.IOException)21 V1PodList (io.kubernetes.client.openapi.models.V1PodList)18 Test (org.junit.Test)18 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)17 KubectlException (io.kubernetes.client.extended.kubectl.exception.KubectlException)14 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)13 ApiClient (io.kubernetes.client.openapi.ApiClient)10 AppsV1Api (io.kubernetes.client.openapi.apis.AppsV1Api)10 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)8 V1Deployment (io.kubernetes.client.openapi.models.V1Deployment)8 V1ListMeta (io.kubernetes.client.openapi.models.V1ListMeta)8 V1Status (io.kubernetes.client.openapi.models.V1Status)8 CallGeneratorParams (io.kubernetes.client.util.CallGeneratorParams)8 Watch (io.kubernetes.client.util.Watch)8 List (java.util.List)8 Configuration (io.kubernetes.client.openapi.Configuration)6 HashMap (java.util.HashMap)6 V1Patch (io.kubernetes.client.custom.V1Patch)5