Search in sources :

Example 6 with ClusterAccess

use of org.eclipse.jkube.kit.config.access.ClusterAccess in project jkube by eclipse.

the class AbstractJKubeMojo method init.

protected void init() throws DependencyResolutionRequiredException {
    log = createLogger(null);
    clusterAccess = new ClusterAccess(log, initClusterConfiguration());
    javaProject = MavenUtil.convertMavenProjectToJKubeProject(project, session);
    jkubeServiceHub = initJKubeServiceHubBuilder(javaProject).build();
    resources = updateResourceConfigNamespace(namespace, resources);
}
Also used : ClusterAccess(org.eclipse.jkube.kit.config.access.ClusterAccess)

Example 7 with ClusterAccess

use of org.eclipse.jkube.kit.config.access.ClusterAccess in project jkube by eclipse.

the class DockerImageWatcher method executeCommandInPod.

private String executeCommandInPod(String command, Collection<HasMetadata> resources) throws IOException, WatchException {
    ClusterAccess clusterAccess = getContext().getJKubeServiceHub().getClusterAccess();
    try {
        final PodExecutor podExecutor = new PodExecutor(clusterAccess, WAIT_TIMEOUT);
        podExecutor.executeCommandInPod(resources, command);
        return podExecutor.getOutput();
    } catch (InterruptedException exception) {
        log.error("Execute command task interrupted");
        Thread.currentThread().interrupt();
    }
    return null;
}
Also used : ClusterAccess(org.eclipse.jkube.kit.config.access.ClusterAccess)

Example 8 with ClusterAccess

use of org.eclipse.jkube.kit.config.access.ClusterAccess in project jkube by eclipse.

the class DockerImageWatcher method copyFileToPod.

private void copyFileToPod(File fileToUpload, Collection<HasMetadata> resources) throws IOException, WatchException {
    ClusterAccess clusterAccess = getContext().getJKubeServiceHub().getClusterAccess();
    try (final PipedOutputStream pos = new PipedOutputStream();
        final PipedInputStream pis = new PipedInputStream(pos)) {
        final Runnable filePusher = uploadFilesRunnable(fileToUpload, pos, log);
        final PodExecutor podExecutor = new PodExecutor(clusterAccess, pis, WAIT_TIMEOUT, filePusher);
        podExecutor.executeCommandInPod(resources, "sh");
    } catch (InterruptedException exception) {
        log.error("Copy files task interrupted");
        Thread.currentThread().interrupt();
    }
}
Also used : ClusterAccess(org.eclipse.jkube.kit.config.access.ClusterAccess) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream)

Example 9 with ClusterAccess

use of org.eclipse.jkube.kit.config.access.ClusterAccess in project jkube by eclipse.

the class DockerImageWatcher method restartContainer.

protected void restartContainer(WatchService.ImageWatcher watcher, Collection<HasMetadata> resources) {
    ImageConfiguration imageConfig = watcher.getImageConfiguration();
    String imageName = imageConfig.getName();
    ClusterAccess clusterAccess = getContext().getJKubeServiceHub().getClusterAccess();
    try (KubernetesClient client = clusterAccess.createDefaultClient()) {
        String namespace = clusterAccess.getNamespace();
        String imagePrefix = getImagePrefix(imageName);
        for (HasMetadata entity : resources) {
            updateImageName(client, namespace, entity, imagePrefix, imageName);
        }
    } catch (KubernetesClientException e) {
        KubernetesHelper.handleKubernetesClientException(e, this.log);
    } catch (IllegalStateException e) {
        throw e;
    } catch (Exception e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ClusterAccess(org.eclipse.jkube.kit.config.access.ClusterAccess) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) IOException(java.io.IOException) WatchException(org.eclipse.jkube.kit.build.service.docker.watch.WatchException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 10 with ClusterAccess

use of org.eclipse.jkube.kit.config.access.ClusterAccess in project jkube by eclipse.

the class OpenshiftBuildService method initClient.

private void initClient() {
    ClusterAccess clusterAccess = jKubeServiceHub.getClusterAccess();
    if (clusterAccess == null) {
        clusterAccess = new ClusterAccess(log, ClusterConfiguration.from(System.getProperties(), jKubeServiceHub.getConfiguration().getProject().getProperties()).build());
    }
    KubernetesClient k8sClient = clusterAccess.createDefaultClient();
    if (!isOpenShift(k8sClient)) {
        throw new IllegalStateException("OpenShift platform has been specified but OpenShift has not been detected!");
    }
    client = (OpenShiftClient) k8sClient;
    if (buildServiceConfig.getResourceConfig() != null && buildServiceConfig.getResourceConfig().getNamespace() != null) {
        applicableOpenShiftNamespace = buildServiceConfig.getResourceConfig().getNamespace();
    } else {
        applicableOpenShiftNamespace = clusterAccess.getNamespace();
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ClusterAccess(org.eclipse.jkube.kit.config.access.ClusterAccess)

Aggregations

ClusterAccess (org.eclipse.jkube.kit.config.access.ClusterAccess)11 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 IOException (java.io.IOException)2 LogOutputSpecFactory (org.eclipse.jkube.kit.build.service.docker.access.log.LogOutputSpecFactory)2 Test (org.junit.Test)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)1 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 AuthConfigFactory (org.eclipse.jkube.kit.build.service.docker.auth.AuthConfigFactory)1 ImageConfigResolver (org.eclipse.jkube.kit.build.service.docker.config.handler.ImageConfigResolver)1 WatchException (org.eclipse.jkube.kit.build.service.docker.watch.WatchException)1 JKubeConfiguration (org.eclipse.jkube.kit.common.JKubeConfiguration)1 KitLogger (org.eclipse.jkube.kit.common.KitLogger)1 MigrateService (org.eclipse.jkube.kit.common.service.MigrateService)1 AnsiLogger (org.eclipse.jkube.kit.common.util.AnsiLogger)1 ImageConfiguration (org.eclipse.jkube.kit.config.image.ImageConfiguration)1 KubernetesUndeployService (org.eclipse.jkube.kit.config.service.kubernetes.KubernetesUndeployService)1 OpenshiftUndeployService (org.eclipse.jkube.kit.config.service.openshift.OpenshiftUndeployService)1