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); }
@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); }
@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 ConfigMapBuilder(ConfigMap instance,Boolean validationEnabled){ this.fluent = this; this.withApiVersion(instance.getApiVersion()); this.withData(instance.getData()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); this.validationEnabled = validationEnabled; }
withData(data).build();
withData(data).build();
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(); }
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); } }
data.put("count", "3"); ConfigMap map2 = new ConfigMapBuilder().withMetadata(new ObjectMetaBuilder().withName("my-config-map-2").build()) .withData(data) .build();
data.put("count", "3"); ConfigMap map2 = new ConfigMapBuilder().withMetadata(new ObjectMetaBuilder().withName("my-config-map-2").build()) .withData(data) .build();