Search in sources :

Example 1 with V1ConfigMap

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

the class V1ControllerTest method testLoadPodFromTemplateValidConfigMap.

@Test
public void testLoadPodFromTemplateValidConfigMap() {
    final String expected = "        containers: [class V1Container {\n" + "            args: null\n" + "            command: null\n" + "            env: null\n" + "            envFrom: null\n" + "            image: apache/heron:latest\n" + "            imagePullPolicy: null\n" + "            lifecycle: null\n" + "            livenessProbe: null\n" + "            name: heron-tracker\n" + "            ports: [class V1ContainerPort {\n" + "                containerPort: 8888\n" + "                hostIP: null\n" + "                hostPort: null\n" + "                name: api-port\n" + "                protocol: null\n" + "            }]\n" + "            readinessProbe: null\n" + "            resources: class V1ResourceRequirements {\n" + "                limits: {cpu=Quantity{number=0.400, format=DECIMAL_SI}, " + "memory=Quantity{number=512000000, format=DECIMAL_SI}}\n" + "                requests: {cpu=Quantity{number=0.100, format=DECIMAL_SI}, " + "memory=Quantity{number=200000000, format=DECIMAL_SI}}\n" + "            }\n" + "            securityContext: null\n" + "            startupProbe: null\n" + "            stdin: null\n" + "            stdinOnce: null\n" + "            terminationMessagePath: null\n" + "            terminationMessagePolicy: null\n" + "            tty: null\n" + "            volumeDevices: null\n" + "            volumeMounts: null\n" + "            workingDir: null\n" + "        }]";
    // ConfigMap with valid Pod Template.
    final V1ConfigMap configMapValidPod = new V1ConfigMapBuilder().withNewMetadata().withName(CONFIGMAP_NAME).endMetadata().addToData(POD_TEMPLATE_NAME, POD_TEMPLATE_VALID).build();
    // Test case container.
    // Input: ConfigMap to setup mock V1Controller, Boolean flag for executor/manager switch.
    // Output: The expected Pod template as a string.
    final List<TestTuple<Pair<V1ConfigMap, Boolean>, String>> testCases = new LinkedList<>();
    testCases.add(new TestTuple<>("Executor valid Pod Template", new Pair<>(configMapValidPod, true), expected));
    testCases.add(new TestTuple<>("Manager valid Pod Template", new Pair<>(configMapValidPod, false), expected));
    // Test loop.
    for (TestTuple<Pair<V1ConfigMap, Boolean>, String> testCase : testCases) {
        doReturn(testCase.input.first).when(v1ControllerWithPodTemplate).getConfigMap(anyString());
        V1PodTemplateSpec podTemplateSpec = v1ControllerWithPodTemplate.loadPodFromTemplate(true);
        Assert.assertTrue(podTemplateSpec.toString().contains(testCase.expected));
    }
}
Also used : V1ConfigMapBuilder(io.kubernetes.client.openapi.models.V1ConfigMapBuilder) TestTuple(org.apache.heron.scheduler.kubernetes.KubernetesUtils.TestTuple) Matchers.anyString(org.mockito.Matchers.anyString) V1PodTemplateSpec(io.kubernetes.client.openapi.models.V1PodTemplateSpec) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) LinkedList(java.util.LinkedList) Pair(org.apache.heron.common.basics.Pair) Test(org.junit.Test)

Example 2 with V1ConfigMap

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

the class V1ControllerTest method testLoadPodFromTemplateNoTargetConfigMap.

@Test
public void testLoadPodFromTemplateNoTargetConfigMap() {
    final List<TestTuple<Boolean, String>> testCases = new LinkedList<>();
    testCases.add(new TestTuple<>("Executor no target ConfigMap", true, "Failed to locate Pod Template"));
    testCases.add(new TestTuple<>("Manager no target ConfigMap", false, "Failed to locate Pod Template"));
    final V1ConfigMap configMapNoTargetData = new V1ConfigMapBuilder().withNewMetadata().withName(CONFIGMAP_NAME).endMetadata().addToData("Dummy Key", "Dummy Value").build();
    for (TestTuple<Boolean, String> testCase : testCases) {
        doReturn(configMapNoTargetData).when(v1ControllerWithPodTemplate).getConfigMap(anyString());
        String message = "";
        try {
            v1ControllerWithPodTemplate.loadPodFromTemplate(testCase.input);
        } catch (TopologySubmissionException e) {
            message = e.getMessage();
        }
        Assert.assertTrue(testCase.description, message.contains(testCase.expected));
    }
}
Also used : V1ConfigMapBuilder(io.kubernetes.client.openapi.models.V1ConfigMapBuilder) TopologySubmissionException(org.apache.heron.scheduler.TopologySubmissionException) TestTuple(org.apache.heron.scheduler.kubernetes.KubernetesUtils.TestTuple) Matchers.anyString(org.mockito.Matchers.anyString) LinkedList(java.util.LinkedList) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) Test(org.junit.Test)

