Search in sources :

Example 31 with V1ObjectMeta

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

the class PodLogsTest method testStream.

@Test
public void testStream() throws ApiException, IOException {
    V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().name(podName).namespace(namespace)).spec(new V1PodSpec().containers(Arrays.asList(new V1Container().name(container).image("nginx"))));
    String content = "this is some\n content for \n various logs \n done";
    wireMockRule.stubFor(get(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/log")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "text/plain").withBody(content)));
    PodLogs logs = new PodLogs(client);
    InputStream is = logs.streamNamespacedPodLog(pod);
    wireMockRule.verify(getRequestedFor(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/log")).withQueryParam("container", equalTo(container)).withQueryParam("follow", equalTo("true")).withQueryParam("pretty", equalTo("false")).withQueryParam("previous", equalTo("false")).withQueryParam("timestamps", equalTo("false")));
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    Streams.copy(is, bos);
    assertEquals(content, bos.toString());
}
Also used : V1Container(io.kubernetes.client.openapi.models.V1Container) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) InputStream(java.io.InputStream) V1Pod(io.kubernetes.client.openapi.models.V1Pod) ByteArrayOutputStream(java.io.ByteArrayOutputStream) V1PodSpec(io.kubernetes.client.openapi.models.V1PodSpec) Test(org.junit.Test)

Example 32 with V1ObjectMeta

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

the class GenericKubernetesApi method create.

/**
 * Create kubernetes api response.
 *
 * @param object the object
 * @param createOptions the create options
 * @return the kubernetes api response
 */
public KubernetesApiResponse<ApiType> create(ApiType object, final CreateOptions createOptions) {
    V1ObjectMeta objectMeta = object.getMetadata();
    boolean isNamespaced = !Strings.isNullOrEmpty(objectMeta.getNamespace());
    if (isNamespaced) {
        return create(objectMeta.getNamespace(), object, createOptions);
    }
    return executeCall(customObjectsApi.getApiClient(), apiTypeClass, () -> {
        // TODO(yue9944882): judge namespaced object via api discovery
        return customObjectsApi.createClusterCustomObjectCall(this.apiGroup, this.apiVersion, this.resourcePlural, object, null, createOptions.getDryRun(), createOptions.getFieldManager(), null);
    });
}
Also used : V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta)

Example 33 with V1ObjectMeta

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

the class CachesTest method testDefaultNamespaceNameKey.

@Test
public void testDefaultNamespaceNameKey() {
    String testName = "test-name";
    String testNamespace = "test-namespace";
    V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().name(testName).namespace(testNamespace));
    assertEquals(testNamespace + "/" + testName, Caches.metaNamespaceKeyFunc(pod));
}
Also used : V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Pod(io.kubernetes.client.openapi.models.V1Pod) Test(org.junit.Test)

Example 34 with V1ObjectMeta

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

the class DeltaFIFOTest method testDeltaFIFOBasic.

@Test
public void testDeltaFIFOBasic() throws InterruptedException {
    Deque<MutablePair<DeltaFIFO.DeltaType, KubernetesObject>> receivingDeltas = new LinkedList<>();
    V1Pod foo1 = new V1Pod().metadata(new V1ObjectMeta().name("foo1").namespace("default"));
    Cache cache = new Cache();
    DeltaFIFO deltaFIFO = new DeltaFIFO(Caches::deletionHandlingMetaNamespaceKeyFunc, cache);
    MutablePair<DeltaFIFO.DeltaType, KubernetesObject> receivingDelta;
    // basic add operation
    deltaFIFO.add(foo1);
    cache.add(foo1);
    deltaFIFO.pop((deltas) -> {
        MutablePair<DeltaFIFO.DeltaType, KubernetesObject> delta = deltas.peekFirst();
        receivingDeltas.add(delta);
    });
    receivingDelta = receivingDeltas.peekFirst();
    receivingDeltas.removeFirst();
    assertEquals(foo1, receivingDelta.getRight());
    assertEquals(DeltaFIFO.DeltaType.Added, receivingDelta.getLeft());
    // basic update operation
    deltaFIFO.update(foo1);
    cache.update(foo1);
    deltaFIFO.pop((deltas) -> {
        MutablePair<DeltaFIFO.DeltaType, KubernetesObject> delta = deltas.peekFirst();
        receivingDeltas.add(delta);
    });
    receivingDelta = receivingDeltas.peekFirst();
    receivingDeltas.removeFirst();
    assertEquals(foo1, receivingDelta.getRight());
    assertEquals(DeltaFIFO.DeltaType.Updated, receivingDelta.getLeft());
    // basic delete operation
    deltaFIFO.delete(foo1);
    cache.delete(foo1);
    deltaFIFO.pop((deltas) -> {
        MutablePair<DeltaFIFO.DeltaType, KubernetesObject> delta = deltas.peekFirst();
        receivingDeltas.add(delta);
    });
    receivingDelta = receivingDeltas.peekFirst();
    receivingDeltas.removeFirst();
    assertEquals(foo1, receivingDelta.getRight());
    assertEquals(DeltaFIFO.DeltaType.Deleted, receivingDelta.getLeft());
    // basic sync operation
    deltaFIFO.replace(Arrays.asList(foo1), "0");
    cache.replace(Arrays.asList(foo1), "0");
    deltaFIFO.pop((deltas) -> {
        MutablePair<DeltaFIFO.DeltaType, KubernetesObject> delta = deltas.peekFirst();
        receivingDeltas.add(delta);
    });
    receivingDelta = receivingDeltas.peekFirst();
    receivingDeltas.removeFirst();
    assertEquals(foo1, receivingDelta.getRight());
    assertEquals(DeltaFIFO.DeltaType.Sync, receivingDelta.getLeft());
}
Also used : MutablePair(org.apache.commons.lang3.tuple.MutablePair) KubernetesObject(io.kubernetes.client.common.KubernetesObject) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Pod(io.kubernetes.client.openapi.models.V1Pod) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 35 with V1ObjectMeta

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

