Search in sources :

Example 16 with V1Patch

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")));
}
Also used : V1Job(io.kubernetes.client.openapi.models.V1Job) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Patch(io.kubernetes.client.custom.V1Patch) Test(org.junit.Test)

Example 17 with V1Patch

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")));
}
Also used : V1Patch(io.kubernetes.client.custom.V1Patch) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) Test(org.junit.Test)

Example 18 with V1Patch

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);
    }
}
Also used : AppsV1Api(io.kubernetes.client.openapi.apis.AppsV1Api) V1Patch(io.kubernetes.client.custom.V1Patch) KubectlException(io.kubernetes.client.extended.kubectl.exception.KubectlException) V1ReplicaSet(io.kubernetes.client.openapi.models.V1ReplicaSet) ApiException(io.kubernetes.client.openapi.ApiException)

Example 19 with V1Patch

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());
    }
}
Also used : MutablePair(org.apache.commons.lang3.tuple.MutablePair) V1Patch(io.kubernetes.client.custom.V1Patch) CoreV1Event(io.kubernetes.client.openapi.models.CoreV1Event)

Aggregations

V1Patch (io.kubernetes.client.custom.V1Patch)19 Test (org.junit.Test)9 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)6 ApiException (io.kubernetes.client.openapi.ApiException)4 AppsV1Api (io.kubernetes.client.openapi.apis.AppsV1Api)3 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)3 CoreV1Event (io.kubernetes.client.openapi.models.CoreV1Event)3 V1Pod (io.kubernetes.client.openapi.models.V1Pod)3 KubectlException (io.kubernetes.client.extended.kubectl.exception.KubectlException)2 ApiClient (io.kubernetes.client.openapi.ApiClient)2 V1Container (io.kubernetes.client.openapi.models.V1Container)2 V1Deployment (io.kubernetes.client.openapi.models.V1Deployment)2 V1PodList (io.kubernetes.client.openapi.models.V1PodList)2 V1PodSpec (io.kubernetes.client.openapi.models.V1PodSpec)2 PatchOptions (io.kubernetes.client.util.generic.options.PatchOptions)2 OffsetDateTime (java.time.OffsetDateTime)2 MutablePair (org.apache.commons.lang3.tuple.MutablePair)2 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)1 KubernetesListObject (io.kubernetes.client.common.KubernetesListObject)1 KubernetesObject (io.kubernetes.client.common.KubernetesObject)1