public ConfigMap getConfigMap(String namespace, String configMapName) { return getAllConfigMaps(namespace).getItems().stream() .filter(configMap -> configMap.getMetadata().getName().equals(configMapName)) .findFirst().get(); }
public ConfigMapListBuilder(ConfigMapListFluent<?> fluent,Boolean validationEnabled){ this(fluent, new ConfigMapList(), validationEnabled); } public ConfigMapListBuilder(ConfigMapListFluent<?> fluent,ConfigMapList instance){
public ConfigMapListFluentImpl(ConfigMapList instance){ this.withApiVersion(instance.getApiVersion()); this.withItems(instance.getItems()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); }
protected void doListConfigMapsByLabels(Exchange exchange, String operation) throws Exception { ConfigMapList configMapsList = null; Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_CONFIGMAPS_LABELS, Map.class); FilterWatchListMultiDeletable<ConfigMap, ConfigMapList, Boolean, Watch, Watcher<ConfigMap>> configMaps = getEndpoint().getKubernetesClient().configMaps().inAnyNamespace(); for (Map.Entry<String, String> entry : labels.entrySet()) { configMaps.withLabel(entry.getKey(), entry.getValue()); } configMapsList = configMaps.list(); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(configMapsList.getItems()); }
public ConfigMapListBuilder(ConfigMapListFluent<?> fluent,ConfigMapList instance,Boolean validationEnabled){ this.fluent = fluent; fluent.withApiVersion(instance.getApiVersion()); fluent.withItems(instance.getItems()); fluent.withKind(instance.getKind()); fluent.withMetadata(instance.getMetadata()); this.validationEnabled = validationEnabled; } public ConfigMapListBuilder(ConfigMapList instance){
public ConfigMapListBuilder(Boolean validationEnabled){ this(new ConfigMapList(), validationEnabled); } public ConfigMapListBuilder(ConfigMapListFluent<?> fluent){
private Set<AddressSpace> listAddressSpacesMatching(Map<String, String> labels) { Set<AddressSpace> instances = new LinkedHashSet<>(); ConfigMapList list = client.configMaps().withLabels(labels).list(); for (ConfigMap map : list.getItems()) { instances.add(getAddressSpaceFromConfig(map)); } return instances; }
public ConfigMapListBuilder(ConfigMapList instance,Boolean validationEnabled){ this.fluent = this; this.withApiVersion(instance.getApiVersion()); this.withItems(instance.getItems()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); this.validationEnabled = validationEnabled; }
public ConfigMapList build(){ ConfigMapList buildable = new ConfigMapList(fluent.getApiVersion(),fluent.getItems(),fluent.getKind(),fluent.getMetadata()); validate(buildable); return buildable; }
@Override public List<Topic> get() { log.debug("Scanning {} for ConfigMaps.", kubeClient().getNamespace()); ConfigMapList list = kubeClient().configMaps().withLabels(labels()).list(); log.debug("Scanned {}", list); return list.getItems().stream().map(this::topicBuilder).filter(Objects::nonNull) .collect(toList()); }
when(cm.list()).thenReturn( new ConfigMapList() );
protected void doList(Exchange exchange, String operation) throws Exception { ConfigMapList configMapsList = getEndpoint().getKubernetesClient().configMaps().inAnyNamespace().list(); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(configMapsList.getItems()); }
@Override public Set<Address> listAddressesWithLabels(String namespace, Map<String, String> labelSelector) { Map<String, String> labels = new LinkedHashMap<>(labelSelector); labels.put(LabelKeys.TYPE, "address-config"); labels.put(LabelKeys.INFRA_UUID, infraUuid); Set<Address> addresses = new LinkedHashSet<>(); ConfigMapList list = client.configMaps().withLabels(labels).list(); for (ConfigMap config : list.getItems()) { Address address = getAddressFromConfig(config); if (namespace.equals(address.getMetadata().getNamespace())) { addresses.add(address); } } return addresses; }
public void collectConfigMaps(String operation) { log.info("Collecting configmaps for namespace {}", namespace); kubernetes.getAllConfigMaps(namespace).getItems().forEach(configMap -> { try { Path confMapFile = resolveLogFile(configMap.getMetadata().getName() + "." + operation + ".configmap"); log.info("config map '{}' will be archived with path: '{}'", configMap.getMetadata().getName(), confMapFile); if (!Files.exists(confMapFile)) { try (BufferedWriter bf = Files.newBufferedWriter(confMapFile)) { bf.write(configMap.toString()); } } } catch (IOException e) { throw new UncheckedIOException(e); } }); }
private String createSubscriptionName(SubscribeRequest request, String namespace, String prefix) { Set<String> configMapNames = new TreeSet<>(); ConfigMapList configMapList = kubernetesClient.configMaps().inNamespace(namespace).list(); List<ConfigMap> list = notNullList(configMapList.getItems()); for (ConfigMap configMap : list) { configMapNames.add(KubernetesHelper.getName(configMap)); } int idx = 0; while (true) { String name = prefix + (++idx); if (!configMapNames.contains(name)) { return name; } } }
for (ConfigMap map : list.getItems()) { updateConfig(map);
public List<ConfigMap> listConfigMaps(Map<String, String> labels) { return client.configMaps().inNamespace(globalNamespace).withLabels(labels).list().getItems(); }
@SuppressWarnings({"PMD.AvoidCatchingGenericException", "PMD.ExceptionAsFlowControl"}) protected void addResourceDescriptors(ZipOutputStream os) { Stream<BuildConfig> bcStream = client.buildConfigs().list().getItems().stream(); Stream<DeploymentConfig> dcStream = client.deploymentConfigs().list().getItems().stream(); Stream<ConfigMap> cmStream = client.configMaps().list().getItems().stream(); Stream<ImageStreamTag> istStream = client.imageStreamTags().list().getItems().stream(); Stream<? extends HasMetadata > stream = Stream.concat(bcStream, dcStream); stream = Stream.concat(stream, cmStream); stream = Stream.concat(stream, istStream); stream.forEach( res -> { HasMetadata resWithMetadata = (HasMetadata) res; try { ZipEntry ze = new ZipEntry("descriptors/"+ resWithMetadata.getKind() + '/' + resWithMetadata.getMetadata().getName() + ".YAML"); os.putNextEntry(ze); dumpAsYaml(resWithMetadata, os); os.closeEntry(); } catch (Exception e){ LOG.error("Error adding resource {} {}", resWithMetadata.getKind(), resWithMetadata.getMetadata().getName(), e); } }); }
@Override public List<BrokerCluster> listClusters() { Map<String, List<HasMetadata>> resourceMap = new HashMap<>(); // Add other resources part of a destination cluster List<HasMetadata> objects = new ArrayList<>(); objects.addAll(client.apps().deployments().withLabel(LabelKeys.INFRA_UUID, infraUuid).list().getItems()); objects.addAll(client.apps().statefulSets().withLabel(LabelKeys.INFRA_UUID, infraUuid).list().getItems()); objects.addAll(client.persistentVolumeClaims().withLabel(LabelKeys.INFRA_UUID, infraUuid).list().getItems()); objects.addAll(client.configMaps().withLabel(LabelKeys.INFRA_UUID, infraUuid).withLabelNotIn("type", "address-config", "address-space", "address-space-plan", "address-plan").list().getItems()); objects.addAll(client.services().withLabel(LabelKeys.INFRA_UUID, infraUuid).list().getItems()); for (HasMetadata config : objects) { Map<String, String> annotations = config.getMetadata().getAnnotations(); if (annotations != null && annotations.containsKey(AnnotationKeys.CLUSTER_ID)) { String groupId = annotations.get(AnnotationKeys.CLUSTER_ID); Map<String, String> labels = config.getMetadata().getLabels(); if (labels != null) { if (!resourceMap.containsKey(groupId)) { resourceMap.put(groupId, new ArrayList<>()); } resourceMap.get(groupId).add(config); } } } return resourceMap.entrySet().stream() .map(entry -> { KubernetesList list = new KubernetesList(); list.setItems(entry.getValue()); return new BrokerCluster(entry.getKey(), list); }).collect(Collectors.toList()); }