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

The following examples show how to use io.fabric8.kubernetes.api.model.PodStatusBuilder. 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: KubernetesDockerRunnerPodPollerTest.java    From styx with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotDeleteUnwantedStyxPodsIfDebugEnabled() {
  when(debug.get()).thenReturn(true);

  final Pod createdPod1 = createPod(WORKFLOW_INSTANCE, RUN_SPEC, SECRET_SPEC);
  final Pod createdPod2 = createPod(WORKFLOW_INSTANCE_2, RUN_SPEC_2, SECRET_SPEC);

  podList.setItems(Arrays.asList(createdPod1, createdPod2));
  when(k8sClient.getPod(RUN_SPEC.executionId())).thenReturn(Optional.of(createdPod1));
  when(k8sClient.getPod(RUN_SPEC_2.executionId())).thenReturn(Optional.of(createdPod2));
  createdPod1.setStatus(new PodStatusBuilder().withContainerStatuses().build());
  createdPod2.setStatus(new PodStatusBuilder().withContainerStatuses().build());

  kdr.tryCleanupPods();

  verify(k8sClient, never()).deletePod(any());
}
 
Example #2
Source File: KubeCloudInstanceImplTest.java    From teamcity-kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetStartedTime() throws Exception {
    KubeCloudImage image = m.mock(KubeCloudImage.class);
    ObjectMeta metadata = new ObjectMeta();
    metadata.setName("foo");
    Pod pod = new Pod("1.0", "kind", metadata, new PodSpec(), new PodStatusBuilder().withStartTime("2017-06-12T22:59Z").build());
    m.checking(new Expectations(){{
        allowing(myApi).getPodStatus(with("foo")); will(returnValue(pod.getStatus()));
    }});
    KubeCloudInstanceImpl instance = new KubeCloudInstanceImpl(image, pod);
    Date startedTime = instance.getStartedTime();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    assertEquals("2017-06-12T22:59Z", dateFormat.format(startedTime));
}
 
Example #3
Source File: KubernetesDockerRunnerTest.java    From styx with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotCleanupRunningPodWithoutRunStateIfTerminatedAfterRefresh() {
  final ContainerStatus runningMainContainer = new ContainerStatusBuilder()
      .withName(MAIN_CONTAINER_NAME)
      .withNewState().withNewRunning().endRunning().endState()
      .build();

  final ContainerStatus terminatedMainContainer = new ContainerStatusBuilder()
      .withName(MAIN_CONTAINER_NAME)
      .withNewState()
      .withNewTerminated()
      .withFinishedAt(FIXED_INSTANT.minus(Duration.ofDays(1)).toString())
      .endTerminated()
      .endState()
      .build();

  createdPod.setStatus(new PodStatusBuilder()
      .withContainerStatuses(runningMainContainer, keepaliveContainerStatus)
      .build());

  final Pod refreshedPod = new PodBuilder(createdPod)
      .withStatus(new PodStatusBuilder()
          .withContainerStatuses(terminatedMainContainer, keepaliveContainerStatus)
          .build())
      .build();

  // Return terminated container when refreshing by name
  when(k8sClient.getPod(POD_NAME)).thenReturn(Optional.of(refreshedPod));

  var shouldDelete = kdr.shouldDeletePodWithoutRunState(WORKFLOW_INSTANCE, createdPod);

  // Leave the pod to expire and be deleted by a later poll tick
  assertThat(shouldDelete, is(false));
}
 
Example #4
Source File: KubernetesResourceManagerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
void terminatePod(Pod pod) {
	pod.setStatus(new PodStatusBuilder()
		.withContainerStatuses(new ContainerStatusBuilder().withState(
			new ContainerStateBuilder().withNewTerminated().endTerminated().build())
			.build())
		.build());
}
 
Example #5
Source File: KubernetesPodEventTranslatorTest.java    From styx with Apache License 2.0 4 votes vote down vote up
static PodStatus podStatusNoContainer(String phase) {
  return new PodStatusBuilder()
      .withPhase(phase)
      .build();
}
 
Example #6
Source File: PodRetentionTest.java    From kubernetes-plugin with Apache License 2.0 4 votes vote down vote up
private PodStatus buildStatus(String phase) {
    return new PodStatusBuilder().withPhase(phase).build();
}