Java Code Examples for io.fabric8.kubernetes.api.model.ConfigMap#setMetadata()

The following examples show how to use io.fabric8.kubernetes.api.model.ConfigMap#setMetadata() . 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: ConfigMapLockTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
void getWithExistingConfigMapShouldReturnLeaderElectionRecord() {
  // Given
  final ConfigMap cm = new ConfigMap();
  when(configMaps.withName(eq("name")).get()).thenReturn(cm);
  cm.setMetadata(new ObjectMetaBuilder()
    .withAnnotations(
      Collections.singletonMap("control-plane.alpha.kubernetes.io/leader",
        "{\"holderIdentity\":\"1337\",\"leaseDuration\":15,\"acquireTime\":1445401740,\"renewTime\":1445412480}")
    )
    .withResourceVersion("313373").build());
  final ConfigMapLock lock = new ConfigMapLock("namespace", "name", "1337");
  // When
  final LeaderElectionRecord result = lock.get(kc);
  // Then
  assertNotNull(result);
  assertEquals("313373", result.getVersion());
  assertEquals("1337", result.getHolderIdentity());
  assertEquals(15, result.getLeaseDuration().getSeconds());
  assertEquals(ZonedDateTime.of(2015, 10, 21, 4, 29, 0, 0, ZoneId.of("UTC")), result.getAcquireTime());
}
 
Example 2
Source File: ConfigMapLockTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
void updateWithValidLeaderElectionRecordShouldSendPutRequest() throws Exception {
  // Given
  final Resource<ConfigMap, ?> configMapResource = configMaps.withName("name");
  final Replaceable<ConfigMap, ConfigMap> replaceable = mock(Replaceable.class, Answers.RETURNS_DEEP_STUBS);
  when(configMapResource.lockResourceVersion(any())).thenReturn(replaceable);
  final ConfigMap configMapInTheCluster = new ConfigMap();
  configMapInTheCluster.setMetadata(new ObjectMetaBuilder().withAnnotations(new HashMap<>()).build());
  when(configMapResource.get()).thenReturn(configMapInTheCluster);
  final LeaderElectionRecord record = new LeaderElectionRecord(
    "1337", Duration.ofSeconds(1), ZonedDateTime.now(), ZonedDateTime.now(), 0);
  record.setVersion("313373");
  final ConfigMapLock lock = new ConfigMapLock("namespace", "name", "1337");
  // When
  lock.update(kc, record);
  // Then
  verify(replaceable, times(1)).replace(eq(configMapInTheCluster));
}
 
Example 3
Source File: KubernetesAppDeployerIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
private ConfigMap randomConfigMap() {
	Map<String, String> configMapData = new HashMap<>();
	configMapData.put("d-" + UUID.randomUUID().toString().substring(0, 5), "value1");
	configMapData.put("d-" + UUID.randomUUID().toString().substring(0, 5), "value2");

	ConfigMap configMap = new ConfigMap();
	configMap.setData(configMapData);

	ObjectMeta objectMeta = new ObjectMeta();
	objectMeta.setName("cm-" + UUID.randomUUID().toString().substring(0, 5));

	configMap.setMetadata(objectMeta);

	return kubernetesClient.configMaps().create(configMap);
}