Example 3 with V1ConfigMap

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

the class V1ControllerTest method testLoadPodFromTemplateInvalidConfigMap.

@Test
public void testLoadPodFromTemplateInvalidConfigMap() {
    // ConfigMap with an invalid Pod Template.
    final String invalidPodTemplate = "apiVersion: apps/v1\n" + "kind: InvalidTemplate\n" + "metadata:\n" + "  name: heron-tracker\n" + "  namespace: default\n" + "template:\n" + "  metadata:\n" + "    labels:\n" + "      app: heron-tracker\n" + "  spec:\n";
    final V1ConfigMap configMap = new V1ConfigMapBuilder().withNewMetadata().withName(CONFIGMAP_NAME).endMetadata().addToData(POD_TEMPLATE_NAME, invalidPodTemplate).build();
    // Test case container.
    // Input: ConfigMap to setup mock V1Controller, Boolean flag for executor/manager switch.
    // Output: The expected Pod template as a string.
    final List<TestTuple<Pair<V1ConfigMap, Boolean>, String>> testCases = new LinkedList<>();
    testCases.add(new TestTuple<>("Executor invalid Pod Template", new Pair<>(configMap, true), "Error parsing"));
    testCases.add(new TestTuple<>("Manager invalid Pod Template", new Pair<>(configMap, false), "Error parsing"));
    // Test loop.
    for (TestTuple<Pair<V1ConfigMap, Boolean>, String> testCase : testCases) {
        doReturn(testCase.input.first).when(v1ControllerWithPodTemplate).getConfigMap(anyString());
        String message = "";
        try {
            v1ControllerWithPodTemplate.loadPodFromTemplate(testCase.input.second);
        } catch (TopologySubmissionException e) {
            message = e.getMessage();
        }
        Assert.assertTrue(message.contains(testCase.expected));
    }
}
Also used : V1ConfigMapBuilder(io.kubernetes.client.openapi.models.V1ConfigMapBuilder) TopologySubmissionException(org.apache.heron.scheduler.TopologySubmissionException) TestTuple(org.apache.heron.scheduler.kubernetes.KubernetesUtils.TestTuple) Matchers.anyString(org.mockito.Matchers.anyString) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) LinkedList(java.util.LinkedList) Pair(org.apache.heron.common.basics.Pair) Test(org.junit.Test)

Example 4 with V1ConfigMap

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

the class CoreV1Api method patchNamespacedConfigMapAsync.

/**
 * (asynchronously) 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)
 * @param _callback The callback to be executed when the API call finishes
 * @return The request call
 * @throws ApiException If fail to process the API call, e.g. serializing the request body object
 * @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 okhttp3.Call patchNamespacedConfigMapAsync(String name, String namespace, V1Patch body, String pretty, String dryRun, String fieldManager, String fieldValidation, Boolean force, final ApiCallback<V1ConfigMap> _callback) throws ApiException {
    okhttp3.Call localVarCall = patchNamespacedConfigMapValidateBeforeCall(name, namespace, body, pretty, dryRun, fieldManager, fieldValidation, force, _callback);
    Type localVarReturnType = new TypeToken<V1ConfigMap>() {
    }.getType();
    localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
    return localVarCall;
}
Also used : Type(java.lang.reflect.Type) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap)

Example 5 with V1ConfigMap

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

the class ConfigMapLock method get.

@Override
public LeaderElectionRecord get() throws ApiException {
    V1ConfigMap configMap = coreV1Client.readNamespacedConfigMap(name, namespace, null);
    configMapRefer.set(configMap);
    Map<String, String> annotations = configMap.getMetadata().getAnnotations();
    if (annotations == null || annotations.isEmpty()) {
        configMap.getMetadata().setAnnotations(new HashMap<>());
    }
    String recordRawStringContent = configMap.getMetadata().getAnnotations().get(LeaderElectionRecordAnnotationKey);
    if (StringUtils.isEmpty(recordRawStringContent)) {
        return new LeaderElectionRecord();
    }
    LeaderElectionRecord record = coreV1Client.getApiClient().getJSON().deserialize(recordRawStringContent, LeaderElectionRecord.class);
    return record;
}
Also used : LeaderElectionRecord(io.kubernetes.client.extended.leaderelection.LeaderElectionRecord) 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