Search in sources :

Example 1 with EnricherManager

use of io.fabric8.maven.plugin.enricher.EnricherManager 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 2 with EnricherManager

use of io.fabric8.maven.plugin.enricher.EnricherManager in project fabric8-maven-plugin by fabric8io.

the class ResourceMojo method generateResources.

private KubernetesList generateResources(List<ImageConfiguration> images) throws IOException, MojoExecutionException {
    // Manager for calling enrichers.
    openshiftDependencyResources = new OpenShiftDependencyResources(log);
    loadOpenShiftOverrideResources();
    EnricherContext.Builder ctxBuilder = new EnricherContext.Builder().project(project).session(session).goalFinder(goalFinder).config(extractEnricherConfig()).resources(resources).images(resolvedImages).log(log).useProjectClasspath(useProjectClasspath).openshiftDependencyResources(openshiftDependencyResources);
    if (resources != null) {
        ctxBuilder.namespace(resources.getNamespace());
    }
    EnricherManager enricherManager = new EnricherManager(resources, ctxBuilder.build());
    // Generate all resources from the main resource diretory, configuration and enrich them accordingly
    KubernetesListBuilder builder = generateAppResources(images, enricherManager);
    // Add resources found in subdirectories of resourceDir, with a certain profile
    // applied
    addProfiledResourcesFromSubirectories(builder, resourceDir, enricherManager);
    return builder.build();
}
Also used : EnricherContext(io.fabric8.maven.enricher.api.EnricherContext) EnricherManager(io.fabric8.maven.plugin.enricher.EnricherManager)

Example 3 with EnricherManager

use of io.fabric8.maven.plugin.enricher.EnricherManager in project fabric8-maven-plugin by fabric8io.

the class EnricherManagerTest method enrichSimple.

@Test
public void enrichSimple() {
    new Expectations() {

        {
            context.getConfig();
            result = new ProcessorConfig(Arrays.asList("fmp-project"), null, new HashMap<String, TreeMap>());
        }
    };
    EnricherManager manager = new EnricherManager(null, context);
    KubernetesListBuilder builder = new KubernetesListBuilder();
    builder.addNewReplicaSetItem().withNewSpec().withNewTemplate().withNewSpec().addNewContainer().withName("test").withImage("busybox").endContainer().endSpec().endTemplate().endSpec().endReplicaSetItem();
    manager.enrich(builder);
    KubernetesList list = builder.build();
    assertEquals(1, list.getItems().size());
    ReplicaSet pod = (ReplicaSet) list.getItems().get(0);
    ObjectMeta metadata = pod.getMetadata();
    assertNotNull(metadata);
    Map<String, String> labels = metadata.getLabels();
    assertNotNull(labels);
    assertEquals("fabric8", labels.get("provider"));
}
Also used : Expectations(mockit.Expectations) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) Test(org.junit.Test)

Example 4 with EnricherManager

use of io.fabric8.maven.plugin.enricher.EnricherManager in project fabric8-maven-plugin by fabric8io.

the class EnricherManagerTest method createDefaultResources.

@Test
public void createDefaultResources() {
    new Expectations() {

        {
            context.getConfig();
            result = new ProcessorConfig(Arrays.asList("fmp-controller"), null, null);
            context.getImages();
            result = new ImageConfiguration.Builder().alias("img1").name("img1").build();
        }
    };
    EnricherManager manager = new EnricherManager(null, context);
    KubernetesListBuilder builder = new KubernetesListBuilder();
    manager.createDefaultResources(builder);
    assertTrue(builder.build().getItems().size() > 0);
}
Also used : Expectations(mockit.Expectations) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) Test(org.junit.Test)

Aggregations

ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)2 Expectations (mockit.Expectations)2 Test (org.junit.Test)2 ReplicaSet (io.fabric8.kubernetes.api.model.extensions.ReplicaSet)1 ComposeService (io.fabric8.maven.core.service.ComposeService)1 Fabric8ServiceException (io.fabric8.maven.core.service.Fabric8ServiceException)1 EnricherContext (io.fabric8.maven.enricher.api.EnricherContext)1 EnricherManager (io.fabric8.maven.plugin.enricher.EnricherManager)1 File (java.io.File)1 Path (java.nio.file.Path)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1