io.fabric8.kubernetes.api.model.PodListBuilder Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.PodListBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResourceIT.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
public void list() {
  Pod listPod1 = new PodBuilder()
    .withNewMetadata().withName("pod3").endMetadata()
    .withNewSpec()
    .addNewContainer().withName("nginx").withImage("nginx").endContainer()
    .endSpec()
    .build();
  client.resourceList(new PodListBuilder().withItems(listPod1).build())
    .inNamespace(currentNamespace)
    .apply();

  assertTrue(client.pods().inNamespace(currentNamespace).withName("pod3") != null);

  boolean bDeleted = client.resourceList(new PodListBuilder().withItems(listPod1).build())
    .inNamespace(currentNamespace)
    .delete();
  assertTrue(bDeleted);
}
 
Example #2
Source File: LabelTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
void testLabelsNotIn() {
  server.expect().get().withPath("/api/v1/namespaces/test/pods?labelSelector=foo%20notin%20%28bar%29")
    .andReturn(200, new PodListBuilder().withItems(pod2).build())
    .once();

  server.expect().get().withPath("/api/v1/namespaces/test/pods?labelSelector=app%20notin%20%28nginx%29")
    .andReturn(200, new PodListBuilder().withItems(pod1).build())
    .once();

  KubernetesClient client = server.getClient();
  Map<String, String> filterLabels = new HashMap<>();

  PodList list = client.pods().inNamespace("test").withLabelNotIn("foo", "bar").list();
  assertNotNull(list);
  assertEquals(1, list.getItems().size());

  filterLabels.put("app", "nginx");
  list = client.pods().inNamespace("test").withLabelNotIn("app", "nginx").list();
  assertNotNull(list);
  assertEquals(1, list.getItems().size());

}
 
Example #3
Source File: LabelTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
void testLabelsIn() {
  server.expect().get().withPath("/api/v1/namespaces/test/pods?labelSelector=foo%20in%20%28bar%29")
    .andReturn(200, new PodListBuilder().withItems(pod1).build())
    .once();

  server.expect().get().withPath("/api/v1/namespaces/test/pods?labelSelector=app%20in%20%28nginx%29")
    .andReturn(200, new PodListBuilder().withItems(pod2).build())
    .once();

  KubernetesClient client = server.getClient();
  Map<String, String> filterLabels = new HashMap<>();

  PodList list = client.pods().inNamespace("test").withLabelIn("foo", "bar").list();
  assertNotNull(list);
  assertEquals(1, list.getItems().size());

  filterLabels.put("app", "nginx");
  list = client.pods().inNamespace("test").withLabelIn("app", "nginx").list();
  assertNotNull(list);
  assertEquals(1, list.getItems().size());
}
 
Example #4
Source File: LabelTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
void testWithoutLabel() {
  server.expect().get().withPath("/api/v1/namespaces/test/pods?labelSelector=" + Utils.toUrlEncoded("!foo"))
    .andReturn(200, new PodListBuilder().withItems(pod2).build())
    .once();

  server.expect().get().withPath("/api/v1/namespaces/test/pods?labelSelector=" + Utils.toUrlEncoded("!app"))
    .andReturn(200, new PodListBuilder().withItems(pod1).build())
    .once();

  KubernetesClient client = server.getClient();
  PodList list = client.pods().inNamespace("test").withoutLabel("foo").list();
  assertNotNull(list);
  assertEquals(1, list.getItems().size());

  list = client.pods().inNamespace("test").withoutLabel("app").list();
  assertNotNull(list);
  assertEquals(1, list.getItems().size());
}
 
Example #5
Source File: LabelTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
void testWithLabel() {
  server.expect().get().withPath("/api/v1/namespaces/test/pods?labelSelector=foo")
    .andReturn(200, new PodListBuilder().withItems(pod1).build())
    .once();

  server.expect().get().withPath("/api/v1/namespaces/test/pods?labelSelector=app")
    .andReturn(200, new PodListBuilder().withItems(pod2).build())
    .once();

  KubernetesClient client = server.getClient();
  PodList list = client.pods().inNamespace("test").withLabel("foo").list();
  assertNotNull(list);
  assertEquals(1, list.getItems().size());

  list = client.pods().inNamespace("test").withLabel("app").list();
  assertNotNull(list);
  assertEquals(1, list.getItems().size());
}
 
