Search in sources :

Example 41 with Client

use of io.fabric8.kubernetes.client.Client in project watchdog by isdream.

the class OpenshiftListenerTest method main.

public static void main(String[] args) {
    // Configure config = new Parser().parse("config/podWatcher.yaml");
    Configure config = null;
    try {
        config = new Parser().parse("config/podWatcher.yaml");
        OpenShiftClient client = getClient("https", "master.example.com", "8443", "NaD95GPF8rIpbphyCyep--pJQH7t3pzBBV9aXQE77O4");
        Listener listener = new OpenShiftListener();
        listener.start(client, config);
        Thread.sleep(600000);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : OpenShiftListener(com.github.isdream.cwatcher.listeners.OpenShiftListener) OpenShiftListener(com.github.isdream.cwatcher.listeners.OpenShiftListener) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) FileNotFoundException(java.io.FileNotFoundException) FileNotFoundException(java.io.FileNotFoundException)

Example 42 with Client

use of io.fabric8.kubernetes.client.Client in project ballerina by ballerina-lang.

the class TestUtils method deleteDockerImage.

public static void deleteDockerImage(String imageName) {
    if (!imageName.contains(":")) {
        imageName += ":" + Constants.IMAGE_VERSION_LATEST;
    }
    DockerClient client = new io.fabric8.docker.client.DefaultDockerClient();
    List<ImageDelete> imageDeleteList = client.image().withName(imageName).delete().force().andPrune(false);
    for (ImageDelete imageDelete : imageDeleteList) {
        imageDelete.getDeleted();
        imageDelete.getUntagged();
    }
}
Also used : ImageDelete(io.fabric8.docker.api.model.ImageDelete) DockerClient(io.fabric8.docker.client.DockerClient)

Example 43 with Client

use of io.fabric8.kubernetes.client.Client in project ballerina by ballerina-lang.

the class DefaultBallerinaDockerClient method buildImage.

/*
    Execute a Docker image build using Fabric8 DSL.
     */
private void buildImage(String dockerEnv, String imageName, Path tmpDir, String buildArgs) throws InterruptedException, IOException {
    DockerClient client = getDockerClient(dockerEnv);
    OutputHandle buildHandle = client.image().build().withRepositoryName(imageName).withNoCache().alwaysRemovingIntermediate().withBuildArgs(buildArgs).usingListener(new DockerBuilderEventListener()).fromFolder(tmpDir.toString());
    buildDone.await();
    buildHandle.close();
    client.close();
}
Also used : DockerClient(io.fabric8.docker.client.DockerClient) BallerinaDockerClient(org.ballerinalang.containers.docker.BallerinaDockerClient) OutputHandle(io.fabric8.docker.dsl.OutputHandle)

Example 44 with Client

use of io.fabric8.kubernetes.client.Client in project fabric8-maven-plugin by fabric8io.

the class PortForwardServiceTest method testSimpleScenario.

@Test
public void testSimpleScenario() throws Exception {
    // Cannot test more complex scenarios due to errors in mockwebserver
    OpenShiftMockServer mockServer = new OpenShiftMockServer(false);
    Pod pod1 = new PodBuilder().withNewMetadata().withName("mypod").addToLabels("mykey", "myvalue").withResourceVersion("1").endMetadata().withNewStatus().withPhase("run").endStatus().build();
    PodList pods1 = new PodListBuilder().withItems(pod1).withNewMetadata().withResourceVersion("1").endMetadata().build();
    mockServer.expect().get().withPath("/api/v1/namespaces/test/pods?labelSelector=mykey%3Dmyvalue").andReturn(200, pods1).always();
    mockServer.expect().get().withPath("/api/v1/namespaces/test/pods").andReturn(200, pods1).always();
    mockServer.expect().get().withPath("/api/v1/namespaces/test/pods?labelSelector=mykey%3Dmyvalue&watch=true").andUpgradeToWebSocket().open().waitFor(1000).andEmit(new WatchEvent(pod1, "MODIFIED")).done().always();
    mockServer.expect().get().withPath("/api/v1/namespaces/test/pods?resourceVersion=1&watch=true").andUpgradeToWebSocket().open().waitFor(1000).andEmit(new WatchEvent(pod1, "MODIFIED")).done().always();
    OpenShiftClient client = mockServer.createOpenShiftClient();
    PortForwardService service = new PortForwardService(clientToolsService, logger, client) {

        @Override
        public ProcessUtil.ProcessExecutionContext forwardPortAsync(Logger externalProcessLogger, String pod, int remotePort, int localPort) throws Fabric8ServiceException {
            return new ProcessUtil.ProcessExecutionContext(process, Collections.<Thread>emptyList(), logger);
        }
    };
    try (Closeable c = service.forwardPortAsync(logger, new LabelSelectorBuilder().withMatchLabels(Collections.singletonMap("mykey", "myvalue")).build(), 8080, 9000)) {
        Thread.sleep(3000);
    }
}
Also used : LabelSelectorBuilder(io.fabric8.kubernetes.api.model.LabelSelectorBuilder) PodList(io.fabric8.kubernetes.api.model.PodList) Pod(io.fabric8.kubernetes.api.model.Pod) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) Closeable(java.io.Closeable) Logger(io.fabric8.maven.docker.util.Logger) ProcessUtil(io.fabric8.maven.core.util.ProcessUtil) PodListBuilder(io.fabric8.kubernetes.api.model.PodListBuilder) OpenShiftMockServer(io.fabric8.openshift.client.server.mock.OpenShiftMockServer) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) WatchEvent(io.fabric8.kubernetes.api.model.WatchEvent) Test(org.junit.Test)

Example 45 with Client

use of io.fabric8.kubernetes.client.Client in project fabric8-maven-plugin by fabric8io.

the class OpenshiftBuildServiceTest method testFailedBuild.

@Test(expected = Fabric8ServiceException.class)
public void testFailedBuild() throws Exception {
    BuildService.BuildServiceConfig config = defaultConfig.build();
    WebServerEventCollector<OpenShiftMockServer> collector = createMockServer(config, false, 50, false, false);
    OpenShiftMockServer mockServer = collector.getMockServer();
    OpenShiftClient client = mockServer.createOpenShiftClient();
    OpenshiftBuildService service = new OpenshiftBuildService(client, logger, dockerServiceHub, config);
    service.build(image);
}
Also used : OpenShiftMockServer(io.fabric8.openshift.client.server.mock.OpenShiftMockServer) BuildService(io.fabric8.maven.core.service.BuildService) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Test(org.junit.Test)

Aggregations

KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)42 Test (org.junit.Test)34 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)29 Service (io.fabric8.kubernetes.api.model.Service)24 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)23 IOException (java.io.IOException)23 File (java.io.File)22 ArrayList (java.util.ArrayList)21 HashMap (java.util.HashMap)20 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)18 Pod (io.fabric8.kubernetes.api.model.Pod)14 DefaultOpenShiftClient (io.fabric8.openshift.client.DefaultOpenShiftClient)14 ClientInvokerImpl (io.fabric8.dosgi.tcp.ClientInvokerImpl)8 ServerInvokerImpl (io.fabric8.dosgi.tcp.ServerInvokerImpl)8 URL (java.net.URL)8 Map (java.util.Map)8 ServerInvoker (io.fabric8.dosgi.io.ServerInvoker)7 DockerClient (io.fabric8.docker.client.DockerClient)6 MalformedURLException (java.net.MalformedURLException)6 Session (io.fabric8.arquillian.kubernetes.Session)5