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

The following examples show how to use io.fabric8.kubernetes.api.model.ConfigMap. 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: KubernetesJobManagerFactoryTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testHadoopConfConfigMap() throws IOException {
	setHadoopConfDirEnv();
	generateHadoopConfFileItems();
	kubernetesJobManagerSpecification = KubernetesJobManagerFactory.buildKubernetesJobManagerSpecification(kubernetesJobManagerParameters);

	final ConfigMap resultConfigMap = (ConfigMap) kubernetesJobManagerSpecification.getAccompanyingResources()
		.stream()
		.filter(x -> x instanceof ConfigMap &&
			x.getMetadata().getName().equals(HadoopConfMountDecorator.getHadoopConfConfigMapName(CLUSTER_ID)))
		.collect(Collectors.toList())
		.get(0);

	assertEquals(2, resultConfigMap.getMetadata().getLabels().size());

	final Map<String, String> resultDatas = resultConfigMap.getData();
	assertEquals(2, resultDatas.size());
	assertEquals("some data", resultDatas.get("core-site.xml"));
	assertEquals("some data", resultDatas.get("hdfs-site.xml"));
}
 
Example #2
Source File: UniqueNamesProvisionerTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void rewritePodConfigMapVolumes() throws Exception {
  when(runtimeIdentity.getWorkspaceId()).thenReturn(WORKSPACE_ID);

  ConfigMap configMap = newConfigMap();
  doReturn(ImmutableMap.of(CONFIGMAP_NAME, configMap)).when(k8sEnv).getConfigMaps();

  Volume volume =
      new VolumeBuilder().withNewConfigMap().withName(CONFIGMAP_NAME).endConfigMap().build();
  Pod pod = newPod();
  pod.getSpec().setVolumes(ImmutableList.of(volume));
  PodData podData = new PodData(pod.getSpec(), pod.getMetadata());
  doReturn(ImmutableMap.of(POD_NAME, podData)).when(k8sEnv).getPodsData();

  uniqueNamesProvisioner.provision(k8sEnv, runtimeIdentity);

  String newConfigMapName = configMap.getMetadata().getName();
  Volume newVolume = pod.getSpec().getVolumes().iterator().next();
  assertEquals(newVolume.getConfigMap().getName(), newConfigMapName);
}
 
