Search in sources :

Example 21 with V1ConfigMap

use of io.kubernetes.client.openapi.models.V1ConfigMap in project heron by twitter.

the class V1ControllerTest method testDisablePodTemplates.

@Test
public void testDisablePodTemplates() {
    // ConfigMap with valid Pod Template.
    V1ConfigMap configMapValidPod = new V1ConfigMapBuilder().withNewMetadata().withName(CONFIGMAP_NAME).endMetadata().addToData(POD_TEMPLATE_NAME, POD_TEMPLATE_VALID).build();
    final String expected = "Pod Templates are disabled";
    String message = "";
    doReturn(configMapValidPod).when(v1ControllerPodTemplate).getConfigMap(anyString());
    try {
        v1ControllerPodTemplate.loadPodFromTemplate(true);
    } catch (TopologySubmissionException e) {
        message = e.getMessage();
    }
    Assert.assertTrue(message.contains(expected));
}
Also used : V1ConfigMapBuilder(io.kubernetes.client.openapi.models.V1ConfigMapBuilder) TopologySubmissionException(org.apache.heron.scheduler.TopologySubmissionException) Matchers.anyString(org.mockito.Matchers.anyString) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) Test(org.junit.Test)

Example 22 with V1ConfigMap

use of io.kubernetes.client.openapi.models.V1ConfigMap in project java by kubernetes-client.

the class KubectlApplyTest method testApplyConfigMap.

@Test
public void testApplyConfigMap() throws KubectlException, IOException {
    wireMockRule.stubFor(patch(urlPathEqualTo("/api/v1/namespaces/foo/configmaps/bar")).withHeader("Content-Type", new EqualToPattern(V1Patch.PATCH_FORMAT_APPLY_YAML)).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.apply(V1ConfigMap.class).apiClient(apiClient).resource(new V1ConfigMap().apiVersion("v1").metadata(new V1ObjectMeta().namespace("foo").name("bar")).data(new HashMap<String, String>() {

        {
            put("key1", "value1");
        }
    })).execute();
    wireMockRule.verify(1, patchRequestedFor(urlPathEqualTo("/api/v1/namespaces/foo/configmaps/bar")));
    assertNotNull(configMap);
}
Also used : V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) Test(org.junit.Test)

Example 23 with V1ConfigMap

use of io.kubernetes.client.openapi.models.V1ConfigMap in project java by kubernetes-client.

the class KubectlCreateTest method testCreateConfigMap.

@Test
public void testCreateConfigMap() throws KubectlException, IOException {
    wireMockRule.stubFor(post(urlPathEqualTo("/api/v1/namespaces/foo/configmaps")).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 = (V1ConfigMap) Kubectl.create(V1ConfigMap.class).apiClient(apiClient).resource(new V1ConfigMap().apiVersion("v1").metadata(new V1ObjectMeta().namespace("foo").name("bar")).data(new HashMap<String, String>() {

        {
            put("key1", "value1");
        }
    })).execute();
    wireMockRule.verify(1, postRequestedFor(urlPathEqualTo("/api/v1/namespaces/foo/configmaps")));
    assertNotNull(configMap);
}
Also used : HashMap(java.util.HashMap) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) Test(org.junit.Test)

Example 24 with V1ConfigMap

use of io.kubernetes.client.openapi.models.V1ConfigMap 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 25 with V1ConfigMap

use of io.kubernetes.client.openapi.models.V1ConfigMap in project java by kubernetes-client.

the class CoreV1Api method patchNamespacedConfigMapWithHttpInfo.

/**
 * partially update the specified ConfigMap
 *
 * @param name name of the ConfigMap (required)
 * @param namespace object name and auth scope, such as for teams and projects (required)
 * @param body (required)
 * @param pretty If &#39;true&#39;, then the output is pretty printed. (optional)
 * @param dryRun When present, indicates that modifications should not be persisted. An invalid or
 *     unrecognized dryRun directive will result in an error response and no further processing of
 *     the request. Valid values are: - All: all dry run stages will be processed (optional)
 * @param fieldManager fieldManager is a name associated with the actor or entity that is making
 *     these changes. The value must be less than or 128 characters long, and only contain
 *     printable characters, as defined by https://golang.org/pkg/unicode/#IsPrint. This field is
 *     required for apply requests (application/apply-patch) but optional for non-apply patch
 *     types (JsonPatch, MergePatch, StrategicMergePatch). (optional)
 * @param fieldValidation fieldValidation determines how the server should respond to
 *     unknown/duplicate fields in the object in the request. Introduced as alpha in 1.23, older
 *     servers or servers with the &#x60;ServerSideFieldValidation&#x60; feature disabled will
 *     discard valid values specified in this param and not perform any server side field
 *     validation. Valid values are: - Ignore: ignores unknown/duplicate fields. - Warn: responds
 *     with a warning for each unknown/duplicate field, but successfully serves the request. -
 *     Strict: fails the request on unknown/duplicate fields. (optional)
 * @param force Force is going to \&quot;force\&quot; Apply requests. It means user will
 *     re-acquire conflicting fields owned by other people. Force flag must be unset for non-apply
 *     patch requests. (optional)
 * @return ApiResponse&lt;V1ConfigMap&gt;
 * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the
 *     response body
 * @http.response.details
 *     <table summary="Response Details" border="1">
 * <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
 * <tr><td> 200 </td><td> OK </td><td>  -  </td></tr>
 * <tr><td> 201 </td><td> Created </td><td>  -  </td></tr>
 * <tr><td> 401 </td><td> Unauthorized </td><td>  -  </td></tr>
 * </table>
 */
public ApiResponse<V1ConfigMap> patchNamespacedConfigMapWithHttpInfo(String name, String namespace, V1Patch body, String pretty, String dryRun, String fieldManager, String fieldValidation, Boolean force) throws ApiException {
    okhttp3.Call localVarCall = patchNamespacedConfigMapValidateBeforeCall(name, namespace, body, pretty, dryRun, fieldManager, fieldValidation, force, null);
    Type localVarReturnType = new TypeToken<V1ConfigMap>() {
    }.getType();
    return localVarApiClient.execute(localVarCall, localVarReturnType);
}
Also used : Type(java.lang.reflect.Type) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap)

Aggregations

V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)35 Test (org.junit.Test)11 Type (java.lang.reflect.Type)8 V1ConfigMapBuilder (io.kubernetes.client.openapi.models.V1ConfigMapBuilder)6 TopologySubmissionException (org.apache.heron.scheduler.TopologySubmissionException)6 Matchers.anyString (org.mockito.Matchers.anyString)6 ApiException (io.kubernetes.client.openapi.ApiException)5 LinkedList (java.util.LinkedList)5 TestTuple (org.apache.heron.scheduler.kubernetes.KubernetesUtils.TestTuple)5 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)4 JobConfig (edu.iu.dsc.tws.api.JobConfig)3 Config (edu.iu.dsc.tws.api.config.Config)3 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)3 HashMap (java.util.HashMap)3 Pair (org.apache.heron.common.basics.Pair)3 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)2 Twister2RuntimeException (edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException)2 KubernetesController (edu.iu.dsc.tws.rsched.schedulers.k8s.KubernetesController)2 JSON (io.kubernetes.client.openapi.JSON)2 V1ConfigMapList (io.kubernetes.client.openapi.models.V1ConfigMapList)2