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);
}
}
}
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);
}
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);
}
}
}
Aggregations