use of io.kubernetes.client.openapi.models.V1Pod in project java by kubernetes-client.
the class KubectlExec method execute.
@Override
public Integer execute() throws KubectlException {
V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().name(name).namespace(namespace));
Exec exec = new Exec(apiClient);
try {
Process proc = exec.exec(pod, command, container, stdin, tty);
copyAsync(proc.getInputStream(), System.out);
copyAsync(proc.getErrorStream(), System.err);
if (stdin) {
copyAsync(System.in, proc.getOutputStream());
}
return proc.waitFor();
} catch (InterruptedException | ApiException | IOException ex) {
throw new KubectlException(ex);
}
}
use of io.kubernetes.client.openapi.models.V1Pod in project java by kubernetes-client.
the class KubectlGetTest method testGetDefaultNamespaceOnePod.
@Test
public void testGetDefaultNamespaceOnePod() throws KubectlException {
V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().namespace("default").name("foo1"));
wireMockRule.stubFor(get(urlPathEqualTo("/api/v1/namespaces/default/pods/foo1")).willReturn(aResponse().withStatus(200).withBody(apiClient.getJSON().serialize(pod))));
Kubectl.get(V1Pod.class).apiClient(apiClient).skipDiscovery().namespace("default").name("foo1").execute();
Kubectl.get(V1Pod.class).apiClient(apiClient).skipDiscovery().name("foo1").namespace("default").execute();
wireMockRule.verify(2, getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/pods/foo1")));
}
use of io.kubernetes.client.openapi.models.V1Pod in project java by kubernetes-client.
the class KubectlGetTest method testGetAllNamespacePods.
@Test
public void testGetAllNamespacePods() throws KubectlException {
V1PodList podList = new V1PodList().items(Arrays.asList(new V1Pod().metadata(new V1ObjectMeta().namespace("default").name("foo1")), new V1Pod().metadata(new V1ObjectMeta().namespace("default").name("foo2"))));
wireMockRule.stubFor(get(urlPathEqualTo("/api/v1/pods")).willReturn(aResponse().withStatus(200).withBody(apiClient.getJSON().serialize(podList))));
List<V1Pod> pods = Kubectl.get(V1Pod.class).apiClient(apiClient).skipDiscovery().execute();
wireMockRule.verify(1, getRequestedFor(urlPathEqualTo("/api/v1/pods")));
assertEquals(2, pods.size());
}
use of io.kubernetes.client.openapi.models.V1Pod in project java by kubernetes-client.
the class KubernetesInformerCreatorTest method testInformerInjection.
@Test
public void testInformerInjection() throws InterruptedException {
assertNotNull(podInformer);
assertNotNull(configMapInformer);
Semaphore getCount = new Semaphore(2);
Semaphore watchCount = new Semaphore(2);
Parameters getParams = new Parameters();
Parameters watchParams = new Parameters();
getParams.put("semaphore", getCount);
watchParams.put("semaphore", watchCount);
V1Pod foo1 = new V1Pod().kind("Pod").metadata(new V1ObjectMeta().namespace("default").name("foo1"));
V1ConfigMap bar1 = new V1ConfigMap().kind("ConfigMap").metadata(new V1ObjectMeta().namespace("default").name("bar1"));
wireMockRule.stubFor(get(urlMatching("^/api/v1/pods.*")).withPostServeAction("semaphore", getParams).withQueryParam("watch", equalTo("false")).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1PodList().metadata(new V1ListMeta().resourceVersion("0")).items(Arrays.asList(foo1))))));
wireMockRule.stubFor(get(urlMatching("^/api/v1/pods.*")).withPostServeAction("semaphore", watchParams).withQueryParam("watch", equalTo("true")).willReturn(aResponse().withStatus(200).withBody("{}")));
wireMockRule.stubFor(get(urlMatching("^/api/v1/namespaces/default/configmaps.*")).withPostServeAction("semaphore", getParams).withQueryParam("watch", equalTo("false")).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1ConfigMapList().metadata(new V1ListMeta().resourceVersion("0")).items(Arrays.asList(bar1))))));
wireMockRule.stubFor(get(urlMatching("^/api/v1/namespaces/default/configmaps.*")).withPostServeAction("semaphore", watchParams).withQueryParam("watch", equalTo("true")).willReturn(aResponse().withStatus(200).withBody("{}")));
// These will be released for each web call above.
getCount.acquire(2);
watchCount.acquire(2);
informerFactory.startAllRegisteredInformers();
// Wait for the GETs to complete and the watches to start.
getCount.acquire(2);
watchCount.acquire(2);
verify(1, getRequestedFor(urlPathEqualTo("/api/v1/pods")).withQueryParam("watch", equalTo("false")));
verify(getRequestedFor(urlPathEqualTo("/api/v1/pods")).withQueryParam("watch", equalTo("true")));
verify(1, getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/configmaps")).withQueryParam("watch", equalTo("false")));
verify(getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/configmaps")).withQueryParam("watch", equalTo("true")));
assertEquals(1, new Lister<>(podInformer.getIndexer()).list().size());
assertEquals(1, new Lister<>(configMapInformer.getIndexer()).list().size());
}
use of io.kubernetes.client.openapi.models.V1Pod in project java by kubernetes-client.
the class YamlTest method testDateTime.
@Test
public void testDateTime() {
try {
String strInput = "apiVersion: v1\n" + "kind: Pod\n" + "metadata:\n" + " creationTimestamp: 2018-09-06T15:12:24Z";
V1Pod pod = Yaml.loadAs(strInput, V1Pod.class);
assertEquals("Incorrect value loaded for creationTimestamp", "2018-09-06T15:12:24Z", new String(pod.getMetadata().getCreationTimestamp().toString().getBytes(), UTF_8));
} catch (Exception ex) {
assertNull("Unexpected exception: " + ex.toString(), ex);
}
}
Aggregations