Example #6
Source File: ResourceListTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testDelete() {
  Pod pod1 = new PodBuilder().withNewMetadata().withName("pod1").withNamespace("test").and().build();
  Pod pod2 = new PodBuilder().withNewMetadata().withName("pod2").withNamespace("ns1").and().build();
  Pod pod3 = new PodBuilder().withNewMetadata().withName("pod3").withNamespace("any").and().build();


  server.expect().withPath("/api/v1/namespaces/test/pods/pod1").andReturn(200, pod1).times(2);
  server.expect().withPath("/api/v1/namespaces/ns1/pods/pod2").andReturn(200, pod2).times(2);
  server.expect().withPath("/api/v1/namespaces/any/pods/pod3").andReturn(200, pod3).times(1);

  KubernetesClient client = server.getClient();

  //First time all items should be deleted.
  Boolean deleted = client.resourceList(new PodListBuilder().withItems(pod1, pod2, pod3).build()).delete();
  assertTrue(deleted);

  //Now we expect pod3 to fail.
  deleted = client.resourceList(new PodListBuilder().withItems(pod1, pod2, pod3).build()).delete();
  assertFalse(deleted);
}
 
Example #7
Source File: PodTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testListWithFields() {
 server.expect().withPath("/api/v1/namespaces/test/pods?fieldSelector=" + Utils.toUrlEncoded("key1=value1,key2=value2,key3!=value3,key3!=value4")).andReturn(200, new PodListBuilder()
    .addNewItem().and()
    .addNewItem().and()
    .build()).once();

  KubernetesClient client = server.getClient();
  PodList podList = client.pods()
    .withField("key1", "value1")
    .withField("key2","value2")
    .withoutField("key3","value3")
    .withoutField("key3", "value4")
    .list();


  assertNotNull(podList);
  assertEquals(2, podList.getItems().size());
}
 
Example #8
Source File: PodTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testList() {
 server.expect().withPath("/api/v1/namespaces/test/pods").andReturn(200, new PodListBuilder().build()).once();
 server.expect().withPath("/api/v1/namespaces/ns1/pods").andReturn(200, new PodListBuilder()
    .addNewItem().and()
    .addNewItem().and().build()).once();

 server.expect().withPath("/api/v1/pods").andReturn(200, new PodListBuilder()
    .addNewItem().and()
    .addNewItem().and()
    .addNewItem()
    .and().build()).once();


  KubernetesClient client = server.getClient();
  PodList podList = client.pods().list();
  assertNotNull(podList);
  assertEquals(0, podList.getItems().size());

  podList = client.pods().inNamespace("ns1").list();
  assertNotNull(podList);
  assertEquals(2, podList.getItems().size());

  podList = client.pods().inAnyNamespace().list();
  assertNotNull(podList);
  assertEquals(3, podList.getItems().size());
}
 
Example #9
Source File: LabelTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
void testWithoutLabels() {
  server.expect().get().withPath("/api/v1/namespaces/test/pods?labelSelector=" + Utils.toUrlEncoded("foo!=bar"))
    .andReturn(200, new PodListBuilder().withItems(pod2).build())
    .once();

  server.expect().get().withPath("/api/v1/namespaces/test/pods?labelSelector=" + Utils.toUrlEncoded("app!=nginx,foo!=bar"))
    .andReturn(200, new PodListBuilder().build())
    .once();

  server.expect().get().withPath("/api/v1/namespaces/test/pods?labelSelector=" + Utils.toUrlEncoded("app!=nginx"))
    .andReturn(200, new PodListBuilder().withItems(pod1).build())
    .once();

  KubernetesClient client = server.getClient();
  Map<String, String> filterLabels = new HashMap<>();

  filterLabels.put("foo", "bar");
  PodList list = client.pods().inNamespace("test").withoutLabels(filterLabels).list();
  assertNotNull(list);
  assertEquals(1, list.getItems().size());

  filterLabels.put("app", "nginx");
  list = client.pods().inNamespace("test").withoutLabels(filterLabels).list();
  assertNotNull(list);
  assertEquals(0, list.getItems().size());

  filterLabels.remove("foo");
  list = client.pods().inNamespace("test").withoutLabels(filterLabels).list();
  assertNotNull(list);
  assertEquals(1, list.getItems().size());
}
 
