use of io.kubernetes.client.custom.V1Patch in project java by kubernetes-client.
the class EventLoggerTest method testPatchComputing.
@Test
public void testPatchComputing() {
CoreV1Event event1 = new CoreV1EventBuilder().withSource(new V1EventSourceBuilder().build()).withMetadata(new V1ObjectMeta()).withInvolvedObject(new V1ObjectReferenceBuilder().build()).withCount(1).withMessage("foo1").build();
CoreV1Event event2 = new CoreV1EventBuilder().withSource(new V1EventSourceBuilder().build()).withMetadata(new V1ObjectMeta()).withInvolvedObject(new V1ObjectReferenceBuilder().build()).withCount(2).withMessage("foo2").build();
String aggregatedKey = EventUtils.getAggregatedAndLocalKeyByReason(event1).getRight();
EventLogger eventLogger = new EventLogger(100, EventUtils::getEventKey);
MutablePair<CoreV1Event, V1Patch> result1 = eventLogger.observe(event1, aggregatedKey);
assertEquals(event1, result1.getLeft());
assertNull(result1.getRight());
MutablePair<CoreV1Event, V1Patch> result2 = eventLogger.observe(event2, aggregatedKey);
assertEquals(event2, result2.getLeft());
assertNotNull(result2.getRight());
}
use of io.kubernetes.client.custom.V1Patch 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.custom.V1Patch 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();
}
use of io.kubernetes.client.custom.V1Patch in project java by kubernetes-client.
the class GenericKubernetesApiForCoreApiTest method patchNamespacedPodReturningObject.
@Test
public void patchNamespacedPodReturningObject() {
V1Patch v1Patch = new V1Patch("{}");
V1Pod foo1 = new V1Pod().kind("Pod").metadata(new V1ObjectMeta().namespace("default").name("foo1"));
stubFor(patch(urlEqualTo("/api/v1/namespaces/default/pods/foo1")).withHeader("Content-Type", containing(V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH)).willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
KubernetesApiResponse<V1Pod> podPatchResp = podClient.patch("default", "foo1", V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, v1Patch);
assertTrue(podPatchResp.isSuccess());
assertEquals(foo1, podPatchResp.getObject());
assertNull(podPatchResp.getStatus());
verify(1, patchRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/pods/foo1")));
}
use of io.kubernetes.client.custom.V1Patch in project java by kubernetes-client.
the class GenericKubernetesApiForCoreApiTest method patchNamespacedPodWithApiPrefix.
@Test
public void patchNamespacedPodWithApiPrefix() {
V1Patch v1Patch = new V1Patch("{}");
V1Pod foo1 = new V1Pod().kind("Pod").metadata(new V1ObjectMeta().namespace("default").name("foo1"));
// add api prefix
String prefix = "/k8s/clusters/c-7q988";
stubFor(patch(urlEqualTo(prefix + "/api/v1/namespaces/default/pods/foo1")).withHeader("Content-Type", containing(V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH)).willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
GenericKubernetesApi<V1Pod, V1PodList> rancherPodClient = new GenericKubernetesApi<>(V1Pod.class, V1PodList.class, "", "v1", "pods", new ClientBuilder().setBasePath("http://localhost:" + 8181 + prefix).build());
KubernetesApiResponse<V1Pod> podPatchResp = rancherPodClient.patch("default", "foo1", V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, v1Patch);
assertTrue(podPatchResp.isSuccess());
assertEquals(foo1, podPatchResp.getObject());
assertNull(podPatchResp.getStatus());
verify(1, patchRequestedFor(urlPathEqualTo(prefix + "/api/v1/namespaces/default/pods/foo1")));
}
Aggregations