Search in sources :

Example 1 with KindAndName

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

the class DependencyEnricherTest method checkUniqueResources.

private boolean checkUniqueResources(List<HasMetadata> resourceList) {
    Map<KindAndName, Integer> resourceMap = new HashMap<>();
    for (int index = 0; index < resourceList.size(); index++) {
        KindAndName aKey = new KindAndName(resourceList.get(index));
        if (resourceMap.containsKey(aKey))
            return false;
        resourceMap.put(aKey, index);
    }
    return true;
}
Also used : KindAndName(io.fabric8.maven.core.util.KindAndName)

Example 2 with KindAndName

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

the class OpenShiftDependencyResources method addOpenShiftResources.

public void addOpenShiftResources(List<HasMetadata> items, boolean isAppCatalog) {
    for (HasMetadata item : items) {
        if (item instanceof Template) {
            Template template = (Template) item;
            if (!KubernetesResourceUtil.isAppCatalogResource(template) && !isAppCatalog) {
                List<HasMetadata> objects = notNullList(template.getObjects());
                String sourceUrl = getSourceUrlAnnotation(template);
                if (Strings.isNotBlank(sourceUrl)) {
                    for (HasMetadata object : objects) {
                        setSourceUrlAnnotationIfNotSet(object, sourceUrl);
                    }
                }
                addOpenShiftResources(objects, isAppCatalog);
                mergeParametersIntoMap(templateParameters, notNullList(template.getParameters()));
                continue;
            }
        }
        KindAndName key = new KindAndName(item);
        HasMetadata old = openshiftDependencyResources.get(key);
        if (old != null && !isAppCatalog) {
            log.warn("Duplicate OpenShift resources for %s at %s and %s", key, getSourceUrlAnnotation(old), getSourceUrlAnnotation(item));
        }
        openshiftDependencyResources.put(key, item);
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Template(io.fabric8.openshift.api.model.Template)

Example 3 with KindAndName

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

the class OpenShiftDependencyResources method convertKubernetesItemToOpenShift.

/**
 * Returns the OpenShift dependency for the given resource if there is one
 */
public HasMetadata convertKubernetesItemToOpenShift(HasMetadata item) {
    KindAndName key = new KindAndName(item);
    HasMetadata answer = openshiftDependencyResources.get(key);
    if (answer == null && item instanceof Deployment) {
        key = new KindAndName("DeploymentConfig", getName(item));
        answer = openshiftDependencyResources.get(key);
    }
    return answer;
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment)

Example 4 with KindAndName

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

the class OpenShiftDependencyResources method addMissingResources.

public void addMissingResources(List<HasMetadata> objects) {
    Map<KindAndName, HasMetadata> itemMap = new HashMap<>();
    for (HasMetadata item : objects) {
        itemMap.put(new KindAndName(item), item);
    }
    // lets add any openshift specific dependencies (OAuthClient etc) which are not already added
    for (Map.Entry<KindAndName, HasMetadata> entry : openshiftDependencyResources.entrySet()) {
        KindAndName key = entry.getKey();
        HasMetadata dependency = entry.getValue();
        if (!itemMap.containsKey(key)) {
            objects.add(dependency);
        }
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with KindAndName

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

the class OpenShiftOverrideResources method overrideResource.

/**
 * Applies any overrides if we have any for the given item
 */
public HasMetadata overrideResource(HasMetadata item) {
    KindAndName key = new KindAndName(item);
    HasMetadata override = map.get(key);
    if (override != null) {
        log.info("Overriding " + key);
        HasMetadata answer = KubernetesResourceUtil.mergeResources(item, override, log, false);
        if (answer != null) {
            return answer;
        }
    }
    return item;
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata)

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