Search in sources :

Example 21 with DefaultKubernetesClient

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

the class OpenShiftBuildConfigTest method serviceAnnotationTest.

/**
 * Test case openshift build config annotation with a service.
 */
@Test(groups = { "openshift" })
public void serviceAnnotationTest() throws IOException, InterruptedException, KubernetesPluginException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "annotation_on_service.bal"), 0);
    File yamlFile = new File(KUBERNETES_TARGET_PATH + File.separator + "annotation_on_service.yaml");
    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 "BuildConfig":
                BuildConfig bc = (BuildConfig) data;
                // metadata
                Assert.assertNotNull(bc.getMetadata());
                Assert.assertEquals(bc.getMetadata().getName(), "helloworld-openshift-bc", "Invalid name found.");
                Assert.assertNotNull(bc.getMetadata().getLabels(), "Labels are missing");
                Assert.assertEquals(bc.getMetadata().getLabels().size(), 1, "Labels are missing");
                Assert.assertNotNull(bc.getMetadata().getLabels().get("build"), "'build' label is missing");
                Assert.assertEquals(bc.getMetadata().getLabels().get("build"), "helloworld-openshift-bc", "Invalid label 'build' label value.");
                // spec
                Assert.assertNotNull(bc.getSpec());
                Assert.assertNotNull(bc.getSpec().getOutput());
                Assert.assertNotNull(bc.getSpec().getOutput().getTo());
                Assert.assertEquals(bc.getSpec().getOutput().getTo().getKind(), "ImageStreamTag", "Invalid output kind.");
                Assert.assertEquals(bc.getSpec().getOutput().getTo().getName(), "annotation_on_service:latest", "Invalid image stream name.");
                Assert.assertNotNull(bc.getSpec().getSource());
                Assert.assertNotNull(bc.getSpec().getSource().getBinary(), "Binary source is missing");
                Assert.assertNotNull(bc.getSpec().getStrategy());
                Assert.assertNotNull(bc.getSpec().getStrategy().getDockerStrategy(), "Docker strategy is missing.");
                Assert.assertEquals(bc.getSpec().getStrategy().getDockerStrategy().getBuildArgs().size(), 0, "Invalid number of build args.");
                Assert.assertEquals(bc.getSpec().getStrategy().getDockerStrategy().getDockerfilePath(), "kubernetes/docker/Dockerfile", "Invalid docker path.");
                Assert.assertFalse(bc.getSpec().getStrategy().getDockerStrategy().getForcePull(), "Force pull image set to false");
                Assert.assertFalse(bc.getSpec().getStrategy().getDockerStrategy().getNoCache(), "No cache for image build set to false");
                break;
            case "ImageStream":
                ImageStream is = (ImageStream) data;
                Assert.assertNotNull(is.getMetadata());
                Assert.assertEquals(is.getMetadata().getName(), "annotation_on_service", "Invalid name found.");
                Assert.assertEquals(is.getMetadata().getLabels().size(), 1, "Labels are missing");
                Assert.assertNotNull(is.getMetadata().getLabels().get("build"), "'build' label is missing");
                Assert.assertEquals(is.getMetadata().getLabels().get("build"), "helloworld-openshift-bc", "Invalid label 'build' label value.");
                Assert.assertNull(is.getSpec());
                break;
            default:
                Assert.fail("Unexpected k8s resource found: " + data.getKind());
                break;
        }
    }
    KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
    KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ImageStream(io.fabric8.openshift.api.model.ImageStream) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test)

Example 22 with DefaultKubernetesClient

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

the class Sample1Test method compileSample.

@BeforeClass
public void compileSample() throws IOException, InterruptedException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_k8s.bal"), 0);
    File artifactYaml = KUBERNETES_TARGET_PATH.resolve("hello_world_k8s.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":
                service = (Service) data;
                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 23 with DefaultKubernetesClient

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

the class Sample3Test method compileSample.

@BeforeClass
public void compileSample() throws IOException, InterruptedException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "foodstore.bal"), 0);
    File artifactYaml = KUBERNETES_TARGET_PATH.resolve("foodstore.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":
                switch(data.getMetadata().getName()) {
                    case "pizzaep-svc":
                        pizzaSvc = (Service) data;
                        break;
                    case "burgerep-svc":
                        burgerSvc = (Service) data;
                        break;
                    default:
                        break;
                }
                break;
            case "Ingress":
                switch(data.getMetadata().getName()) {
                    case "pizzaep-ingress":
                        pizzaIngress = (Ingress) data;
                        break;
                    case "burgerep-ingress":
                        burgerIngress = (Ingress) data;
                        break;
                    default:
                        break;
                }
                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 24 with DefaultKubernetesClient

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

the class Sample19Test method compileSample.

@BeforeClass
public void compileSample() throws IOException, InterruptedException {
    Assert.assertEquals(KnativeTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_knative_config_map.bal"), 0);
    File artifactYaml = KUBERNETES_TARGET_PATH.resolve(KNATIVE).resolve("hello_world_knative_config_map.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) {
        switch(data.getKind()) {
            case "Service":
                this.knativeService = (Service) data;
                break;
            case "ConfigMap":
                switch(data.getMetadata().getName()) {
                    case "helloworld-ballerina-conf-config-map":
                        this.ballerinaConf = (ConfigMap) data;
                        break;
                    case "helloworld-config-map":
                        this.dataMap = (ConfigMap) data;
                        break;
                    default:
                        break;
                }
                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) 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 25 with DefaultKubernetesClient

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

the class Sample5Test method compileSample.

@BeforeClass
public void compileSample() throws IOException, InterruptedException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "pizzashack.bal"), 0);
    File artifactYaml = KUBERNETES_TARGET_PATH.resolve("pizzashack.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 "HorizontalPodAutoscaler":
                podAutoscaler = (HorizontalPodAutoscaler) data;
                break;
            case "Service":
            case "Ingress":
            case "Secret":
            case "Deployment":
                break;
            default:
                Assert.fail("Unexpected k8s resource found: " + data.getKind());
                break;
        }
    }
}
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) BeforeClass(org.testng.annotations.BeforeClass)

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