the class JobMasterRequestObject method constructPodTemplate.

/**
 * construct pod template
 */
public static V1PodTemplateSpec constructPodTemplate() {
    V1PodTemplateSpec template = new V1PodTemplateSpec();
    V1ObjectMeta templateMetaData = new V1ObjectMeta();
    HashMap<String, String> labels = KubernetesUtils.createJobLabels(jobID);
    // job master pod
    labels.put("t2-mp", jobID);
    templateMetaData.setLabels(labels);
    template.setMetadata(templateMetaData);
    V1PodSpec podSpec = new V1PodSpec();
    podSpec.setTerminationGracePeriodSeconds(0L);
    ArrayList<V1Volume> volumes = new ArrayList<>();
    V1Volume memoryVolume = new V1Volume();
    memoryVolume.setName(KubernetesConstants.POD_MEMORY_VOLUME_NAME);
    V1EmptyDirVolumeSource volumeSource1 = new V1EmptyDirVolumeSource();
    volumeSource1.setMedium("Memory");
    memoryVolume.setEmptyDir(volumeSource1);
    volumes.add(memoryVolume);
    // create it if the requested disk space is positive
    if (JobMasterContext.volatileVolumeRequested(config)) {
        double vSize = JobMasterContext.volatileVolumeSize(config);
        V1Volume volatileVolume = RequestObjectBuilder.createVolatileVolume(vSize);
        volumes.add(volatileVolume);
    }
    if (JobMasterContext.persistentVolumeRequested(config)) {
        String claimName = jobID;
        V1Volume persistentVolume = RequestObjectBuilder.createPersistentVolume(claimName);
        volumes.add(persistentVolume);
    }
    podSpec.setVolumes(volumes);
    ArrayList<V1Container> containers = new ArrayList<V1Container>();
    containers.add(constructContainer());
    podSpec.setContainers(containers);
    template.setSpec(podSpec);
    return template;
}
Also used : V1Container(io.kubernetes.client.openapi.models.V1Container) V1Volume(io.kubernetes.client.openapi.models.V1Volume) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) ArrayList(java.util.ArrayList) V1EmptyDirVolumeSource(io.kubernetes.client.openapi.models.V1EmptyDirVolumeSource) V1PodTemplateSpec(io.kubernetes.client.openapi.models.V1PodTemplateSpec) IntOrString(io.kubernetes.client.custom.IntOrString) V1PodSpec(io.kubernetes.client.openapi.models.V1PodSpec)

Aggregations

V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)78 Test (org.junit.Test)49 V1Pod (io.kubernetes.client.openapi.models.V1Pod)37 HashMap (java.util.HashMap)14 ApiException (io.kubernetes.client.openapi.ApiException)11 V1PodList (io.kubernetes.client.openapi.models.V1PodList)11 V1PodSpec (io.kubernetes.client.openapi.models.V1PodSpec)10 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)8 V1Container (io.kubernetes.client.openapi.models.V1Container)7 ApiClient (io.kubernetes.client.openapi.ApiClient)6 JSON (io.kubernetes.client.openapi.JSON)6 V1Job (io.kubernetes.client.openapi.models.V1Job)6 V1ListMeta (io.kubernetes.client.openapi.models.V1ListMeta)6 V1PodTemplateSpec (io.kubernetes.client.openapi.models.V1PodTemplateSpec)6 V1Patch (io.kubernetes.client.custom.V1Patch)5 SharedInformerFactory (io.kubernetes.client.informer.SharedInformerFactory)5 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)5 V1Service (io.kubernetes.client.openapi.models.V1Service)5 V1ServiceSpec (io.kubernetes.client.openapi.models.V1ServiceSpec)5 CallGeneratorParams (io.kubernetes.client.util.CallGeneratorParams)5