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); }
private void removeConfigMapEntry(ConfigMap configMap, String key) { LOGGER.debug("Removing config map entry '{}'", key); ConfigMap newConfigMap = new ConfigMapBuilder(configMap) .removeFromData(key) .build(); updateConfigMap(configMap, newConfigMap); }
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); }
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 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); } }
vertx.exceptionHandler(tc.exceptionHandler()); ConfigMap map1 = new ConfigMapBuilder().withMetadata(new ObjectMetaBuilder().withName("my-config-map").build()) .addToData("my-app-json", SOME_JSON) .addToData("my-app-props", SOME_PROPS) .build(); data.put("bool", "true"); data.put("count", "3"); ConfigMap map2 = new ConfigMapBuilder().withMetadata(new ObjectMetaBuilder().withName("my-config-map-2").build()) .withData(data) .build(); ConfigMap map3 = new ConfigMapBuilder().withMetadata(new ObjectMetaBuilder().withName("my-config-map-x").build()) .addToData("my-app-json", SOME_JSON) .build();
public DoneableConfigMap(ConfigMap item){ super(item);this.builder=new ConfigMapBuilder(this, item);this.function=new Function<ConfigMap, ConfigMap>() { public ConfigMap apply(ConfigMap item) { return item; } } ; }
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 static HasMetadata mergeConfigMaps(ConfigMap cm1, ConfigMap cm2, Logger log, boolean switchOnLocalCustomisation) { ConfigMap cm1OrCopy = cm1; if (!switchOnLocalCustomisation) { // lets copy the original to avoid modifying it cm1OrCopy = new ConfigMapBuilder(cm1OrCopy).build(); } log.info("Merging 2 resources for " + KubernetesHelper.getKind(cm1OrCopy) + " " + KubernetesHelper.getName(cm1OrCopy) + " from " + getSourceUrlAnnotation(cm1OrCopy) + " and " + getSourceUrlAnnotation(cm2) + " and removing " + getSourceUrlAnnotation(cm1OrCopy)); cm1OrCopy.setData(mergeMapsAndRemoveEmptyStrings(cm2.getData(), cm1OrCopy.getData())); mergeMetadata(cm1OrCopy, cm2); return cm1OrCopy; }
public ConfigMap done(){ return function.apply(builder.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; }
@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); } } });
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); }
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); } }
vertx.exceptionHandler(tc.exceptionHandler()); ConfigMap map1 = new ConfigMapBuilder().withMetadata(new ObjectMetaBuilder().withName("my-config-map").build()) .addToData("my-app-json", SOME_JSON) .addToData("my-app-props", SOME_PROPS) .build(); data.put("bool", "true"); data.put("count", "3"); ConfigMap map2 = new ConfigMapBuilder().withMetadata(new ObjectMetaBuilder().withName("my-config-map-2").build()) .withData(data) .build(); ConfigMap map3 = new ConfigMapBuilder().withMetadata(new ObjectMetaBuilder().withName("my-config-map-x").build()) .addToData("my-app-json", SOME_JSON) .build();
@Override public ConfigMapBuilder edit(ConfigMap item) { return new ConfigMapBuilder(item); }
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(); }
@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(); } }
@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(); }
ConfigMapBuilder configMapBuilder = new ConfigMapBuilder() .editOrNewMetadata() .withName(keycloakConfigName) .addToLabels("app", "enmasse") 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)); client.configMaps().createOrReplace(configMapBuilder.build()); log.debug("Created config map: {} ", keycloakConfigName); } else if (oauthClientAccessible) {