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);
}
}
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();
}
}
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);
}
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.");
}
}
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);
}
Aggregations