Search in sources :

Example 1 with PatchOptions

use of io.kubernetes.client.util.generic.options.PatchOptions 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 PatchOptions

use of io.kubernetes.client.util.generic.options.PatchOptions in project java by kubernetes-client.

the class PatchHelper method dryRunStrategyMergePatch.

public static <ApiType extends KubernetesObject, ApiListType extends KubernetesListObject> ApiType dryRunStrategyMergePatch(GenericKubernetesApi<ApiType, ApiListType> genericApi, String patch, String namespace, String name) throws ApiException {
    PatchOptions options = new PatchOptions();
    options.setDryRun("All");
    return genericApi.patch(namespace, name, V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, new V1Patch(patch), options).throwsApiException().getObject();
}
Also used : PatchOptions(io.kubernetes.client.util.generic.options.PatchOptions) V1Patch(io.kubernetes.client.custom.V1Patch)

Aggregations

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