Example #3
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 #4
Source File: ConfigMapPropertySource.java    From spring-cloud-kubernetes with Apache License 2.0 6 votes vote down vote up
private static Map<String, String> getData(KubernetesClient client, String name, String namespace) {
    Map<String, String> result = new HashMap<>();
    try {
        ConfigMap map = namespace == null || namespace.isEmpty()
                ? client.configMaps().withName(name).get()
                : client.configMaps().inNamespace(namespace).withName(name).get();

        if (map != null) {
            for (Map.Entry<String, String> entry : map.getData().entrySet()) {
                String key = entry.getKey();
                String value = entry.getValue();
                if (key.equals(APPLICATION_YAML) || key.equals(APPLICATION_YML)) {
                    result.putAll(YAML_TO_PROPETIES.andThen(PROPERTIES_TO_MAP).apply(value));
                } else if (key.equals(APPLICATION_PROPERTIES)) {
                    result.putAll(KEY_VALUE_TO_PROPERTIES.andThen(PROPERTIES_TO_MAP).apply(value));
                } else {
                    result.put(key, value);
                }
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Can't read configMap with name: [" + name + "] in namespace:[" + namespace + "]. Ignoring");
    }
    return result;
}
 
Example #5
Source File: ConfigMapEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void should_materialize_binary_file_content_from_annotation() throws Exception {
    final ConfigMap baseConfigMap = createAnnotationConfigMap("test.bin", "src/test/resources/test.bin");
    final KubernetesListBuilder builder = new KubernetesListBuilder()
            .addToConfigMapItems(baseConfigMap);
    new ConfigMapEnricher(context).create(PlatformMode.kubernetes, builder);

    final ConfigMap configMap = (ConfigMap) builder.buildFirstItem();

    final Map<String, String> data = configMap.getData();
    assertThat(data)
            .isEmpty();

    final Map<String, String> binaryData = configMap.getBinaryData();
    assertThat(binaryData)
            .containsEntry("test.bin", "wA==");

    final Map<String, String> annotations = configMap.getMetadata().getAnnotations();
    assertThat(annotations)
            .isEmpty();
}
 
Example #6
Source File: ConfigMapSupplier.java    From data-highway with Apache License 2.0 6 votes vote down vote up
@Override
public void eventReceived(Action action, ConfigMap configMap) {
  synchronized (lock) {
    switch (action) {
    case MODIFIED:
      log.info("ConfigMap {} was modified. {}", name, configMap);
      this.configMap = configMap;
      break;
    case ADDED:
      log.warn("ConfigMap {} should never be ADDED during lifetime of this instance.", name);
      this.configMap = configMap;
      break;
    case DELETED:
      log.warn("ConfigMap {} should never be DELETED during lifetime of this instance.", name);
      this.configMap = null;
      break;
    case ERROR:
      throw new RuntimeException(String.format("An unknown error occurred with ConfigMap %s.", name));
    default:
      throw new RuntimeException("Unknown Action:" + action.name());
    }
  }
}
 
Example #7
Source File: UniqueNamesProvisionerTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void rewritePodConfigMapEnvFrom() throws Exception {
  when(runtimeIdentity.getWorkspaceId()).thenReturn(WORKSPACE_ID);

  ConfigMap configMap = newConfigMap();
  doReturn(ImmutableMap.of(CONFIGMAP_NAME, configMap)).when(k8sEnv).getConfigMaps();

  EnvFromSource envFrom =
      new EnvFromSourceBuilder()
          .withNewConfigMapRef()
          .withName(CONFIGMAP_NAME)
          .endConfigMapRef()
          .build();
  Container container = new ContainerBuilder().withEnvFrom(envFrom).build();
  Pod pod = newPod();
  pod.getSpec().setContainers(ImmutableList.of(container));
  PodData podData = new PodData(pod.getSpec(), pod.getMetadata());
  doReturn(ImmutableMap.of(POD_NAME, podData)).when(k8sEnv).getPodsData();

  uniqueNamesProvisioner.provision(k8sEnv, runtimeIdentity);

  String newConfigMapName = configMap.getMetadata().getName();
  EnvFromSource newEnvFromSource = container.getEnvFrom().iterator().next();
  assertEquals(newEnvFromSource.getConfigMapRef().getName(), newConfigMapName);
}
 
Example #8
Source File: PatchServiceTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testInvalidPatcherKind() {
    ConfigMap oldResource = new ConfigMapBuilder()
            .withNewMetadata().withName("configmap1").endMetadata()
            .addToData(Collections.singletonMap("foo", "bar"))
            .build();
    ConfigMap newResource = new ConfigMapBuilder()
            .withNewMetadata().withName("configmap1").endMetadata()
            .addToData(Collections.singletonMap("FOO", "BAR"))
            .build();

    OpenShiftClient client = mockServer.createOpenShiftClient();
    PatchService patchService = new PatchService(client, log);

    patchService.compareAndPatchEntity("test", newResource, oldResource);
}
 
Example #9
Source File: SshKeysProvisioner.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
private void doProvisionVcsSshConfig(
    List<SshPairImpl> vcsSshPairs, KubernetesEnvironment k8sEnv, String wsId) {
  StringBuilder sshConfigData = new StringBuilder();
  for (SshPair sshPair : vcsSshPairs) {
    sshConfigData.append(buildConfig(sshPair.getName()));
  }

  String sshConfigMapName = wsId + SSH_CONFIG_MAP_NAME_SUFFIX;

  Map<String, String> sshConfig = new HashMap<>();
  sshConfig.put(SSH_CONFIG, sshConfigData.toString());
  ConfigMap configMap =
      new ConfigMapBuilder()
          .withNewMetadata()
          .withName(sshConfigMapName)
          .endMetadata()
          .withData(sshConfig)
          .build();

  k8sEnv.getConfigMaps().put(configMap.getMetadata().getName(), configMap);
  k8sEnv
      .getPodsData()
      .values()
      .forEach(
          p -> mountConfigFile(p.getSpec(), sshConfigMapName, p.getRole() != PodRole.INJECTABLE));
}
 
Example #10
Source File: CreateOrReplaceResourceTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testReplaceWithoutLock() throws Exception {
  server.expect().get().withPath("/api/v1/namespaces/test/configmaps/map1").andReturn(200, new ConfigMapBuilder()
    .withNewMetadata().withResourceVersion("1000").and().build()).always();

  server.expect().put().withPath("/api/v1/namespaces/test/configmaps/map1").andReturn(200, new ConfigMapBuilder()
    .withNewMetadata().withResourceVersion("1001").and().build()).once();

  KubernetesClient client = server.getClient();
  ConfigMap map = client.configMaps().withName("map1").replace(new ConfigMapBuilder()
    .withNewMetadata().withName("map1").and().build());
  assertNotNull(map);
  assertEquals("1001", map.getMetadata().getResourceVersion());

  RecordedRequest request = server.getLastRequest();
  ConfigMap replacedMap = new ObjectMapper().readerFor(ConfigMap.class).readValue(request.getBody().inputStream());
  assertEquals("1000", replacedMap.getMetadata().getResourceVersion());
}
 
Example #11
Source File: OpenShiftEnvironment.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
public OpenShiftEnvironment(
    InternalRecipe internalRecipe,
    Map<String, InternalMachineConfig> machines,
    List<Warning> warnings,
    Map<String, Pod> pods,
    Map<String, Deployment> deployments,
    Map<String, Service> services,
    Map<String, Ingress> ingresses,
    Map<String, PersistentVolumeClaim> pvcs,
    Map<String, Secret> secrets,
    Map<String, ConfigMap> configMaps,
    Map<String, Route> routes) {
  super(
      internalRecipe,
      machines,
      warnings,
      pods,
      deployments,
      services,
      ingresses,
      pvcs,
      secrets,
      configMaps);
  setType(TYPE);
  this.routes = routes;
}
 
Example #12
Source File: WaitForConditionWatcherTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
void itCompletesExceptionallyWithRetryOnCloseNonGone() throws Exception {
  TrackingPredicate condition = condition(ss -> true);
  WaitForConditionWatcher<ConfigMap> watcher = new WaitForConditionWatcher<>(condition);
  watcher.onClose(new KubernetesClientException("test", 500, null));
  assertTrue(watcher.getFuture().isDone());
  try {
    watcher.getFuture().get();
    fail("should have thrown exception");
  } catch (ExecutionException e) {
    assertEquals(e.getCause().getClass(), WatchException.class);
    assertEquals(e.getCause().getMessage(), "Watcher closed");
    assertTrue(((WatchException) e.getCause()).isShouldRetry());
  }
  assertFalse(condition.isCalled());
}
 
Example #13
Source File: LeadershipController.java    From spring-cloud-kubernetes with Apache License 2.0 6 votes vote down vote up
public synchronized void update() {
	LOGGER.debug("Checking leader state");
	ConfigMap configMap = getConfigMap();
	Leader leader = extractLeader(configMap);

	if (leader != null && isPodReady(leader.getId())) {
		handleLeaderChange(leader);
		return;
	}

	if (leader != null && leader.isCandidate(this.candidate)) {
		revoke(configMap);
	}
	else {
		acquire(configMap);
	}
}
 
Example #14
Source File: KubernetesEnvironment.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
protected KubernetesEnvironment(
    InternalRecipe internalRecipe,
    Map<String, InternalMachineConfig> machines,
    List<Warning> warnings,
    Map<String, Pod> pods,
    Map<String, Deployment> deployments,
    Map<String, Service> services,
    Map<String, Ingress> ingresses,
    Map<String, PersistentVolumeClaim> persistentVolumeClaims,
    Map<String, Secret> secrets,
    Map<String, ConfigMap> configMaps) {
  super(internalRecipe, machines, warnings);
  setType(TYPE);
  this.pods = pods;
  this.deployments = deployments;
  this.services = services;
  this.ingresses = ingresses;
  this.persistentVolumeClaims = persistentVolumeClaims;
  this.secrets = secrets;
  this.configMaps = configMaps;
  this.podData = new HashMap<>();
  this.injectablePods = new HashMap<>();
  pods.forEach((name, pod) -> podData.put(name, new PodData(pod)));
  deployments.forEach((name, deployment) -> podData.put(name, new PodData(deployment)));
}
 
Example #15
Source File: ConfigMapHandler.java    From module-ballerina-kubernetes with Apache License 2.0 6 votes vote down vote up
private void generate(ConfigMapModel configMapModel) throws KubernetesPluginException {
    ConfigMap configMap = new ConfigMapBuilder()
            .withNewMetadata()
            .withName(configMapModel.getName())
            .withNamespace(dataHolder.getNamespace())
            .endMetadata()
            .withData(configMapModel.getData())
            .build();
    try {
        String configMapContent = SerializationUtils.dumpWithoutRuntimeStateAsYaml(configMap);
        KubernetesUtils.writeToFile(configMapContent, CONFIG_MAP_FILE_POSTFIX + YAML);
    } catch (IOException e) {
        String errorMessage = "Error while parsing yaml file for config map: " + configMapModel.getName();
        throw new KubernetesPluginException(errorMessage, e);
    }
}
 
Example #16
Source File: GitConfigProvisioner.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
private void doProvisionGitConfiguration(
    String gitConfigMapName, String gitConfig, KubernetesEnvironment k8sEnv) {
  Map<String, String> gitConfigData = singletonMap(GIT_CONFIG, gitConfig);
  ConfigMap configMap =
      new ConfigMapBuilder()
          .withNewMetadata()
          .withName(gitConfigMapName)
          .endMetadata()
          .withData(gitConfigData)
          .build();

  k8sEnv.getConfigMaps().put(configMap.getMetadata().getName(), configMap);
  k8sEnv
      .getPodsData()
      .values()
      .forEach(
          p -> mountConfigFile(p.getSpec(), gitConfigMapName, p.getRole() != PodRole.INJECTABLE));
}
 
Example #17
Source File: KafkaAssemblyOperator.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
ConfigMap getKafkaAncialiaryCm()    {
    ConfigMap loggingCm = null;

    if (kafkaCluster.getLogging() instanceof ExternalLogging) {
        loggingCm = configMapOperations.get(kafkaAssembly.getMetadata().getNamespace(), ((ExternalLogging) kafkaCluster.getLogging()).getName());
    }

    ConfigMap brokerCm = kafkaCluster.generateAncillaryConfigMap(loggingCm, kafkaExternalAdvertisedHostnames, kafkaExternalAdvertisedPorts);

    String brokerConfiguration = brokerCm.getData().get(KafkaCluster.BROKER_CONFIGURATION_FILENAME);
    brokerConfiguration += brokerCm.getData().getOrDefault(KafkaCluster.BROKER_ADVERTISED_PORTS_FILENAME, "");
    brokerConfiguration += brokerCm.getData().getOrDefault(KafkaCluster.BROKER_ADVERTISED_HOSTNAMES_FILENAME, "");
    this.kafkaBrokerConfigurationHash = getStringHash(brokerConfiguration);

    String loggingConfiguration = brokerCm.getData().get(AbstractModel.ANCILLARY_CM_KEY_LOG_CONFIG);
    this.kafkaLoggingHash = getStringHash(loggingConfiguration);

    return brokerCm;
}
 
Example #18
Source File: BrokerEnvironmentFactory.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private BrokersConfigs getBrokersConfigs(
    Collection<PluginFQN> pluginFQNs, RuntimeIdentity runtimeID, String brokerImage)
    throws InfrastructureException {

  String configMapName = generateUniqueName(CONFIG_MAP_NAME_SUFFIX);
  String configMapVolume = generateUniqueName(BROKER_VOLUME);
  ConfigMap configMap = newConfigMap(configMapName, pluginFQNs);

  Pod pod = newPod();
  List<EnvVar> envVars =
      Stream.of(
              authEnableEnvVarProvider.get(runtimeID), machineTokenEnvVarProvider.get(runtimeID))
          .map(this::asEnvVar)
          .collect(Collectors.toList());
  Container container = newContainer(runtimeID, envVars, brokerImage, configMapVolume);
  pod.getSpec().getContainers().add(container);
  pod.getSpec().getVolumes().add(newConfigMapVolume(configMapName, configMapVolume));

  InternalMachineConfig machineConfig = new InternalMachineConfig();
  String machineName = Names.machineName(pod.getMetadata(), container);

  BrokersConfigs configs = new BrokersConfigs();
  configs.configMaps = singletonMap(configMapName, configMap);
  configs.machines = singletonMap(machineName, machineConfig);
  configs.pods = singletonMap(pod.getMetadata().getName(), pod);

  return configs;
}
 
Example #19
Source File: ConfigMapsTests.java    From spring-cloud-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigMap() {
	ConfigMap configmap = mockClient.configMaps().inNamespace("test")
			.withName(APPLICATION_NAME).get();
	HashMap<String, String> keys = (HashMap<String, String>) configmap.getData();
	assertThat("Hello ConfigMap, %s!").isEqualTo(keys.get("bean.greeting"));
}
 
Example #20
Source File: ConfigMapTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testFromResourceConfigMap() throws InterruptedException {
  KubernetesClient client = server.getClient();
  ConfigMap configMap = client.configMaps().load(getClass().getResourceAsStream("/test-config-map.yml")).get();
  assertEquals("cfg1", configMap.getMetadata().getName());

  Map<String, String> keys = (Map<String, String>) configMap.getData();
  assertEquals("gouda",keys.get("cheese"));
  assertEquals("bar",keys.get("foo"));
}
 
Example #21
Source File: KubernetesEnvironmentFactoryTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void addConfigMapsWhenRecipeContainsThem() throws Exception {
  ConfigMap configMap =
      new ConfigMapBuilder().withNewMetadata().withName("test-configmap").endMetadata().build();
  when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(singletonList(configMap));

  final KubernetesEnvironment parsed =
      k8sEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());

  assertEquals(parsed.getConfigMaps().size(), 1);
  assertEquals(parsed.getConfigMaps().get("test-configmap"), configMap);
}
 
Example #22
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);
}
 
