Search in sources :

Example 11 with V1Patch

use of io.kubernetes.client.custom.V1Patch in project heron by twitter.

the class V1Controller method patchStatefulSetReplicas.

/**
 * Performs an in-place update of the replica count for a <code>topology</code>. This allows the
 * <code>topology</code> Pod count to be scaled up or down.
 * @param replicas The new number of Pod replicas required.
 * @throws ApiException in the event there is a failure patching the StatefulSet.
 */
private void patchStatefulSetReplicas(int replicas) throws ApiException {
    final String body = String.format(KubernetesConstants.JSON_PATCH_STATEFUL_SET_REPLICAS_FORMAT, replicas);
    final V1Patch patch = new V1Patch(body);
    PatchUtils.patch(V1StatefulSet.class, () -> appsClient.patchNamespacedStatefulSetCall(getStatefulSetName(true), getNamespace(), patch, null, null, null, null, null), V1Patch.PATCH_FORMAT_JSON_PATCH, appsClient.getApiClient());
}
Also used : V1Patch(io.kubernetes.client.custom.V1Patch)

Example 12 with V1Patch

use of io.kubernetes.client.custom.V1Patch in project java by kubernetes-client.

the class EventLoggerTest method buildEventPatch.

@Test
public void buildEventPatch() {
    String expectedStr = "2021-03-02T15:02:48.179000Z";
    OffsetDateTime expected = OffsetDateTime.parse("2021-03-02T15:02:48.179000Z");
    V1Patch patch = EventLogger.buildEventPatch(1, "foo", expected);
    assertEquals("{\"message\":\"foo\",\"count\":1,\"lastTimestamp\":\"" + expectedStr + "\"}", patch.getValue());
}
Also used : OffsetDateTime(java.time.OffsetDateTime) V1Patch(io.kubernetes.client.custom.V1Patch) Test(org.junit.Test)

Example 13 with V1Patch

use of io.kubernetes.client.custom.V1Patch in project java by kubernetes-client.

the class KubectlPatchTest method testPatchConfigMap.

@Test
public void testPatchConfigMap() throws KubectlException, IOException {
    wireMockRule.stubFor(patch(urlPathEqualTo("/api/v1/namespaces/foo/configmaps/bar")).withHeader("Content-Type", new EqualToPattern(V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH)).willReturn(aResponse().withStatus(200).withBody("{\"metadata\":{\"name\":\"bar\",\"namespace\":\"foo\"}}")));
    wireMockRule.stubFor(get(urlPathEqualTo("/api")).willReturn(aResponse().withStatus(200).withBody(new String(Files.readAllBytes(Paths.get(DISCOVERY_API))))));
    wireMockRule.stubFor(get(urlPathEqualTo("/apis")).willReturn(aResponse().withStatus(200).withBody(new String(Files.readAllBytes(Paths.get(DISCOVERY_APIS))))));
    wireMockRule.stubFor(get(urlPathEqualTo("/api/v1")).willReturn(aResponse().withStatus(200).withBody(new String(Files.readAllBytes(Paths.get(DISCOVERY_APIV1))))));
    V1ConfigMap configMap = Kubectl.patch(V1ConfigMap.class).namespace("foo").name("bar").patchType(V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH).patchContent(new V1Patch("{\"data\":{\"key\":\"value\"}}")).apiClient(apiClient).execute();
    wireMockRule.verify(1, patchRequestedFor(urlPathEqualTo("/api/v1/namespaces/foo/configmaps/bar")));
    assertNotNull(configMap);
}
Also used : V1Patch(io.kubernetes.client.custom.V1Patch) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) Test(org.junit.Test)

Example 14 with V1Patch

use of io.kubernetes.client.custom.V1Patch in project java by kubernetes-client.

the class PatchUtilsTest method testMergePatchPod.

@Test
public void testMergePatchPod() throws ApiException {
    CoreV1Api coreV1Api = new CoreV1Api(client);
    stubFor(patch(urlPathEqualTo("/api/v1/namespaces/default/pods/foo")).withHeader("Content-Type", containing(V1Patch.PATCH_FORMAT_JSON_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_JSON_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 15 with V1Patch

use of io.kubernetes.client.custom.V1Patch in project java by kubernetes-client.

the class PatchUtilsTest method testJsonPatchPod.

@Test
public void testJsonPatchPod() throws ApiException {
    CoreV1Api coreV1Api = new CoreV1Api(client);
    stubFor(patch(urlPathEqualTo("/api/v1/namespaces/default/pods/foo")).withHeader("Content-Type", containing(V1Patch.PATCH_FORMAT_JSON_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_JSON_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)

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