Search in sources :

Example 26 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project fabric8-maven-plugin by fabric8io.

the class KubernetesResourceUtil method loadResources.

public static Set<HasMetadata> loadResources(File manifest) throws IOException {
    Object dto = KubernetesHelper.loadYaml(manifest, KubernetesResource.class);
    if (dto == null) {
        throw new IllegalStateException("Cannot load kubernetes YAML: " + manifest);
    }
    if (dto instanceof Template) {
        Template template = (Template) dto;
        boolean failOnMissingParameterValue = false;
        dto = Templates.processTemplatesLocally(template, failOnMissingParameterValue);
    }
    Set<KubernetesResource<?>> resources = new LinkedHashSet<>();
    Set<HasMetadata> entities = new TreeSet<>(new HasMetadataComparator());
    for (KubernetesResource<?> resource : resources) {
        entities.addAll(KubernetesHelper.toItemList(resource));
    }
    entities.addAll(KubernetesHelper.toItemList(dto));
    return entities;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) HasMetadataComparator(io.fabric8.kubernetes.internal.HasMetadataComparator) TreeSet(java.util.TreeSet) KubernetesResource(io.fabric8.kubernetes.api.model.KubernetesResource) Template(io.fabric8.openshift.api.model.Template)

Example 27 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata 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 28 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata 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 29 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project fabric8-maven-plugin by fabric8io.

the class ValidationUtil method createValidationMessage.

public static String createValidationMessage(Set<ConstraintViolation<?>> constraintViolations) {
    if (constraintViolations.isEmpty()) {
        return "No Constraint Validations!";
    }
    StringBuilder builder = new StringBuilder("Constraint Validations: ");
    for (ConstraintViolation<?> violation : constraintViolations) {
        if (builder.length() > 0) {
            builder.append(", ");
        }
        Object leafBean = violation.getLeafBean();
        if (leafBean instanceof HasMetadata) {
            HasMetadata hasMetadata = (HasMetadata) leafBean;
            ObjectMeta metadata = hasMetadata.getMetadata();
            if (metadata != null) {
                leafBean = "" + hasMetadata.getKind() + ": " + metadata;
            }
        }
        builder.append(violation.getPropertyPath() + " " + violation.getMessage() + " on bean: " + leafBean);
    }
    return builder.toString();
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata)

Example 30 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project fabric8-maven-plugin by fabric8io.

the class ReplicSetOpenShiftConverter method convert.

@Override
public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec, boolean enableAutomaticTrigger) {
    ReplicaSet resource = (ReplicaSet) item;
    ReplicationControllerBuilder builder = new ReplicationControllerBuilder();
    builder.withMetadata(resource.getMetadata());
    ReplicaSetSpec spec = resource.getSpec();
    if (spec != null) {
        ReplicationControllerFluent.SpecNested<ReplicationControllerBuilder> specBuilder = builder.withNewSpec();
        Integer replicas = spec.getReplicas();
        if (replicas != null) {
            specBuilder.withReplicas(replicas);
        }
        LabelSelector selector = spec.getSelector();
        if (selector != null) {
            Map<String, String> matchLabels = selector.getMatchLabels();
            if (matchLabels != null && !matchLabels.isEmpty()) {
                specBuilder.withSelector(matchLabels);
            }
        }
        PodTemplateSpec template = spec.getTemplate();
        if (template != null) {
            specBuilder.withTemplate(template);
        }
        specBuilder.endSpec();
    }
    return builder.build();
}
Also used : ReplicaSetSpec(io.fabric8.kubernetes.api.model.extensions.ReplicaSetSpec) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)79 Test (org.junit.Test)25 File (java.io.File)21 ArrayList (java.util.ArrayList)21 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)16 IOException (java.io.IOException)16 Template (io.fabric8.openshift.api.model.Template)15 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)14 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)13 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)13 Service (io.fabric8.kubernetes.api.model.Service)13 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)13 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)13 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)11 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 HashMap (java.util.HashMap)9 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)8 ReplicaSet (io.fabric8.kubernetes.api.model.extensions.ReplicaSet)8 Map (java.util.Map)8 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)7