Java Code Examples for io.fabric8.kubernetes.api.model.Pod#setStatus()

The following examples show how to use io.fabric8.kubernetes.api.model.Pod#setStatus() . 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: KubernetesLanderTest.java    From data-highway with Apache License 2.0 6 votes vote down vote up
@Test
public void successfulPodCompletion() throws Exception {
  when(podNameFactory.newName(any(LanderConfiguration.class))).thenReturn("pod-name");
  when(podResource.watch(podWatcherCaptor.capture())).thenReturn(watch);
  when(client.pods()).thenReturn(mixedOperation);
  when(mixedOperation.withName(anyString())).thenReturn(podResource);
  Pod pod = new Pod();
  when(podResource.get()).thenReturn(pod);
  KubernetesLander.Factory factory = new KubernetesLander.Factory(argsFactory, podFactory, podNameFactory, client);
  LanderConfiguration config = new LanderConfiguration("road", "topic", ImmutableMap.of(), "s3Prefix", false,
      "partitionColumnValue", false);
  when(argsFactory.newInstance(config)).thenReturn(ARGS);
  when(podFactory.newInstance(config, ARGS)).thenReturn(pod);
  Lander lander = factory.newInstance(config);
  CompletableFuture<LanderConfiguration> future = lander.run();
  verify(podResource).delete();
  verify(mixedOperation).create(pod);

  pod.setStatus(terminatedPostStatus(0));
  podWatcherCaptor.getValue().eventReceived(null, pod); // trigger successful pod termination.
  assertThat(config, is(future.get()));
}
 
Example 2
Source File: KubernetesLanderTest.java    From data-highway with Apache License 2.0 6 votes vote down vote up
@Test
public void nonZeroExitCode() throws Exception {
  when(podNameFactory.newName(any(LanderConfiguration.class))).thenReturn("pod-name");
  when(podResource.watch(podWatcherCaptor.capture())).thenReturn(watch);
  when(client.pods()).thenReturn(mixedOperation);
  when(mixedOperation.withName(anyString())).thenReturn(podResource);
  Pod pod = new Pod();
  when(podResource.get()).thenReturn(pod);
  KubernetesLander.Factory factory = new KubernetesLander.Factory(argsFactory, podFactory, podNameFactory, client);
  LanderConfiguration config = new LanderConfiguration("road", "topic", ImmutableMap.of(), "s3Prefix", false,
      "partitionColumnValue", false);
  when(argsFactory.newInstance(config)).thenReturn(ARGS);
  when(podFactory.newInstance(config, ARGS)).thenReturn(pod);
  Lander lander = factory.newInstance(config);
  CompletableFuture<LanderConfiguration> run = lander.run();
  verify(podResource).delete();
  verify(mixedOperation).create(pod);

  pod.setStatus(terminatedPostStatus(1));
  podWatcherCaptor.getValue().eventReceived(null, pod);
  assertThat(run.isCompletedExceptionally(), is(true));
}
 
Example 3
Source File: KubernetesGCPServiceAccountSecretManagerTest.java    From styx with Apache License 2.0 6 votes vote down vote up
@Test
@Parameters({"Failed", "Succeeded"})
public void shouldRemoveServiceAccountSecretsAndKeysUsedByTerminatedPods(String phase) throws Exception {
  final Secret secret = fakeServiceAccountKeySecret(
      SERVICE_ACCOUNT, SECRET_EPOCH, "json-key", "p12-key", EXPIRED_CREATION_TIMESTAMP.toString());

  when(secretList.getItems()).thenReturn(List.of(secret));

  final KubernetesSecretSpec secretSpec = KubernetesSecretSpec.builder()
      .serviceAccountSecret(secret.getMetadata().getName())
      .build();
  final Pod pod = createPod(WORKFLOW_INSTANCE, RUN_SPEC_WITH_SA, secretSpec);

  final PodStatus podStatus = podStatus(phase);
  pod.setStatus(podStatus);

  sut.cleanup();
  verify(serviceAccountKeyManager).deleteKey(keyName(SERVICE_ACCOUNT, "json-key"));
  verify(serviceAccountKeyManager).deleteKey(keyName(SERVICE_ACCOUNT, "p12-key"));
  verify(k8sClient).deleteSecret(secret.getMetadata().getName());
  verify(stats).recordServiceAccountCleanup();
}
 