Example #23
Source File: EventBasedConfigurationChangeDetectorTests.java    From spring-cloud-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test
public void verifyConfigChangesAccountsForBootstrapPropertySources() {
	ConfigReloadProperties configReloadProperties = new ConfigReloadProperties();
	MockEnvironment env = new MockEnvironment();
	KubernetesClient k8sClient = mock(KubernetesClient.class);
	ConfigMap configMap = new ConfigMap();
	Map<String, String> data = new HashMap();
	data.put("foo", "bar");
	configMap.setData(data);
	MixedOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> mixedOperation = mock(
			MixedOperation.class);
	Resource<ConfigMap, DoneableConfigMap> resource = mock(Resource.class);
	when(resource.get()).thenReturn(configMap);
	when(mixedOperation.withName(eq("myconfigmap"))).thenReturn(resource);
	when(k8sClient.configMaps()).thenReturn(mixedOperation);

	ConfigMapPropertySource configMapPropertySource = new ConfigMapPropertySource(
			k8sClient, "myconfigmap");
	env.getPropertySources()
			.addFirst(new BootstrapPropertySource(configMapPropertySource));

	ConfigurationUpdateStrategy configurationUpdateStrategy = mock(
			ConfigurationUpdateStrategy.class);
	ConfigMapPropertySourceLocator configMapLocator = mock(
			ConfigMapPropertySourceLocator.class);
	SecretsPropertySourceLocator secretsLocator = mock(
			SecretsPropertySourceLocator.class);
	EventBasedConfigurationChangeDetector detector = new EventBasedConfigurationChangeDetector(
			env, configReloadProperties, k8sClient, configurationUpdateStrategy,
			configMapLocator, secretsLocator);
	List<ConfigMapPropertySource> sources = detector
			.findPropertySources(ConfigMapPropertySource.class);
	assertThat(sources.size()).isEqualTo(1);
	assertThat(sources.get(0).getProperty("foo")).isEqualTo("bar");
}
 
