Search in sources :

Example 46 with Resource

use of io.fabric8.support.api.Resource 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 47 with Resource

use of io.fabric8.support.api.Resource 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)

Example 48 with Resource

use of io.fabric8.support.api.Resource in project fabric8-maven-plugin by fabric8io.

the class AbstractResourceMojo method writeResourcesIndividualAndComposite.

public static File writeResourcesIndividualAndComposite(KubernetesList resources, File resourceFileBase, ResourceFileType resourceFileType, Logger log, Boolean generateRoute) throws MojoExecutionException {
    // Creating a new items list. This will be used to generate openshift.yml
    List<HasMetadata> newItemList = new ArrayList<>();
    if (!generateRoute) {
        // if flag is set false, this will remove the Route resource from resources list
        for (HasMetadata item : resources.getItems()) {
            if (item.getKind().equalsIgnoreCase("Route")) {
                continue;
            }
            newItemList.add(item);
        }
        // update the resource with new list
        resources.setItems(newItemList);
    }
    // entity is object which will be sent to writeResource for openshift.yml
    // if generateRoute is false, this will be set to resources with new list
    // otherwise it will be set to resources with old list.
    Object entity = resources;
    // if the list contains a single Template lets unwrap it
    // in resources already new or old as per condition is set.
    // no need to worry about this for dropping Route.
    Template template = getSingletonTemplate(resources);
    if (template != null) {
        entity = template;
    }
    File file = writeResource(resourceFileBase, entity, resourceFileType);
    // write separate files, one for each resource item
    // resources passed to writeIndividualResources is also new one.
    writeIndividualResources(resources, resourceFileBase, resourceFileType, log, generateRoute);
    return file;
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ArrayList(java.util.ArrayList) File(java.io.File) Template(io.fabric8.openshift.api.model.Template)

Example 49 with Resource

use of io.fabric8.support.api.Resource in project fabric8-maven-plugin by fabric8io.

the class ResourceMojo method generateAppResources.

private KubernetesListBuilder generateAppResources(List<ImageConfiguration> images, EnricherManager enricherManager) throws IOException, MojoExecutionException {
    Path composeFilePath = checkComposeConfig();
    ComposeService composeUtil = new ComposeService(komposeBinDir, composeFilePath, log);
    try {
        File[] resourceFiles = KubernetesResourceUtil.listResourceFragments(resourceDir);
        File[] composeResourceFiles = composeUtil.convertToKubeFragments();
        File[] allResources = ArrayUtils.addAll(resourceFiles, composeResourceFiles);
        KubernetesListBuilder builder;
        // Add resource files found in the fabric8 directory
        if (allResources != null && allResources.length > 0) {
            if (resourceFiles != null && resourceFiles.length > 0) {
                log.info("using resource templates from %s", resourceDir);
            }
            if (composeResourceFiles != null && composeResourceFiles.length > 0) {
                log.info("using resource templates generated from compose file");
            }
            builder = readResourceFragments(allResources);
        } else {
            builder = new KubernetesListBuilder();
        }
        // Add locally configured objects
        if (resources != null) {
            // TODO: Allow also support resources to be specified via XML
            addConfiguredResources(builder, images);
        }
        // Create default resources for app resources only
        enricherManager.createDefaultResources(builder);
        // Enrich descriptors
        enricherManager.enrich(builder);
        return builder;
    } catch (ConstraintViolationException e) {
        String message = ValidationUtil.createValidationMessage(e.getConstraintViolations());
        log.error("ConstraintViolationException: %s", message);
        throw new MojoExecutionException(message, e);
    } catch (Fabric8ServiceException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } finally {
        composeUtil.cleanComposeResources();
    }
}
Also used : Path(java.nio.file.Path) Fabric8ServiceException(io.fabric8.maven.core.service.Fabric8ServiceException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ComposeService(io.fabric8.maven.core.service.ComposeService) ConstraintViolationException(javax.validation.ConstraintViolationException) File(java.io.File)

Example 50 with Resource

use of io.fabric8.support.api.Resource in project fabric8-maven-plugin by fabric8io.

the class ResourceMojo method getResolvedImages.

private List<ImageConfiguration> getResolvedImages(List<ImageConfiguration> images, final Logger log) throws MojoExecutionException {
    List<ImageConfiguration> ret;
    ret = ConfigHelper.resolveImages(log, images, new ConfigHelper.Resolver() {

        @Override
        public List<ImageConfiguration> resolve(ImageConfiguration image) {
            return imageConfigResolver.resolve(image, project, session);
        }
    }, // no filter on image name yet (TODO: Maybe add this, too ?)
    null, new ConfigHelper.Customizer() {

        @Override
        public List<ImageConfiguration> customizeConfig(List<ImageConfiguration> configs) {
            try {
                GeneratorContext ctx = new GeneratorContext.Builder().config(extractGeneratorConfig()).project(project).session(session).goalFinder(goalFinder).goalName("fabric8:resource").logger(log).mode(mode).strategy(buildStrategy).useProjectClasspath(useProjectClasspath).build();
                return GeneratorManager.generate(configs, ctx, true);
            } catch (Exception e) {
                throw new IllegalArgumentException("Cannot extract generator: " + e, e);
            }
        }
    });
    Date now = getBuildReferenceDate();
    storeReferenceDateInPluginContext(now);
    String minimalApiVersion = ConfigHelper.initAndValidate(ret, null, /* no minimal api version */
    new ImageNameFormatter(project, now), log);
    return ret;
}
Also used : ImageConfigResolver(io.fabric8.maven.docker.config.handler.ImageConfigResolver) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) ImageNameFormatter(io.fabric8.maven.docker.util.ImageNameFormatter) List(java.util.List) ArrayList(java.util.ArrayList) GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) Fabric8ServiceException(io.fabric8.maven.core.service.Fabric8ServiceException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ConstraintViolationException(javax.validation.ConstraintViolationException) Date(java.util.Date)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)25 Resource (io.fabric8.kubernetes.client.dsl.Resource)25 Map (java.util.Map)20 Test (org.junit.Test)20 IOException (java.io.IOException)19 HashMap (java.util.HashMap)16 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)14 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)14 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)14 Resource (org.osgi.resource.Resource)14 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)13 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)13 ArrayList (java.util.ArrayList)13 Async (io.vertx.ext.unit.Async)12 File (java.io.File)10 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)9 Service (io.fabric8.kubernetes.api.model.Service)9 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)9 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)8 Bundle (org.osgi.framework.Bundle)7