Example 4
Source File: KubernetesGCPServiceAccountSecretManagerTest.java    From styx with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotRemoveServiceAccountSecretsAndKeysInUse() throws Exception {
  final Secret secret = fakeServiceAccountKeySecret(
      SERVICE_ACCOUNT, SECRET_EPOCH, "json-key", "p12-key", EXPIRED_CREATION_TIMESTAMP.toString());

  when(secretList.getItems()).thenReturn(List.of(secret));

  final KubernetesSecretSpec secretSpec = KubernetesSecretSpec.builder()
      .serviceAccountSecret(secret.getMetadata().getName())
      .build();
  final Pod pod = createPod(WORKFLOW_INSTANCE, RUN_SPEC_WITH_SA, secretSpec);
  pod.setStatus(podStatus("Running"));
  when(podList.getItems()).thenReturn(List.of(pod));
  sut.cleanup();
  verify(serviceAccountKeyManager, never()).deleteKey(anyString());
  verify(k8sClient, never()).deleteSecret(any());
  verify(stats, never()).recordServiceAccountCleanup();
}
 
Example 5
Source File: KubernetesDockerRunnerPodPollerTest.java    From styx with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldDeleteUnwantedStyxPods() {
  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(podStatus1);
  when(podStatus1.getContainerStatuses()).thenReturn(List.of(containerStatus1));
  when(containerStatus1.getName()).thenReturn(RUN_SPEC.executionId());

  createdPod2.setStatus(podStatus2);
  when(podStatus2.getContainerStatuses()).thenReturn(List.of(containerStatus2));
  when(containerStatus2.getName()).thenReturn(RUN_SPEC_2.executionId());

  kdr.tryCleanupPods();

  verify(k8sClient).deletePod(createdPod1.getMetadata().getName());
  verify(k8sClient).deletePod(createdPod2.getMetadata().getName());
}
 
Example 6
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 7
Source File: K8sPodManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
private static Pod createK8sPod(String uid, String name) {
    ObjectMeta meta = new ObjectMeta();
    meta.setUid(uid);
    meta.setName(name);

    PodStatus status = new PodStatus();
    status.setPhase("Running");

    Pod pod = new Pod();
    pod.setApiVersion("v1");
    pod.setKind("pod");
    pod.setMetadata(meta);
    pod.setStatus(status);

    return pod;
}
 
Example 8
Source File: KubernetesDockerRunnerPodPollerTest.java    From styx with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotDeleteWantedStyxPods() {
  final Pod createdPod1 = createPod(WORKFLOW_INSTANCE, RUN_SPEC, SECRET_SPEC);
  final Pod createdPod2 = createPod(WORKFLOW_INSTANCE_2, RUN_SPEC_2, SECRET_SPEC);

  createdPod1.setStatus(podStatus1);
  createdPod2.setStatus(podStatus2);
  podList.setItems(Arrays.asList(createdPod1, createdPod2));

  setupActiveInstances(RunState.State.RUNNING, RUN_SPEC.executionId(), RUN_SPEC_2.executionId());

  kdr.tryCleanupPods();

  verify(k8sClient, never()).deletePod(any());
}
 
Example 9
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 10
Source File: KubernetesPodEventTranslatorTest.java    From styx with Apache License 2.0 4 votes vote down vote up
static void setRunning(Pod pod, boolean ready) {
  pod.setStatus(running(ready));
}
 
Example 11
Source File: KubernetesPodEventTranslatorTest.java    From styx with Apache License 2.0 4 votes vote down vote up
static void setTerminated(Pod pod, String phase, Integer exitCode, String message) {
  pod.setStatus(terminated(phase, exitCode, message));
}
 
Example 12
Source File: KubernetesPodEventTranslatorTest.java    From styx with Apache License 2.0 4 votes vote down vote up
static void setWaiting(Pod pod, String phase, String reason) {
  pod.setStatus(waiting(phase, reason));
}
 
Example 13
Source File: KubernetesPodEventTranslatorTest.java    From styx with Apache License 2.0 4 votes vote down vote up
static void setWaiting(Pod pod, String phase, String reason, String message) {
  pod.setStatus(waiting(phase, reason, message));
}