Java Code Examples for io.fabric8.kubernetes.api.model.ObjectMeta#setCreationTimestamp()

The following examples show how to use io.fabric8.kubernetes.api.model.ObjectMeta#setCreationTimestamp() . 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: ServerPingRequestExecutorTest.java    From kubernetes-elastic-agents with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    initMocks(this);
    when(factory.client(any())).thenReturn(mockedClient);
    when(mockedClient.pods()).thenReturn(mockedOperation);
    when(mockedOperation.create(any(Pod.class))).thenAnswer(new Answer<Pod>() {
        @Override
        public Pod answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            return (Pod) args[0];
        }
    });

    when(mockedOperation.withName(anyString())).thenReturn(podResource);
    when(podResource.get()).thenReturn(mockedPod);

    objectMetadata = new ObjectMeta();
    objectMetadata.setCreationTimestamp(getSimpleDateFormat().format(new Date()));

    when(mockedPod.getMetadata()).thenReturn(objectMetadata);

    final PodList podList = mock(PodList.class);
    when(mockedOperation.list()).thenReturn(podList);
    when(podList.getItems()).thenReturn(Collections.emptyList());
}
 
Example 2
Source File: KubernetesGCPServiceAccountSecretManagerTest.java    From styx with Apache License 2.0 6 votes vote down vote up
private static Secret fakeServiceAccountKeySecret(String serviceAccount, long epoch, String jsonKeyId,
    String p12KeyId, String creationTimestamp) {
  final String jsonKeyName = keyName(serviceAccount, jsonKeyId);
  final String p12KeyName = keyName(serviceAccount, p12KeyId);

  final ObjectMeta metadata = new ObjectMeta();
  metadata.setCreationTimestamp(creationTimestamp);
  metadata.setName("styx-wf-sa-keys-" + epoch + "-" + Hashing.sha256().hashString(serviceAccount, UTF_8));
  metadata.setAnnotations(Map.of(
      "styx-wf-sa", serviceAccount,
      "styx-wf-sa-json-key-name", jsonKeyName,
      "styx-wf-sa-p12-key-name", p12KeyName));

  return new SecretBuilder()
      .withMetadata(metadata)
      .withData(Map.of(
          "styx-wf-sa.json", "json-private-key-data",
          "styx-wf-sa.p12", "p12-private-key-data"))
      .build();
}
 
Example 3
Source File: ServerPingRequestExecutorTest.java    From kubernetes-elastic-agents with Apache License 2.0 4 votes vote down vote up
@Test
public void testShouldTerminateUnregisteredInstances_forSingleCluster() throws Exception {
    String unregisteredAgentId1 = "unregisteredAgentId1-" + UUID.randomUUID().toString();
    String unregisteredAgentId2 = "unregisteredAgentId2-" + UUID.randomUUID().toString();

    long time = Calendar.getInstance().getTimeInMillis();
    Pod mockedPod = mock(Pod.class);
    when(mockedOperation.withName(anyString())).thenReturn(podResource);
    when(podResource.get()).thenReturn(mockedPod);
    objectMetadata = new ObjectMeta();
    objectMetadata.setLabels(Collections.singletonMap(JOB_ID_LABEL_KEY, "20"));
    objectMetadata.setName(unregisteredAgentId1);
    objectMetadata.setCreationTimestamp(getSimpleDateFormat().format(new Date(time - (20 * 60000))));

    when(mockedPod.getMetadata()).thenReturn(objectMetadata);

    ClusterProfileProperties clusterProfilePropertiesForCluster1 = new ClusterProfileProperties("https://localhost:8154/go", null, null);

    KubernetesInstance k8sUnregisteredCluster1Pod1 = new KubernetesInstance(new DateTime().minusMinutes(100), null, unregisteredAgentId1, Collections.emptyMap(), 3L, PodState.Running);
    KubernetesInstance k8sUnregisteredCluster1Pod2 = new KubernetesInstance(new DateTime(), null, unregisteredAgentId2, Collections.emptyMap(), 3L, PodState.Running);

    final Agents allAgentsInitially = new Agents();

    KubernetesAgentInstances agentInstancesForCluster1 = new KubernetesAgentInstances(factory);
    agentInstancesForCluster1.register(k8sUnregisteredCluster1Pod1);
    agentInstancesForCluster1.register(k8sUnregisteredCluster1Pod2);

    HashMap<String, KubernetesAgentInstances> clusterSpecificInstances = new HashMap<>();
    clusterSpecificInstances.put(clusterProfilePropertiesForCluster1.uuid(), agentInstancesForCluster1);

    ServerPingRequest serverPingRequest = mock(ServerPingRequest.class);
    when(serverPingRequest.allClusterProfileProperties()).thenReturn(Arrays.asList(clusterProfilePropertiesForCluster1));

    PluginRequest pluginRequest = mock(PluginRequest.class);

    when(pluginRequest.listAgents()).thenReturn(allAgentsInitially);

    assertTrue(clusterSpecificInstances.get(clusterProfilePropertiesForCluster1.uuid()).hasInstance(k8sUnregisteredCluster1Pod1.name()));
    assertTrue(clusterSpecificInstances.get(clusterProfilePropertiesForCluster1.uuid()).hasInstance(k8sUnregisteredCluster1Pod2.name()));

    new ServerPingRequestExecutor(serverPingRequest, clusterSpecificInstances, pluginRequest).execute();

    assertFalse(clusterSpecificInstances.get(clusterProfilePropertiesForCluster1.uuid()).hasInstance(k8sUnregisteredCluster1Pod1.name()));
    assertTrue(clusterSpecificInstances.get(clusterProfilePropertiesForCluster1.uuid()).hasInstance(k8sUnregisteredCluster1Pod2.name()));
}