Search in sources :

Example 91 with DefaultKubernetesClient

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

the class OpenShiftBuildConfigTest method noCacheAndForcePullTest.

/**
 * Test case openshift build config annotation with force pull and caching disabled when docker image building.
 */
@Test(groups = { "openshift" })
public void noCacheAndForcePullTest() throws IOException, InterruptedException, KubernetesPluginException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "cache_and_force_pull.bal"), 0);
    File yamlFile = new File(KUBERNETES_TARGET_PATH + File.separator + "cache_and_force_pull.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(), "helloep-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"), "helloep-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(), "cache_and_force_pull: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.assertTrue(bc.getSpec().getStrategy().getDockerStrategy().getForcePull(), "Force pull image set to false");
                Assert.assertTrue(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(), "cache_and_force_pull", "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"), "helloep-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 92 with DefaultKubernetesClient

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

the class OpenShiftBuildConfigTest method buildProject.

/**
 * Test case openshift build config annotation with a ballerina project.
 */
@Test(groups = { "openshift" })
public void buildProject() throws IOException, InterruptedException, KubernetesPluginException {
    Path projectPath = BAL_DIRECTORY.resolve("print-project");
    Path targetPath = projectPath.resolve("target");
    Path moduleArtifacts = targetPath.resolve(KUBERNETES).resolve("printer");
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaProject(projectPath.toAbsolutePath()), 0);
    File yamlFile = moduleArtifacts.resolve("doodle-printer-1.0.0.yaml").toAbsolutePath().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 "BuildConfig":
                BuildConfig bc = (BuildConfig) data;
                // metadata
                Assert.assertNotNull(bc.getMetadata());
                Assert.assertEquals(bc.getMetadata().getName(), "printep-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"), "printep-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(), "printer: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(), "printer", "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"), "printep-openshift-bc", "Invalid label 'build' label value.");
                Assert.assertNull(is.getSpec());
                break;
            default:
                Assert.fail("Unexpected k8s resource found: " + data.getKind());
                break;
        }
    }
    KubernetesUtils.deleteDirectory(targetPath);
    KubernetesUtils.deleteDirectory(targetPath.resolve(DOCKER).resolve("printer"));
}
Also used : Path(java.nio.file.Path) 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 93 with DefaultKubernetesClient

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

the class Sample8Test method compileSample.

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

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

the class Sample4Test method compileSample.

@BeforeClass
public void compileSample() throws IOException, InterruptedException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_ssl_k8s.bal"), 0);
    File artifactYaml = KUBERNETES_TARGET_PATH.resolve("hello_world_ssl_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 "Secret":
                secret = (Secret) data;
                break;
            case "Ingress":
                ingress = (Ingress) data;
                break;
            case "Service":
                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 95 with DefaultKubernetesClient

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

the class Sample7Test method compileSample.

@BeforeClass
public void compileSample() throws IOException, InterruptedException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_secret_mount_k8s.bal"), 0);
    File artifactYaml = KUBERNETES_TARGET_PATH.resolve("hello_world_secret_mount_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 "Secret":
                switch(data.getMetadata().getName()) {
                    case "helloworldep-secure-socket":
                        sslSecret = (Secret) data;
                        break;
                    case "private":
                        privateSecret = (Secret) data;
                        break;
                    case "public":
                        publicSecret = (Secret) data;
                        break;
                    case "helloworld-ballerina-conf-secret":
                        ballerinaConf = (Secret) data;
                        break;
                    default:
                        break;
                }
                break;
            case "Service":
            case "Ingress":
                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)

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