Search in sources :

Example 1 with PlatformMode

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);
}
Also used : KitLogger(org.eclipse.jkube.kit.common.KitLogger) PlatformMode(org.eclipse.jkube.kit.config.resource.PlatformMode) PluginServiceFactory(org.eclipse.jkube.kit.common.util.PluginServiceFactory)

Example 2 with PlatformMode

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);
    }
}
Also used : ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) OpenshiftHelper(org.eclipse.jkube.kit.common.util.OpenshiftHelper) ClusterAccess(org.eclipse.jkube.kit.config.access.ClusterAccess) Container(io.fabric8.kubernetes.api.model.Container) ReplicationControllerSpec(io.fabric8.kubernetes.api.model.ReplicationControllerSpec) Date(java.util.Date) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) WatchContext(org.eclipse.jkube.kit.build.service.docker.watch.WatchContext) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) WatcherContext(org.eclipse.jkube.watcher.api.WatcherContext) PlatformMode(org.eclipse.jkube.kit.config.resource.PlatformMode) ReplicaSetSpec(io.fabric8.kubernetes.api.model.apps.ReplicaSetSpec) PipedInputStream(java.io.PipedInputStream) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) Duration(java.time.Duration) DeploymentSpec(io.fabric8.kubernetes.api.model.apps.DeploymentSpec) ImageNameFormatter(org.eclipse.jkube.kit.build.service.docker.helper.ImageNameFormatter) BaseWatcher(org.eclipse.jkube.watcher.api.BaseWatcher) PrintWriter(java.io.PrintWriter) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) Collection(java.util.Collection) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) IOException(java.io.IOException) KubernetesHelper(org.eclipse.jkube.kit.common.util.KubernetesHelper) FileInputStream(java.io.FileInputStream) PipedOutputStream(java.io.PipedOutputStream) WatchException(org.eclipse.jkube.kit.build.service.docker.watch.WatchException) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) File(java.io.File) DockerServiceHub(org.eclipse.jkube.kit.build.service.docker.DockerServiceHub) KitLogger(org.eclipse.jkube.kit.common.KitLogger) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) DeploymentConfigSpec(io.fabric8.openshift.api.model.DeploymentConfigSpec) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) WatchService(org.eclipse.jkube.kit.build.service.docker.WatchService) Base64InputStream(org.apache.commons.codec.binary.Base64InputStream) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) DockerServiceHub(org.eclipse.jkube.kit.build.service.docker.DockerServiceHub) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) IOException(java.io.IOException) WatchException(org.eclipse.jkube.kit.build.service.docker.watch.WatchException) WatchContext(org.eclipse.jkube.kit.build.service.docker.watch.WatchContext)

Aggregations

KitLogger (org.eclipse.jkube.kit.common.KitLogger)2 PlatformMode (org.eclipse.jkube.kit.config.resource.PlatformMode)2 Container (io.fabric8.kubernetes.api.model.Container)1 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)1 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)1 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)1 ReplicationControllerSpec (io.fabric8.kubernetes.api.model.ReplicationControllerSpec)1 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)1 DeploymentSpec (io.fabric8.kubernetes.api.model.apps.DeploymentSpec)1 ReplicaSet (io.fabric8.kubernetes.api.model.apps.ReplicaSet)1 ReplicaSetSpec (io.fabric8.kubernetes.api.model.apps.ReplicaSetSpec)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)1 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)1 DeploymentConfigSpec (io.fabric8.openshift.api.model.DeploymentConfigSpec)1 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1