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());
}
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);
});
}
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));
}
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());
}
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;
}
Aggregations