Search in sources :

Example 6 with ProcessorConfig

use of io.fabric8.maven.core.config.ProcessorConfig in project fabric8-maven-plugin by fabric8io.

the class MetadataVisitor method visit.

public void visit(T item) {
    ProcessorConfig config = getProcessorConfig();
    ObjectMeta metadata = getOrCreateMetadata(item);
    updateLabels(metadata);
    updateAnnotations(metadata);
}
Also used : ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig)

Example 7 with ProcessorConfig

use of io.fabric8.maven.core.config.ProcessorConfig in project fabric8-maven-plugin by fabric8io.

the class GeneratorManager method generate.

public static List<ImageConfiguration> generate(List<ImageConfiguration> imageConfigs, GeneratorContext genCtx, boolean prePackagePhase) throws MojoExecutionException {
    List<ImageConfiguration> ret = imageConfigs;
    PluginServiceFactory<GeneratorContext> pluginFactory = genCtx.isUseProjectClasspath() ? new PluginServiceFactory<GeneratorContext>(genCtx, ClassUtil.createProjectClassLoader(genCtx.getProject(), genCtx.getLogger())) : new PluginServiceFactory<GeneratorContext>(genCtx);
    List<Generator> generators = pluginFactory.createServiceObjects("META-INF/fabric8/generator-default", "META-INF/fabric8/fabric8-generator-default", "META-INF/fabric8/generator", "META-INF/fabric8-generator");
    ProcessorConfig config = genCtx.getConfig();
    Logger log = genCtx.getLogger();
    List<Generator> usableGenerators = config.prepareProcessors(generators, "generator");
    log.verbose("Generators:");
    for (Generator generator : usableGenerators) {
        log.verbose(" - %s", generator.getName());
        if (generator.isApplicable(ret)) {
            log.info("Running generator %s", generator.getName());
            ret = generator.customize(ret, prePackagePhase);
        }
    }
    return ret;
}
Also used : ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext) Logger(io.fabric8.maven.docker.util.Logger) Generator(io.fabric8.maven.generator.api.Generator) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig)

Example 8 with ProcessorConfig

use of io.fabric8.maven.core.config.ProcessorConfig in project fabric8-maven-plugin by fabric8io.

the class PushMojo method customizeConfig.

/**
 * Customization hook called by the base plugin.
 *
 * @param configs configuration to customize
 * @return the configuration customized by our generators.
 */
@Override
public List<ImageConfiguration> customizeConfig(List<ImageConfiguration> configs) {
    try {
        ProcessorConfig generatorConfig = ProfileUtil.blendProfileWithConfiguration(ProfileUtil.GENERATOR_CONFIG, profile, resourceDir, generator);
        GeneratorContext ctx = new GeneratorContext.Builder().config(generatorConfig).project(project).session(session).goalFinder(goalFinder).goalName("fabric8:push").logger(log).mode(mode).strategy(buildStrategy).useProjectClasspath(false).build();
        return GeneratorManager.generate(configs, ctx, true);
    } catch (Exception e) {
        throw new IllegalArgumentException("Cannot extract generator config: " + e, e);
    }
}
Also used : GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig)

Example 9 with ProcessorConfig

use of io.fabric8.maven.core.config.ProcessorConfig in project fabric8-maven-plugin by fabric8io.

the class WatcherManager method watch.

public static void watch(List<ImageConfiguration> ret, Set<HasMetadata> resources, WatcherContext watcherCtx) throws Exception {
    PluginServiceFactory<WatcherContext> pluginFactory = watcherCtx.isUseProjectClasspath() ? new PluginServiceFactory<>(watcherCtx, ClassUtil.createProjectClassLoader(watcherCtx.getProject(), watcherCtx.getLogger())) : new PluginServiceFactory<>(watcherCtx);
    boolean isOpenshift = KubernetesHelper.isOpenShift(watcherCtx.getKubernetesClient());
    PlatformMode mode = isOpenshift ? PlatformMode.openshift : PlatformMode.kubernetes;
    List<Watcher> watchers = pluginFactory.createServiceObjects("META-INF/fabric8/watcher-default", "META-INF/fabric8/fabric8-watcher-default", "META-INF/fabric8/watcher", "META-INF/fabric8-watcher");
    ProcessorConfig config = watcherCtx.getConfig();
    Logger log = watcherCtx.getLogger();
    List<Watcher> usableWatchers = config.prepareProcessors(watchers, "watcher");
    log.verbose("Watchers:");
    Watcher chosen = null;
    for (Watcher watcher : usableWatchers) {
        if (watcher.isApplicable(ret, resources, mode)) {
            if (chosen == null) {
                log.verbose(" - %s [selected]", watcher.getName());
                chosen = watcher;
            } else {
                log.verbose(" - %s", watcher.getName());
            }
        } else {
            log.verbose(" - %s [not applicable]", watcher.getName());
        }
    }
    if (chosen == null) {
        throw new IllegalStateException("No watchers can be used for the current project");
    }
    log.info("Running watcher %s", chosen.getName());
    chosen.watch(ret, resources, mode);
}
Also used : WatcherContext(io.fabric8.maven.watcher.api.WatcherContext) Watcher(io.fabric8.maven.watcher.api.Watcher) PlatformMode(io.fabric8.maven.core.config.PlatformMode) Logger(io.fabric8.maven.docker.util.Logger) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig)

Example 10 with ProcessorConfig

use of io.fabric8.maven.core.config.ProcessorConfig 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)

Aggregations

ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)27 Test (org.junit.Test)21 Expectations (mockit.Expectations)17 TreeMap (java.util.TreeMap)10 Probe (io.fabric8.kubernetes.api.model.Probe)7 GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)5 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)4 ArrayList (java.util.ArrayList)3 MavenProject (org.apache.maven.project.MavenProject)3 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)2 Logger (io.fabric8.maven.docker.util.Logger)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)1 PodTemplate (io.fabric8.kubernetes.api.model.PodTemplate)1 ReplicaSet (io.fabric8.kubernetes.api.model.extensions.ReplicaSet)1 PlatformMode (io.fabric8.maven.core.config.PlatformMode)1 Profile (io.fabric8.maven.core.config.Profile)1 Generator (io.fabric8.maven.generator.api.Generator)1 Watcher (io.fabric8.maven.watcher.api.Watcher)1