Search in sources :

Example 1 with KubernetesListObject

use of io.kubernetes.client.common.KubernetesListObject 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 2 with KubernetesListObject

use of io.kubernetes.client.common.KubernetesListObject in project java by kubernetes-client.

the class DynamicKubernetesTypeAdaptorFactoryTest method testListDynamicObjectRoundTrip.

@Test
public void testListDynamicObjectRoundTrip() {
    String listJsonContent = new StringBuilder().append("{").append("\"items\":[").append(jsonContent).append("]").append("}").toString();
    KubernetesListObject dynamicListObj = gson.fromJson(listJsonContent, KubernetesListObject.class);
    assertTrue(dynamicListObj instanceof DynamicKubernetesListObject);
    assertEquals(1, dynamicListObj.getItems().size());
    String dumped = gson.toJson(dynamicListObj);
    assertEquals(listJsonContent, dumped);
}
Also used : KubernetesListObject(io.kubernetes.client.common.KubernetesListObject) Test(org.junit.Test)

Example 3 with KubernetesListObject

use of io.kubernetes.client.common.KubernetesListObject in project java by kubernetes-client.

the class KubectlCreate method execute.

@Override
public ApiType execute() throws KubectlException {
    refreshDiscovery();
    GenericKubernetesApi<ApiType, KubernetesListObject> api = getGenericApi();
    if (ModelMapper.isNamespaced(this.targetObj.getClass())) {
        String targetNamespace = namespace != null ? namespace : Strings.isNullOrEmpty(targetObj.getMetadata().getNamespace()) ? Namespaces.NAMESPACE_DEFAULT : targetObj.getMetadata().getNamespace();
        try {
            return api.create(targetNamespace, targetObj, new CreateOptions()).throwsApiException().getObject();
        } catch (ApiException e) {
            throw new KubectlException(e);
        }
    } else {
        try {
            return api.create(targetObj, new CreateOptions()).throwsApiException().getObject();
        } catch (ApiException e) {
            throw new KubectlException(e);
        }
    }
}
Also used : KubernetesListObject(io.kubernetes.client.common.KubernetesListObject) KubectlException(io.kubernetes.client.extended.kubectl.exception.KubectlException) CreateOptions(io.kubernetes.client.util.generic.options.CreateOptions) ApiException(io.kubernetes.client.openapi.ApiException)

Aggregations

KubernetesListObject (io.kubernetes.client.common.KubernetesListObject)3 KubectlException (io.kubernetes.client.extended.kubectl.exception.KubectlException)2 ApiException (io.kubernetes.client.openapi.ApiException)2 KubernetesObject (io.kubernetes.client.common.KubernetesObject)1 V1Patch (io.kubernetes.client.custom.V1Patch)1 CreateOptions (io.kubernetes.client.util.generic.options.CreateOptions)1 PatchOptions (io.kubernetes.client.util.generic.options.PatchOptions)1 Test (org.junit.Test)1