Search in sources :

Example 1 with PlatformMode

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

the class JavaRunGeneratorTest method fromSelector.

@Test
public void fromSelector() throws IOException {
    Object[] data = { "3.1.123", PlatformMode.kubernetes, null, "java.upstream.docker", "3.1.redhat-101", PlatformMode.kubernetes, null, "java.redhat.docker", "3.1.123", PlatformMode.openshift, OpenShiftBuildStrategy.docker, "java.upstream.docker", "3.1.redhat-101", PlatformMode.openshift, OpenShiftBuildStrategy.docker, "java.redhat.docker", "3.1.123", PlatformMode.openshift, OpenShiftBuildStrategy.s2i, "java.upstream.s2i", "3.1.redhat-101", PlatformMode.openshift, OpenShiftBuildStrategy.s2i, "java.redhat.s2i" };
    Properties imageProps = getDefaultImageProps();
    for (int i = 0; i < data.length; i += 4) {
        prepareExpectation((String) data[i], (PlatformMode) data[i + 1], (OpenShiftBuildStrategy) data[i + 2]);
        final GeneratorContext context = ctx;
        FromSelector selector = new FromSelector.Default(context, "java");
        String from = selector.getFrom();
        assertEquals(imageProps.getProperty((String) data[i + 3]), from);
    }
}
Also used : GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext) FromSelector(io.fabric8.maven.generator.api.FromSelector) Test(org.junit.Test)

Example 2 with PlatformMode

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

the class FromSelector method getFrom.

public String getFrom() {
    PlatformMode mode = context.getMode();
    OpenShiftBuildStrategy strategy = context.getStrategy();
    if (mode == PlatformMode.openshift && strategy == OpenShiftBuildStrategy.s2i) {
        return getS2iBuildFrom();
    } else {
        return getDockerBuildFrom();
    }
}
Also used : PlatformMode(io.fabric8.maven.core.config.PlatformMode) OpenShiftBuildStrategy(io.fabric8.maven.core.config.OpenShiftBuildStrategy)

Example 3 with PlatformMode

use of io.fabric8.maven.core.config.PlatformMode 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 4 with PlatformMode

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

the class SpringBootWatcher method watch.

@Override
public void watch(List<ImageConfiguration> configs, Set<HasMetadata> resources, PlatformMode mode) throws Exception {
    KubernetesClient kubernetes = getContext().getKubernetesClient();
    PodLogService.PodLogServiceContext logContext = new PodLogService.PodLogServiceContext.Builder().log(log).newPodLog(getContext().getNewPodLogger()).oldPodLog(getContext().getOldPodLogger()).build();
    new PodLogService(logContext).tailAppPodsLogs(kubernetes, getContext().getNamespace(), resources, false, null, true, null, false);
    String url = getServiceExposeUrl(kubernetes, resources);
    if (url == null) {
        url = getPortForwardUrl(resources);
    }
    if (url != null) {
        runRemoteSpringApplication(url);
    } else {
        throw new IllegalStateException("Unable to open a channel to the remote pod.");
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) PodLogService(io.fabric8.maven.core.service.PodLogService)

Example 5 with PlatformMode

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

the class ResourceMojo method lateInit.

private void lateInit() throws MojoExecutionException {
    if (goalFinder.runningWithGoal(project, session, "fabric8:watch") || goalFinder.runningWithGoal(project, session, "fabric8:watch")) {
        Properties properties = project.getProperties();
        properties.setProperty("fabric8.watch", "true");
    }
    platformMode = clusterAccess.resolvePlatformMode(mode, log);
    log.info("Running in [[B]]%s[[B]] mode", platformMode.getLabel());
    if (isOpenShiftMode()) {
        Properties properties = project.getProperties();
        if (!properties.contains(DOCKER_IMAGE_USER)) {
            String namespace = clusterAccess.getNamespace();
            log.info("Using docker image name of namespace: " + namespace);
            properties.setProperty(DOCKER_IMAGE_USER, namespace);
        }
        if (!properties.contains(PlatformMode.FABRIC8_EFFECTIVE_PLATFORM_MODE)) {
            properties.setProperty(PlatformMode.FABRIC8_EFFECTIVE_PLATFORM_MODE, platformMode.toString());
        }
    }
    openShiftConverters = new HashMap<>();
    openShiftConverters.put("ReplicaSet", new ReplicSetOpenShiftConverter());
    openShiftConverters.put("Deployment", new DeploymentOpenShiftConverter(platformMode, getOpenshiftDeployTimeoutSeconds()));
    // TODO : This converter shouldn't be here. See its javadoc.
    openShiftConverters.put("DeploymentConfig", new DeploymentConfigOpenShiftConverter(getOpenshiftDeployTimeoutSeconds()));
    openShiftConverters.put("Namespace", new NamespaceOpenShiftConverter());
    handlerHub = new HandlerHub(project);
}
Also used : NamespaceOpenShiftConverter(io.fabric8.maven.plugin.converter.NamespaceOpenShiftConverter) DeploymentConfigOpenShiftConverter(io.fabric8.maven.plugin.converter.DeploymentConfigOpenShiftConverter) DeploymentOpenShiftConverter(io.fabric8.maven.plugin.converter.DeploymentOpenShiftConverter) Properties(java.util.Properties) ReplicSetOpenShiftConverter(io.fabric8.maven.plugin.converter.ReplicSetOpenShiftConverter) HandlerHub(io.fabric8.maven.core.handler.HandlerHub)

Aggregations

DockerBuildService (io.fabric8.maven.core.service.kubernetes.DockerBuildService)3 OpenshiftBuildService (io.fabric8.maven.core.service.openshift.OpenshiftBuildService)3 Test (org.junit.Test)3 PlatformMode (io.fabric8.maven.core.config.PlatformMode)2 Controller (io.fabric8.kubernetes.api.Controller)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)1 OpenShiftBuildStrategy (io.fabric8.maven.core.config.OpenShiftBuildStrategy)1 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)1 HandlerHub (io.fabric8.maven.core.handler.HandlerHub)1 PodLogService (io.fabric8.maven.core.service.PodLogService)1 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)1 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)1 BuildService (io.fabric8.maven.docker.service.BuildService)1 ServiceHub (io.fabric8.maven.docker.service.ServiceHub)1 WatchService (io.fabric8.maven.docker.service.WatchService)1 Logger (io.fabric8.maven.docker.util.Logger)1 Task (io.fabric8.maven.docker.util.Task)1 FromSelector (io.fabric8.maven.generator.api.FromSelector)1 GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)1