Example #10
Source File: LabelTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
void testWithLabels() {
  server.expect().get().withPath("/api/v1/namespaces/test/pods?labelSelector=" + Utils.toUrlEncoded("foo=bar"))
    .andReturn(200, new PodListBuilder().withItems(pod1).build())
    .once();

  server.expect().get().withPath("/api/v1/namespaces/test/pods?labelSelector=" + Utils.toUrlEncoded("app=nginx,foo=bar"))
    .andReturn(200, new PodListBuilder().build())
    .once();

  server.expect().get().withPath("/api/v1/namespaces/test/pods?labelSelector=" + Utils.toUrlEncoded("app=nginx"))
    .andReturn(200, new PodListBuilder().withItems(pod2).build())
    .once();

  KubernetesClient client = server.getClient();
  Map<String, String> filterLabels = new HashMap<>();

  filterLabels.put("foo", "bar");
  PodList list = client.pods().inNamespace("test").withLabels(filterLabels).list();
  assertNotNull(list);
  assertEquals(1, list.getItems().size());

  filterLabels.put("app", "nginx");
  list = client.pods().inNamespace("test").withLabels(filterLabels).list();
  assertNotNull(list);
  assertEquals(0, list.getItems().size());

  filterLabels.remove("foo");
  list = client.pods().inNamespace("test").withLabels(filterLabels).list();
  assertNotNull(list);
  assertEquals(1, list.getItems().size());
}
 
Example #11
Source File: LabelTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
void testBasicList() {
  server.expect().get().withPath("/api/v1/namespaces/test/pods")
    .andReturn(200, new PodListBuilder().withItems(pod1, pod2).build())
    .once();

  KubernetesClient client = server.getClient();

  PodList list = client.pods().inNamespace("test").list();
  assertNotNull(list);
  assertEquals(2, list.getItems().size());
}
 
Example #12
Source File: PodTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testListWithLables() {
 server.expect().withPath("/api/v1/namespaces/test/pods?labelSelector=" + Utils.toUrlEncoded("key1=value1,key2=value2,key3=value3")).andReturn(200, new PodListBuilder().build()).always();
 server.expect().withPath("/api/v1/namespaces/test/pods?labelSelector=" + Utils.toUrlEncoded("key1=value1,key2=value2")).andReturn(200, new PodListBuilder()
    .addNewItem().and()
    .addNewItem().and()
    .addNewItem().and()
    .build()).once();

  KubernetesClient client = server.getClient();
  PodList podList = client.pods()
    .withLabel("key1", "value1")
    .withLabel("key2","value2")
    .withLabel("key3","value3")
    .list();


  assertNotNull(podList);
  assertEquals(0, podList.getItems().size());

  podList = client.pods()
    .withLabel("key1", "value1")
    .withLabel("key2","value2")
    .list();

  assertNotNull(podList);
  assertEquals(3, podList.getItems().size());
}
 
Example #13
Source File: HttpServerTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testListWithTrustCerts() {
 server.expect().withPath("/api/v1/namespaces/test/pods").andReturn(200, new PodListBuilder().build()).once();
  //We override the config to create a client that doesn't trust all certs.
  Config override = new ConfigBuilder(server.getClient().getConfiguration()).build();

  KubernetesClient client = new DefaultKubernetesClient(override);
  client.pods().list();
}
 
Example #14
Source File: UntrustedCertTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testListWithTrustCerts() {
 server.expect().withPath("/api/v1/namespaces/test/pods").andReturn(200, new PodListBuilder().build()).once();
  //We override the config to create a client that doesn't trust all certs.
  Config override = new ConfigBuilder(server.getClient().getConfiguration())
          .withTrustCerts(true)
          .withCaCertData(CA_CERT_DATA)
          .build();

  KubernetesClient client = new DefaultKubernetesClient(override);
  client.pods().list();
}
 
Example #15
Source File: UntrustedCertTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testListWithCaCerts() {
  Assertions.assertThrows(KubernetesClientException.class, () -> {
    server.expect().withPath("/api/v1/namespaces/test/pods").andReturn(200, new PodListBuilder().build()).once();
    //We override the config to create a client that doesn't trust all certs.
    Config override = new ConfigBuilder(server.getClient().getConfiguration())
      .withTrustCerts(false)
      .withCaCertData(CA_CERT_DATA)
      .build();

    KubernetesClient client = new DefaultKubernetesClient(override);
    client.pods().list();
  });
}
 
