Search in sources :

Example 6 with KindAndName

use of io.fabric8.maven.core.util.KindAndName in project fabric8-maven-plugin by fabric8io.

the class DependencyEnricher method filterAndAddItemsToBuilder.

public void filterAndAddItemsToBuilder(KubernetesListBuilder builder, List<HasMetadata> items) {
    Map<KindAndName, Integer> aIndexMap = new HashMap<>();
    int nItems = 0;
    // Populate map with existing items in the builder
    for (int index = 0; index < builder.getItems().size(); index++, nItems++) {
        HasMetadata aItem = builder.getItems().get(index);
        KindAndName aKey = new KindAndName(aItem);
        aIndexMap.put(aKey, index);
    }
    for (HasMetadata item : items) {
        KindAndName aKey = new KindAndName(item);
        if (aIndexMap.containsKey(aKey)) {
            // Merge the override fragments, and remove duplicate
            HasMetadata duplicateItem = builder.getItems().get(aIndexMap.get(aKey));
            item = KubernetesResourceUtil.mergeResources(item, duplicateItem, log, false);
            builder.setToItems(aIndexMap.get(aKey), item);
        } else {
            aIndexMap.put(aKey, nItems++);
            builder.addToItems(item);
        }
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) KindAndName(io.fabric8.maven.core.util.KindAndName)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)5 KindAndName (io.fabric8.maven.core.util.KindAndName)2 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)1 Template (io.fabric8.openshift.api.model.Template)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1