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(); }
protected void doCreateConfigMap(Exchange exchange, String operation) throws Exception { ConfigMap configMap = null; String cfMapName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_CONFIGMAP_NAME, String.class); String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); HashMap<String, String> configMapData = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_CONFIGMAP_DATA, HashMap.class); if (ObjectHelper.isEmpty(cfMapName)) { LOG.error("Create a specific configMap require specify a configMap name"); throw new IllegalArgumentException("Create a specific configMap require specify a configMap name"); } if (ObjectHelper.isEmpty(namespaceName)) { LOG.error("Create a specific configMap require specify a namespace name"); throw new IllegalArgumentException("Create a specific configMap require specify a namespace name"); } if (ObjectHelper.isEmpty(configMapData)) { LOG.error("Create a specific configMap require specify a data map"); throw new IllegalArgumentException("Create a specific configMap require specify a data map"); } Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_CONFIGMAPS_LABELS, Map.class); ConfigMap cfMapCreating = new ConfigMapBuilder().withNewMetadata().withName(cfMapName).withLabels(labels).endMetadata().withData(configMapData).build(); configMap = getEndpoint().getKubernetesClient().configMaps().inNamespace(namespaceName).create(cfMapCreating); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(configMap); }
.withName(keycloakConfigName) .addToLabels("app", "enmasse") .endMetadata();
withNewMetadata().withName(componentName).withAnnotations(annotations).withLabels(labels).endMetadata(). withData(data).build();
withNewMetadata().withName(name).withAnnotations(annotations).withLabels(labels).endMetadata(). withData(data).build();
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); } }
@Override public void createResource(Topic topic) { Map<String, String> data = new HashMap<>(); data.put(TOPIC_NAME_KEY, String.valueOf(topic.getName())); data.put(PARTITIONS_KEY, String.valueOf(topic.getPartitions())); data.put(REPLICATION_FACTOR_KEY, String.valueOf(topic.getReplicationFactor())); data.put(PROPERTIES_KEY, Config.propertiesAsString(topic.getProperties())); data.put(ACL_KEY, String.valueOf(topic.isAcl())); Map<String, String> labels = labels(); labels.put(GENERATOR_LABEL, operator.getGeneratorId()); Map<String, String> annotations = new HashMap<>(); annotations.put(GENERATED_ANNOTATION, ZonedDateTime.now().format(DateTimeFormatter.ISO_INSTANT)); ConfigMap cm = new ConfigMapBuilder() .withNewMetadata() .withName(cleanName(topic.getName())) .withLabels(labels) .withAnnotations(annotations) .endMetadata() .withData(data).build(); cm = kubeClient().configMaps().create(cm); log.info("Created ConfigMap {} for topic {}", cm, topic); }
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); } }
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(); }
@Override protected ConfigMap resource() { return new ConfigMapBuilder() .withNewMetadata() .withName(RESOURCE_NAME) .withNamespace(NAMESPACE) .withLabels(singletonMap("foo", "bar")) .endMetadata() .withData(singletonMap("FOO", Integer.toString(new Random().nextInt()))) .build(); } }
public static synchronized ConfigMap updateConfigMapStatus(KubernetesClient client, final Session session, final String status) { try { ConfigMap configMap = new ConfigMapBuilder(). withNewMetadata().withName(FABRIC8_ARQUILLIAN).addToAnnotations(createConfigMapAnnotations(session, status)).endMetadata(). build(); return client.configMaps().inNamespace(session.getNamespace()).withName(FABRIC8_ARQUILLIAN).createOrReplace(configMap); } catch (Exception e) { LOG.warn("failed to update ConfigMap " + FABRIC8_ARQUILLIAN + ". " + e, e); return null; } }
protected ConfigMap createConfigMap(String name, Map<String, String> data) { return new ConfigMapBuilder() .withNewMetadata() .withName(name) .withNamespace(namespace) .withLabels(labels.toMap()) .withOwnerReferences(createOwnerReference()) .endMetadata() .withData(data) .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(); } }