Example #16
Source File: UntrustedCertTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testList() {
  Assertions.assertThrows(KubernetesClientException.class, () -> {
    server.expect().withPath("/api/v1/namespaces/test/pods").andReturn(200, new PodListBuilder().build()).once();
    //We override the config to create a client that doesn't trust all certs.
    Config override = new ConfigBuilder(server.getClient().getConfiguration())
      .withTrustCerts(false)
      .build();

    KubernetesClient client = new DefaultKubernetesClient(override);
    client.pods().list();
  });
}
 
Example #17
Source File: ResourceListTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateWithExplicitNamespace() {
  Pod pod1 = new PodBuilder().withNewMetadata().withName("pod1").withNamespace("test").and().build();

  server.expect().get().withPath("/api/v1/namespaces/ns1/pods/pod1").andReturn(404, "").once();
  server.expect().post().withPath("/api/v1/namespaces/ns1/pods").andReturn(201, pod1).once();

  KubernetesClient client = server.getClient();
  List<HasMetadata> response = client.resourceList(new PodListBuilder().addToItems(pod1).build()).inNamespace("ns1").apply();
  assertTrue(response.contains(pod1));
}
 
Example #18
Source File: ResourceListTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateOrReplace() {
  Pod pod1 = new PodBuilder().withNewMetadata().withName("pod1").withNamespace("test").and().build();

  server.expect().get().withPath("/api/v1/namespaces/test/pods/pod1").andReturn(404, "").once();
  server.expect().post().withPath("/api/v1/namespaces/test/pods").andReturn(201, pod1).once();

  KubernetesClient client = server.getClient();
  List<HasMetadata> response = client.resourceList(new PodListBuilder().addToItems(pod1).build()).createOrReplace();
  assertTrue(response.contains(pod1));
}
 
Example #19
Source File: ActivityTrackingControllerTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
protected PodList listPods() {
    return new PodListBuilder()
        .addNewItem()
        .withNewMetadata()
        .withName("test-pod-x23x")
        .addToLabels(OpenShiftService.COMPONENT_LABEL, "integration")
        .addToLabels(OpenShiftService.DEPLOYMENT_VERSION_LABEL, "3")
        .addToLabels(OpenShiftService.INTEGRATION_ID_LABEL, "my-integration")
        .endMetadata()
        .withNewStatus()
        .withPhase("Running")
        .endStatus()
        .endItem().build();
}
 
Example #20
Source File: KubernetesClientTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void before() {
    Pod pod1 = new PodBuilder().withNewMetadata().withName("pod1").withNamespace("test").and().build();
    Pod pod2 = new PodBuilder().withNewMetadata().withName("pod2").withNamespace("test").and().build();

    mockServer.expect().get().withPath("/api/v1/namespaces/test/pods")
            .andReturn(200,
                    new PodListBuilder().withNewMetadata().withResourceVersion("1").endMetadata().withItems(pod1, pod2)
                            .build())
            .always();

    mockServer.expect().get().withPath("/api/v1/namespaces/test/pods/pod1")
            .andReturn(200, pod1)
            .always();

    mockServer.expect().delete().withPath("/api/v1/namespaces/test/pods/pod1")
            .andReturn(200, "{}")
            .once();

    // it doesn't really matter what we return here, we just need to return a Pod to make sure
    // deserialization works
    mockServer.expect().put().withPath("/api/v1/namespaces/test/pods/pod1").andReturn(200, new PodBuilder()
            .withNewMetadata().withName("pod1").addToLabels("key1", "value1").endMetadata().build()).once();

    // same here, the content itself doesn't really matter
    mockServer.expect().post().withPath("/api/v1/namespaces/test/pods").andReturn(201, new PodBuilder()
            .withNewMetadata().withResourceVersion("54321").and().build()).once();
}
 
