use of io.kubernetes.client.custom.V1Patch in project java by kubernetes-client.
the class GenericKubernetesApiTest method patchNamespacedJobReturningObject.
@Test
public void patchNamespacedJobReturningObject() {
V1Patch v1Patch = new V1Patch("{}");
V1Job foo1 = new V1Job().kind("Job").metadata(new V1ObjectMeta().namespace("default").name("foo1"));
stubFor(patch(urlEqualTo("/apis/batch/v1/namespaces/default/jobs/foo1")).withHeader("Content-Type", containing(V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH)).willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
KubernetesApiResponse<V1Job> jobPatchResp = jobClient.patch("default", "foo1", V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, v1Patch);
assertTrue(jobPatchResp.isSuccess());
assertEquals(foo1, jobPatchResp.getObject());
assertNull(jobPatchResp.getStatus());
verify(1, patchRequestedFor(urlPathEqualTo("/apis/batch/v1/namespaces/default/jobs/foo1")));
}
use of io.kubernetes.client.custom.V1Patch in project java by kubernetes-client.
the class PatchUtilsTest method testStrategicMergePatchPod.
@Test
public void testStrategicMergePatchPod() throws ApiException {
CoreV1Api coreV1Api = new CoreV1Api(client);
stubFor(patch(urlPathEqualTo("/api/v1/namespaces/default/pods/foo")).withHeader("Content-Type", containing(V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH)).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody("{}")));
PatchUtils.patch(V1Pod.class, () -> coreV1Api.patchNamespacedPodCall("foo", "default", new V1Patch("[]"), null, null, null, null, null, null), V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, client);
verify(1, patchRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/pods/foo")));
}
use of io.kubernetes.client.custom.V1Patch in project java by kubernetes-client.
the class KubectlScale method execute.
@Override
public ApiType execute() throws KubectlException {
validate();
String jsonPatchStr = String.format("[{\"op\":\"replace\",\"path\":\"/spec/replicas\",\"value\":%d}]", replicas);
AppsV1Api api = new AppsV1Api(this.apiClient);
try {
if (apiTypeClass.equals(V1Deployment.class)) {
return PatchUtils.patch(apiTypeClass, () -> api.patchNamespacedDeploymentCall(name, namespace, new V1Patch(jsonPatchStr), null, null, null, // field-manager is optional
null, null, null), V1Patch.PATCH_FORMAT_JSON_PATCH, this.apiClient);
} else if (apiTypeClass.equals(V1ReplicaSet.class)) {
return PatchUtils.patch(apiTypeClass, () -> api.patchNamespacedReplicaSetCall(name, namespace, new V1Patch(jsonPatchStr), null, null, null, null, null, null), V1Patch.PATCH_FORMAT_JSON_PATCH, this.apiClient);
} else if (apiTypeClass.equals(V1StatefulSet.class)) {
return PatchUtils.patch(apiTypeClass, () -> api.patchNamespacedStatefulSetCall(name, namespace, new V1Patch(jsonPatchStr), null, null, null, null, null, null), V1Patch.PATCH_FORMAT_JSON_PATCH, this.apiClient);
} else {
throw new KubectlException("Unsupported class for scale: " + apiTypeClass);
}
} catch (ApiException ex) {
throw new KubectlException(ex);
}
}
use of io.kubernetes.client.custom.V1Patch in project java by kubernetes-client.
the class LegacyEventBroadcaster method recordToSink.
private void recordToSink(CoreV1Event event) throws InterruptedException {
Optional<MutablePair<CoreV1Event, V1Patch>> eventAndPatch = this.eventCorrelator.correlate(event);
if (!eventAndPatch.isPresent()) {
// skip
return;
}
CoreV1Event recordingEvent = eventAndPatch.get().getLeft();
V1Patch patch = eventAndPatch.get().getRight();
for (int retries = 0; retries < maxTriesPerEvent; retries++) {
if (recordEvent(recordingEvent, patch, event.getCount() > 1)) {
break;
}
Thread.sleep(sleepDuration.toMillis());
}
}
Aggregations