Example #24
Source File: KubernetesArtifactsBrokerApplierTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@BeforeMethod
public void setUp() throws Exception {
  // Workspace env setup
  ObjectMeta workspacePodMeta =
      new ObjectMetaBuilder().withAnnotations(workspacePodAnnotations).build();
  workspacePod = new PodBuilder().withMetadata(workspacePodMeta).withSpec(new PodSpec()).build();
  Map<String, ConfigMap> workspaceConfigMaps = new HashMap<>();
  workspaceEnvironment =
      KubernetesEnvironment.builder()
          .setPods(ImmutableMap.of(WORKSPACE_POD_NAME, workspacePod))
          .setMachines(new HashMap<>())
          .setConfigMaps(workspaceConfigMaps)
          .build();

  // Broker env setup
  ObjectMeta brokerPodMeta =
      new ObjectMetaBuilder().withAnnotations(brokerPodAnnotations).build();
  brokerContainer = new ContainerBuilder().withName(BROKER_CONTAINER_NAME).build();
  brokerVolume = new VolumeBuilder().build();
  Pod brokerPod =
      new PodBuilder()
          .withMetadata(brokerPodMeta)
          .withNewSpec()
          .withContainers(brokerContainer)
          .withVolumes(brokerVolume)
          .endSpec()
          .build();
  brokerConfigMap = new ConfigMapBuilder().addToData(brokerConfigMapData).build();
  KubernetesEnvironment brokerEnvironment =
      KubernetesEnvironment.builder()
          .setPods(ImmutableMap.of(BROKER_POD_NAME, brokerPod))
          .setConfigMaps(ImmutableMap.of(BROKER_CONFIGMAP_NAME, brokerConfigMap))
          .setMachines(ImmutableMap.of(BROKER_MACHINE_NAME, brokerMachine))
          .build();
  doReturn(brokerEnvironment)
      .when(brokerEnvironmentFactory)
      .createForArtifactsBroker(any(), any());

  applier = new KubernetesArtifactsBrokerApplier<>(brokerEnvironmentFactory);
}
 
