use of org.eclipse.jkube.kit.config.resource.PlatformMode in project jkube by eclipse.
the class WatcherManager method watch.
public static void watch(List<ImageConfiguration> ret, String namespace, Collection<HasMetadata> resources, WatcherContext watcherCtx) throws Exception {
final PluginServiceFactory<WatcherContext> pluginFactory = new PluginServiceFactory<>(watcherCtx);
if (watcherCtx.isUseProjectClasspath()) {
pluginFactory.addAdditionalClassLoader(ClassUtil.createProjectClassLoader(watcherCtx.getBuildContext().getProject().getCompileClassPathElements(), watcherCtx.getLogger()));
}
final boolean isOpenshift = watcherCtx.getJKubeServiceHub().getClusterAccess().isOpenShift();
final PlatformMode mode = isOpenshift ? PlatformMode.openshift : PlatformMode.kubernetes;
final KitLogger log = watcherCtx.getLogger();
final List<Watcher> watchers = pluginFactory.createServiceObjects(SERVICE_PATHS);
final List<Watcher> usableWatchers = watcherCtx.getConfig().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, namespace, resources, mode);
}
use of org.eclipse.jkube.kit.config.resource.PlatformMode in project jkube by eclipse.
the class DockerImageWatcher method watch.
@Override
public void watch(List<ImageConfiguration> configs, String namespace, final Collection<HasMetadata> resources, PlatformMode mode) {
WatchContext watchContext = getContext().getWatchContext();
watchContext = watchContext.toBuilder().imageCustomizer(this::buildImage).containerRestarter(imageWatcher -> restartContainer(imageWatcher, resources)).containerCommandExecutor(command -> executeCommandInPod(command, resources)).containerCopyTask(f -> copyFileToPod(f, resources)).build();
DockerServiceHub hub = getContext().getJKubeServiceHub().getDockerServiceHub();
try {
hub.getWatchService().watch(watchContext, getContext().getBuildContext(), configs);
} catch (Exception ex) {
throw new RuntimeException("Error while watching", ex);
}
}
Aggregations