private void updateConfigMapEntry(ConfigMap configMap, Map<String, String> newData) { LOGGER.debug("Adding new data to config map: {}", newData); ConfigMap newConfigMap = new ConfigMapBuilder(configMap) .addToData(newData) .build(); updateConfigMap(configMap, newConfigMap); }
private void createConfigMap(Map<String, String> data) { LOGGER.debug("Creating new config map with data: {}", data); ConfigMap newConfigMap = new ConfigMapBuilder().withNewMetadata() .withName(leaderProperties.getConfigMapName()) .addToLabels(PROVIDER_KEY, PROVIDER) .addToLabels(KIND_KEY, KIND) .endMetadata() .addToData(data) .build(); kubernetesClient.configMaps() .inNamespace(leaderProperties.getNamespace(kubernetesClient.getNamespace())) .create(newConfigMap); }
@Before public void createTestResource() { configMap1 = new ConfigMapBuilder() .withNewMetadata() .withName("configmap1") .withNamespace("ns1") .withAnnotations(Collections.singletonMap("foo", "bar")) .withLabels(Collections.singletonMap("foo-label", "bar-label")) .endMetadata() .addToData("one", "1") .build(); }
public static void main(String[] args) throws InterruptedException { Config config = new ConfigBuilder().build(); KubernetesClient client = new DefaultKubernetesClient(config); String namespace = null; if (args.length > 0) { namespace = args[0]; } if (namespace == null) { namespace = client.getNamespace(); } if (namespace == null) { namespace = "default"; } String name = "cheese"; try { Resource<ConfigMap, DoneableConfigMap> configMapResource = client.configMaps().inNamespace(namespace).withName(name); ConfigMap configMap = configMapResource.createOrReplace(new ConfigMapBuilder(). withNewMetadata().withName(name).endMetadata(). addToData("foo", "" + new Date()). addToData("bar", "beer"). build()); log("Upserted ConfigMap at " + configMap.getMetadata().getSelfLink() + " data " + configMap.getData()); } finally { client.close(); } }
@Override public void visit(ConfigMapBuilder element) { final Map<String, String> annotations = element.buildMetadata().getAnnotations(); try { final Map<String, String> configMapAnnotations = createConfigMapFromAnnotations(annotations); element.addToData(configMapAnnotations); } catch (IOException e) { throw new IllegalArgumentException(e); } } });
public static ConfigMap getConfigMapWithNewLeader(ConfigMap configMap, LeaderInfo leaderInfo) { return new ConfigMapBuilder(configMap) .addToData(LEADER_PREFIX + leaderInfo.getGroupName(), leaderInfo.getLeader()) .addToData(LOCAL_TIMESTAMP_PREFIX + leaderInfo.getGroupName(), formatDate(leaderInfo.getLocalTimestamp())) .build(); }
void addConfigMapFromConfigurations(KubernetesListBuilder builder, io.fabric8.maven.core.config.ConfigMap configMap) { final Map<String, String> configMapFromConfiguration; try { configMapFromConfiguration = createConfigMapFromConfiguration(configMap); if(!configMapFromConfiguration.isEmpty()) { ConfigMapBuilder element = new ConfigMapBuilder(); element.withNewMetadata().withName("xmlconfig").endMetadata(); element.addToData(configMapFromConfiguration); builder.addToConfigMapItems(element.build()); } } catch (IOException e) { throw new IllegalArgumentException(e); } }
public static ConfigMap createNewConfigMap(String configMapName, LeaderInfo leaderInfo) { return new ConfigMapBuilder(). withNewMetadata() .withName(configMapName) .addToLabels("provider", "camel") .addToLabels("kind", "locks"). endMetadata() .addToData(LEADER_PREFIX + leaderInfo.getGroupName(), leaderInfo.getLeader()) .addToData(LOCAL_TIMESTAMP_PREFIX + leaderInfo.getGroupName(), formatDate(leaderInfo.getLocalTimestamp())) .build(); }
configMapBuilder.addToData("oauthUrl", keycloakOauthUrl); openshiftOauthUrl = String.format("https://%s:%s", env.get("KUBERNETES_SERVICE_HOST"), env.get("KUBERNETES_SERVICE_PORT")); configMapBuilder.addToData("identityProviderUrl", openshiftOauthUrl); configMapBuilder.addToData("identityProviderClientId", oauthClientName); configMapBuilder.addToData("identityProviderClientSecret", oauthClientSecret); } else { log.warn("Unable to initialize identityProviderClientId and identityProviderClientSecret " + configMapBuilder.addToData("hostname", "standard-authservice"); configMapBuilder.addToData("port", "5671"); configMapBuilder.addToData("caSecretName", getKeycloakCertSecretName(env));
private ConfigMap create(AddressSpace addressSpace) { Map<String, String> labels = addressSpace.getMetadata().getLabels(); if ( labels == null ) { labels = new HashMap<>(); addressSpace.getMetadata().setLabels(labels); } String name = getConfigMapName(addressSpace.getMetadata().getNamespace(), addressSpace.getMetadata().getName()); labels.put(LabelKeys.TYPE, "address-space"); labels.put(LabelKeys.NAMESPACE, addressSpace.getMetadata().getNamespace()); ConfigMapBuilder builder = new ConfigMapBuilder() .editOrNewMetadata() .withName(name) .addToLabels(labels) .addToAnnotations(addressSpace.getMetadata().getAnnotations()) .endMetadata(); if (addressSpace.getMetadata().getResourceVersion() != null) { builder.editOrNewMetadata() .withResourceVersion(addressSpace.getMetadata().getResourceVersion()) .endMetadata(); } try { // Reset resource version to avoid unneeded extra writes AddressSpace newAddressSpace = new AddressSpaceBuilder(addressSpace).editOrNewMetadata().withResourceVersion(null).endMetadata().build(); builder.addToData("config.json", mapper.writeValueAsString(newAddressSpace)); return builder.build(); } catch (IOException e) { log.info("Error serializing addressspace for {}", addressSpace, e); throw new UncheckedIOException(e); } }
private ConfigMap create(Address address) { ConfigMapBuilder builder = new ConfigMapBuilder() .editOrNewMetadata() .withName(getConfigMapName(address.getMetadata().getNamespace(), address.getMetadata().getName())) .addToLabels(address.getMetadata().getLabels()) .addToLabels(LabelKeys.TYPE, "address-config") .addToLabels(LabelKeys.INFRA_UUID, infraUuid) .addToLabels(LabelKeys.INFRA_TYPE, "any") .addToAnnotations(address.getMetadata().getAnnotations()) // TODO: Support other ways of doing this .addToAnnotations(AnnotationKeys.ADDRESS_SPACE, Address.extractAddressSpace(address)) .endMetadata(); if (address.getMetadata().getResourceVersion() != null) { builder.editOrNewMetadata() .withResourceVersion(address.getMetadata().getResourceVersion()) .endMetadata(); } try { // Reset resource version to avoid unneeded extra writes final Address newAddress = new AddressBuilder(address).editOrNewMetadata().withResourceVersion(null).endMetadata().build(); builder.addToData("config.json", mapper.writeValueAsString(newAddress)); return builder.build(); } catch (IOException e) { log.info("Error serializing address for {}", address, e); throw new UncheckedIOException(e); } }