Example #21
Source File: PortForwardServiceTest.java    From jkube with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testSimpleScenario() throws Exception {
    // Cannot test more complex scenarios due to errors in mockwebserver
    OpenShiftMockServer mockServer = new OpenShiftMockServer(false);

    Pod pod1 = new PodBuilder()
            .withNewMetadata()
            .withName("mypod")
            .addToLabels("mykey", "myvalue")
            .withResourceVersion("1")
            .endMetadata()
            .withNewStatus()
            .withPhase("run")
            .endStatus()
            .build();

    PodList pods1 = new PodListBuilder()
            .withItems(pod1)
            .withNewMetadata()
            .withResourceVersion("1")
            .endMetadata()
            .build();

    mockServer.expect().get().withPath("/api/v1/namespaces/test/pods?labelSelector=mykey%3Dmyvalue").andReturn(200, pods1).always();
    mockServer.expect().get().withPath("/api/v1/namespaces/test/pods").andReturn(200, pods1).always();
    mockServer.expect().get().withPath("/api/v1/namespaces/test/pods?labelSelector=mykey%3Dmyvalue&watch=true")
            .andUpgradeToWebSocket().open()
            .waitFor(1000)
            .andEmit(new WatchEvent(pod1, "MODIFIED"))
            .done().always();

    mockServer.expect().get().withPath("/api/v1/namespaces/test/pods?resourceVersion=1&watch=true")
            .andUpgradeToWebSocket().open()
            .waitFor(1000)
            .andEmit(new WatchEvent(pod1, "MODIFIED"))
            .done().always();

    OpenShiftClient client = mockServer.createOpenShiftClient();
    PortForwardService service = new PortForwardService(client, logger) {
        @Override
        public ProcessUtil.ProcessExecutionContext forwardPortAsync(KitLogger externalProcessLogger, String pod, String namespace, int remotePort, int localPort) throws JKubeServiceException {
            return new ProcessUtil.ProcessExecutionContext(process, Collections.<Thread>emptyList(), logger);
        }
    };

    try (Closeable c = service.forwardPortAsync(logger, new LabelSelectorBuilder().withMatchLabels(Collections.singletonMap("mykey", "myvalue")).build(), 8080, 9000)) {
        Thread.sleep(3000);
    }
}
 
Example #22
Source File: PodTest.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Test
public void testWatch() throws InterruptedException {
  //We start with a list
  Pod pod1 = new PodBuilder()
          .withNewMetadata()
          .withName("pod1")
          .withResourceVersion("1")
          .endMetadata()
          .build();

 server.expect().withPath("/api/v1/namespaces/test/pods").andReturn(200, new PodListBuilder()
          .withNewMetadata()
              .withResourceVersion("1")
          .endMetadata()
          .addToItems(pod1)
          .build()
  ).once();

 server.expect().withPath("/api/v1/namespaces/test/pods?fieldSelector=metadata.name%3Dpod1&watch=true")
          .andUpgradeToWebSocket()
          .open()
          .waitFor(15000).andEmit(new WatchEvent(pod1, "DELETED"))
          .done()
          .always();

  KubernetesClient client = server.getClient();

  final CountDownLatch deleteLatch = new CountDownLatch(1);
  Watch watch = client.pods().withName("pod1").watch(new Watcher<Pod>() {
    @Override
    public void eventReceived(Action action, Pod resource) {
      switch (action) {
        case DELETED:
          deleteLatch.countDown();
      }
    }

    @Override
    public void onClose(KubernetesClientException cause) {

    }
  });

  assertTrue(deleteLatch.await(10, TimeUnit.MINUTES));
}
 
Example #23
Source File: PodTest.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Test
public void testWait() throws InterruptedException {
  Pod notReady = new PodBuilder()
    .withNewMetadata()
    .withName("pod1")
    .withResourceVersion("1")
    .withNamespace("test")
    .endMetadata()
    .withNewStatus()
    .addNewCondition()
    .withType("Ready")
    .withStatus("False")
    .endCondition()
    .endStatus()
    .build();


  Pod ready = new PodBuilder()
    .withNewMetadata()
    .withName("pod1")
    .withResourceVersion("2")
    .withNamespace("test")
    .endMetadata()
    .withNewStatus()
    .addNewCondition()
    .withType("Ready")
    .withStatus("True")
    .endCondition()
    .endStatus()
    .build();

  server.expect().get().withPath("/api/v1/namespaces/test/pods/pod1").andReturn(200, notReady).once();
  server.expect().get().withPath("/api/v1/namespaces/test/pods/pod1").andReturn(200, ready).once();

  server.expect().get().withPath("/api/v1/namespaces/test/pods").andReturn(200, new PodListBuilder()
    .withNewMetadata()
    .withResourceVersion("1")
    .endMetadata()
    .withItems(notReady).build()).once();

  server.expect().get().withPath("/api/v1/namespaces/test/pods?fieldSelector=metadata.name%3Dpod1&resourceVersion=1&watch=true").andUpgradeToWebSocket()
    .open()
    .waitFor(1000).andEmit(new WatchEvent(ready, "MODIFIED"))
    .done()
    .always();

  KubernetesClient client = server.getClient();
  Pod result = client.pods().withName("pod1").waitUntilReady(5, TimeUnit.SECONDS);
  Assert.assertEquals("2", result.getMetadata().getResourceVersion());
}
 