Example #25
Source File: LeaderRecordWatcher.java    From spring-cloud-kubernetes with Apache License 2.0 5 votes vote down vote up
@Override
public void eventReceived(Action action, ConfigMap configMap) {
	LOGGER.debug("'{}' event received, triggering leadership update", action);

	if (!Action.ERROR.equals(action)) {
		this.leadershipController.update();
	}
}
 
Example #26
Source File: UniqueNamesProvisionerTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void provideUniqueConfigMapName() throws Exception {
  when(runtimeIdentity.getWorkspaceId()).thenReturn(WORKSPACE_ID);

  ConfigMap configMap = newConfigMap();
  doReturn(ImmutableMap.of(CONFIGMAP_NAME, configMap)).when(k8sEnv).getConfigMaps();

  uniqueNamesProvisioner.provision(k8sEnv, runtimeIdentity);

  ObjectMeta configMapMetadata = configMap.getMetadata();
  assertNotEquals(configMapMetadata.getName(), CONFIGMAP_NAME);
  assertEquals(configMapMetadata.getLabels().get(CHE_ORIGINAL_NAME_LABEL), CONFIGMAP_NAME);
}
 
Example #27
Source File: ArchaiusConfigMapSourceConfiguration.java    From spring-cloud-kubernetes with Apache License 2.0 5 votes vote down vote up
public void start() {
    ConfigMap map = Strings.isNullOrEmpty(namespace)
            ? client.configMaps().withName(name).get()
            : client.configMaps().inNamespace(namespace).withName(name).get();

    if (map != null) {
        currentData.set(asObjectMap(map.getData()));
    }
    watch = Strings.isNullOrEmpty(namespace)
            ? client.configMaps().withName(name).watch(watcher)
            : client.configMaps().inNamespace(namespace).withName(namespace).watch(watcher);
    started.set(true);
}
 
Example #28
Source File: UniqueNamesProvisionerTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private static ConfigMap newConfigMap() {
  return new ConfigMapBuilder()
      .withNewMetadata()
      .withName(CONFIGMAP_NAME)
      .endMetadata()
      .withData(ImmutableMap.of(CONFIGMAP_KEY, CONFIGMAP_VALUE))
      .build();
}
 
Example #29
Source File: ConfigMapSupplier.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@Override
public ConfigMap get() {
  synchronized (lock) {
    if (configMap == null) {
      throw new IllegalStateException(String.format("ConfigMap %s has been deleted!", name));
    }
    return configMap;
  }
}
 
Example #30
Source File: WaitForConditionWatcherTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
void itDoesNotCompleteOnNoMatchDeleted() {
  TrackingPredicate condition = condition(Objects::nonNull);
  WaitForConditionWatcher<ConfigMap> watcher = new WaitForConditionWatcher<>(condition);
  watcher.eventReceived(Action.DELETED, configMap);
  assertFalse(watcher.getFuture().isDone());
  condition.isCalledWith(null);
}