Search in sources :

Example 1 with V1ConfigMapBuilder

use of io.kubernetes.client.openapi.models.V1ConfigMapBuilder in project pravega by pravega.

the class AbstractService method getBookkeeperOperatorConfigMap.

private V1ConfigMap getBookkeeperOperatorConfigMap() {
    Map<String, String> dataMap = new HashMap<>();
    dataMap.put("PRAVEGA_CLUSTER_NAME", PRAVEGA_ID);
    dataMap.put("WAIT_FOR", ZK_SERVICE_NAME);
    return new V1ConfigMapBuilder().withApiVersion("v1").withKind("ConfigMap").withMetadata(new V1ObjectMeta().name(CONFIG_MAP_BOOKKEEPER)).withData(dataMap).build();
}
Also used : V1ConfigMapBuilder(io.kubernetes.client.openapi.models.V1ConfigMapBuilder) HashMap(java.util.HashMap) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta)

Example 2 with V1ConfigMapBuilder

use of io.kubernetes.client.openapi.models.V1ConfigMapBuilder in project twister2 by DSC-SPIDAL.

the class RequestObjectBuilder method createConfigMap.

/**
 * create a ConfigMap object
 * It will have start counts for workers
 * @return
 */
public static V1ConfigMap createConfigMap(JobAPI.Job job) {
    String configMapName = jobID;
    // set a label for ConfigMap
    HashMap<String, String> labels = KubernetesUtils.createJobLabels(jobID);
    // data pairs
    HashMap<String, String> dataMap = new HashMap<>();
    String encodedJob = Base64.getEncoder().encodeToString(job.toByteArray());
    dataMap.put(KubernetesConstants.JOB_OBJECT_CM_PARAM, encodedJob);
    V1ConfigMap cm = new V1ConfigMapBuilder().withApiVersion("v1").withNewMetadata().withName(configMapName).withLabels(labels).endMetadata().withData(dataMap).build();
    return cm;
}
Also used : V1ConfigMapBuilder(io.kubernetes.client.openapi.models.V1ConfigMapBuilder) HashMap(java.util.HashMap) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap)

Example 3 with V1ConfigMapBuilder

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

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

use of io.kubernetes.client.openapi.models.V1ConfigMapBuilder 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)

Aggregations

V1ConfigMapBuilder (io.kubernetes.client.openapi.models.V1ConfigMapBuilder)7 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)6 Test (org.junit.Test)5 Matchers.anyString (org.mockito.Matchers.anyString)5 LinkedList (java.util.LinkedList)4 TopologySubmissionException (org.apache.heron.scheduler.TopologySubmissionException)4 TestTuple (org.apache.heron.scheduler.kubernetes.KubernetesUtils.TestTuple)4 Pair (org.apache.heron.common.basics.Pair)3 HashMap (java.util.HashMap)2 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)1 V1PodTemplateSpec (io.kubernetes.client.openapi.models.V1PodTemplateSpec)1