Example #24
Source File: KubernetesHandlerTest.java    From apollo with Apache License 2.0 4 votes vote down vote up
private static void setMockPodLogsAndStatus(RealDeploymentGenerator realDeploymentGenerator,
                                            String log, PodStatus podStatus, ApolloToKubernetes apolloToKubernetes) {

    String containerName = podStatus.getName() + "-container";
    Pod pod = new PodBuilder()
            .withNewMetadata()
            .withName(podStatus.getName())
            .endMetadata()
            .withNewSpec()
            .withContainers(
                    new ContainerBuilder()
                            .withName(containerName)
                            .build()
            )
            .endSpec()
            .withNewStatus()
            .withHostIP(podStatus.getHostIp())
            .withPodIP(podStatus.getPodIp())
            .withPhase(podStatus.getPhase())
            .withReason(podStatus.getReason())
            .withStartTime(podStatus.getStartTime())
            .endStatus()
            .build();

    server.expect()
          .get()
          .withPath(String.format("/api/v1/namespaces/%s/pods?labelSelector=%s",
                  realDeploymentGenerator.getEnvironment().getKubernetesNamespace(),
                  getUrlEscapedLabel(ApolloToKubernetes.getApolloDeploymentUniqueIdentifierKey(),
                          apolloToKubernetes.getApolloDeploymentPodUniqueIdentifierValue())))
          .andReturn(HttpStatus.OK,
                  new PodListBuilder()
                          .withItems(pod)
                          .build()
          )
          .always();

    server.expect()
          .get()
          .withPath(String.format("/api/v1/namespaces/%s/pods/%s/log", realDeploymentGenerator.getEnvironment().getKubernetesNamespace(), podStatus.getName()))
          .andReturn(HttpStatus.OK, log)
          .always();

    server.expect()
          .get()
          .withPath(String.format("/api/v1/namespaces/%s/pods/%s", realDeploymentGenerator.getEnvironment().getKubernetesNamespace(), podStatus.getName()))
          .andReturn(HttpStatus.OK, pod)
          .always();
}
 
Example #25
Source File: Fabric8KubernetesClientTest.java    From styx with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);

  sut = Fabric8KubernetesClient.of(client);

  pod = new PodBuilder()
      .withNewMetadata()
      .withName(POD_NAME)
      .endMetadata()
      .build();
  createdPod = new PodBuilder()
      .withNewMetadata()
      .withName(POD_NAME)
      .withUid(POD_UID)
      .endMetadata()
      .build();
  podList = new PodListBuilder()
      .withNewMetadata().withResourceVersion(POD_LIST_RESOURCE_VERSION).endMetadata()
      .withItems(new ArrayList<>())
      .build();
  podList.getMetadata().setResourceVersion("baz");

  secret = new SecretBuilder()
      .withNewMetadata()
      .withName(SECRET_NAME)
      .endMetadata()
      .build();
  createdSecret = new SecretBuilder()
      .withNewMetadata()
      .withName(SECRET_NAME)
      .withUid(SECRET_UID)
      .endMetadata()
      .build();
  secretList = new SecretListBuilder()
      .withNewMetadata().withResourceVersion(SECRET_LIST_RESOURCE_VERSION).endMetadata()
      .withItems(new ArrayList<>())
      .build();
  secretList.getMetadata().setResourceVersion("baz");

  when(client.pods()).thenReturn(pods);
  when(pods.withName(any())).thenReturn(namedPod);
  when(pods.list()).thenReturn(podList);
  when(pods.watch(any())).thenReturn(watch);
  when(client.secrets()).thenReturn(secrets);
  when(secrets.withName(any())).thenReturn(namedSecret);
  when(secrets.list()).thenReturn(secretList);
}