Search in sources :

Example 96 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project kubernetes by ballerinax.

the class ServiceTest method nodePortTest.

@Test
public void nodePortTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "node_port.bal"), 0);
    File yamlFile = KUBERNETES_TARGET_PATH.resolve("node_port.yaml").toFile();
    Assert.assertTrue(yamlFile.exists());
    KubernetesClient client = new DefaultKubernetesClient();
    List<HasMetadata> k8sItems = client.load(new FileInputStream(yamlFile)).get();
    for (HasMetadata data : k8sItems) {
        if ("Service".equals(data.getKind())) {
            Service service = (Service) data;
            Assert.assertNotNull(service);
            Assert.assertEquals("hello", service.getMetadata().getName());
            Assert.assertEquals("node_port", service.getMetadata().getLabels().get(KubernetesConstants.KUBERNETES_SELECTOR_KEY));
            Assert.assertEquals(KubernetesConstants.ServiceType.NodePort.name(), service.getSpec().getType());
            Assert.assertEquals(1, service.getSpec().getPorts().size());
            Assert.assertEquals(31100, service.getSpec().getPorts().get(0).getNodePort().intValue());
        }
    }
    validateDockerfile();
    validateDockerImage(DOCKER_IMAGE);
    KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
    KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
    KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Service(io.fabric8.kubernetes.api.model.Service) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test)

Example 97 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project kubernetes by ballerinax.

the class Sample12Test method compileSample.

@BeforeClass
public void compileSample() throws IOException, InterruptedException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_copy_file.bal"), 0);
    File artifactYaml = KUBERNETES_TARGET_PATH.resolve("hello_world_copy_file.yaml").toFile();
    Assert.assertTrue(artifactYaml.exists());
    KubernetesClient client = new DefaultKubernetesClient();
    List<HasMetadata> k8sItems = client.load(new FileInputStream(artifactYaml)).get();
    for (HasMetadata data : k8sItems) {
        switch(data.getKind()) {
            case "Deployment":
                deployment = (Deployment) data;
                break;
            case "Service":
            case "Ingress":
            case "Secret":
                break;
            default:
                Assert.fail("Unexpected k8s resource found: " + data.getKind());
                break;
        }
    }
}
Also used : DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) File(java.io.File) FileInputStream(java.io.FileInputStream) BeforeClass(org.testng.annotations.BeforeClass)

Example 98 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project kubernetes by ballerinax.

the class Sample18Test method compileSample.

@BeforeClass
public void compileSample() throws IOException, InterruptedException {
    Assert.assertEquals(KnativeTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_knative.bal"), 0);
    File artifactYaml = KUBERNETES_TARGET_PATH.resolve(KNATIVE).resolve("hello_world_knative.yaml").toFile();
    Assert.assertTrue(artifactYaml.exists());
    Handlers.register(new KnativeTestUtils.ServiceHandler());
    KubernetesClient client = new DefaultKubernetesClient();
    List<HasMetadata> k8sItems = client.load(new FileInputStream(artifactYaml)).get();
    for (HasMetadata data : k8sItems) {
        if ("Service".equals(data.getKind())) {
            this.knativeService = (Service) data;
        } else {
            Assert.fail("Unexpected k8s/knative resource found: " + data.getKind());
        }
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) KnativeTestUtils(org.ballerinax.kubernetes.test.utils.KnativeTestUtils) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) File(java.io.File) FileInputStream(java.io.FileInputStream) BeforeClass(org.testng.annotations.BeforeClass)

Example 99 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project kubernetes by ballerinax.

the class Sample11Test method compileSample.

@BeforeClass
public void compileSample() throws IOException, InterruptedException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_job.bal"), 0);
    File artifactYaml = KUBERNETES_TARGET_PATH.resolve("hello_world_job.yaml").toFile();
    Assert.assertTrue(artifactYaml.exists());
    KubernetesClient client = new DefaultKubernetesClient();
    List<HasMetadata> k8sItems = client.load(new FileInputStream(artifactYaml)).get();
    for (HasMetadata data : k8sItems) {
        if ("Job".equals(data.getKind())) {
            job = (Job) data;
        } else {
            Assert.fail("Unexpected k8s resource found: " + data.getKind());
        }
    }
}
Also used : DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) File(java.io.File) FileInputStream(java.io.FileInputStream) BeforeClass(org.testng.annotations.BeforeClass)

Example 100 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project kubernetes by ballerinax.

the class OpenShiftRouteTest method noDomainTest.

/**
 * Test case openshift route with host domain.
 */
@Test(groups = { "openshift" })
public void noDomainTest() throws IOException, InterruptedException, KubernetesPluginException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "with_domain.bal"), 0);
    File yamlFile = KUBERNETES_TARGET_PATH.resolve("with_domain.yaml").toFile();
    Assert.assertTrue(yamlFile.exists());
    KubernetesClient client = new DefaultKubernetesClient();
    List<HasMetadata> k8sItems = client.load(new FileInputStream(yamlFile)).get();
    for (HasMetadata data : k8sItems) {
        switch(data.getKind()) {
            case "Service":
            case "Deployment":
                break;
            case "Route":
                Route route = (Route) data;
                // metadata
                Assert.assertNotNull(route.getMetadata());
                Assert.assertEquals(route.getMetadata().getName(), "helloep-openshift-route", "Invalid name found.");
                Assert.assertEquals(route.getMetadata().getNamespace(), "ns", "Namespace is missing.");
                // spec
                Assert.assertNotNull(route.getSpec(), "Spec is missing.");
                Assert.assertEquals(route.getSpec().getHost(), "helloep-openshift-route-ns.abc.com", "Invalid host");
                Assert.assertNotNull(route.getSpec().getPort());
                Assert.assertEquals(route.getSpec().getPort().getTargetPort().getIntVal().intValue(), 9090, "Invalid port found");
                Assert.assertNotNull(route.getSpec().getTo(), "To is missing.");
                Assert.assertEquals(route.getSpec().getTo().getKind(), "Service", "Kind is missing.");
                Assert.assertEquals(route.getSpec().getTo().getName(), "helloep-svc", "Service name is invalid.");
                Assert.assertEquals(route.getSpec().getTo().getWeight().intValue(), 100, "Invalid route weight.");
                break;
            default:
                Assert.fail("Unexpected k8s resource found: " + data.getKind());
                break;
        }
    }
    KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
    KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
    KubernetesTestUtils.deleteDockerImage("with_domain:latest");
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) File(java.io.File) FileInputStream(java.io.FileInputStream) Route(io.fabric8.openshift.api.model.Route) Test(org.testng.annotations.Test)

Aggregations

DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)101 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)77 File (java.io.File)27 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)22 FileInputStream (java.io.FileInputStream)22 HashMap (java.util.HashMap)13 Test (org.testng.annotations.Test)12 Config (io.fabric8.kubernetes.client.Config)11 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)11 BeforeClass (org.testng.annotations.BeforeClass)10 Service (io.fabric8.kubernetes.api.model.Service)8 ConfigBuilder (io.fabric8.kubernetes.client.ConfigBuilder)7 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)7 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)6 TaskAction (org.gradle.api.tasks.TaskAction)6 Pod (io.fabric8.kubernetes.api.model.Pod)5 Map (java.util.Map)5 Test (org.junit.Test)5 KubernetesModelGenerator (com.github.isdream.chameleon.container.kubernetes.KubernetesModelGenerator)4 ImmutableMap (com.google.common.collect.ImmutableMap)4