Search in sources :

Example 61 with Deployment

use of io.fabric8.kubernetes.api.model.apps.Deployment 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 62 with Deployment

use of io.fabric8.kubernetes.api.model.apps.Deployment in project kubernetes by ballerinax.

the class Sample3Test method validateDeployment.

@Test
public void validateDeployment() {
    Assert.assertNotNull(deployment);
    Assert.assertEquals(deployment.getMetadata().getName(), SELECTOR_APP);
    Assert.assertEquals(deployment.getSpec().getReplicas().intValue(), 3);
    Assert.assertEquals(deployment.getMetadata().getLabels().get(KubernetesConstants.KUBERNETES_SELECTOR_KEY), SELECTOR_APP);
    Assert.assertEquals(deployment.getSpec().getTemplate().getSpec().getContainers().size(), 1);
    Container container = deployment.getSpec().getTemplate().getSpec().getContainers().get(0);
    Assert.assertEquals(container.getImage(), DOCKER_IMAGE);
    Assert.assertEquals(container.getImagePullPolicy(), KubernetesConstants.ImagePullPolicy.IfNotPresent.name());
    Assert.assertEquals(container.getPorts().size(), 2);
    Assert.assertEquals(container.getEnv().size(), 0);
    Assert.assertEquals(container.getLivenessProbe().getPeriodSeconds().intValue(), 5);
    Assert.assertEquals(container.getLivenessProbe().getInitialDelaySeconds().intValue(), 10);
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) Test(org.testng.annotations.Test)

Example 63 with Deployment

use of io.fabric8.kubernetes.api.model.apps.Deployment 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 64 with Deployment

use of io.fabric8.kubernetes.api.model.apps.Deployment 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)

Example 65 with Deployment

use of io.fabric8.kubernetes.api.model.apps.Deployment in project kubernetes by ballerinax.

the class EnvVarTest method secretKeyRefTest.

/**
 * Build bal file with deployment having name and configMapKeyRef environment variables.
 * @throws IOException Error when loading the generated yaml.
 * @throws InterruptedException Error when compiling the ballerina file.
 * @throws KubernetesPluginException Error when deleting the generated artifacts folder.
 */
@Test
public void secretKeyRefTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "secret_key_ref.bal"), 0);
    // Check if docker image exists and correct
    validateDockerfile();
    validateDockerImage();
    // Validate deployment yaml
    File deploymentYAML = KUBERNETES_TARGET_PATH.resolve("secret_key_ref_deployment.yaml").toFile();
    Assert.assertTrue(deploymentYAML.exists());
    Deployment deployment = KubernetesTestUtils.loadYaml(deploymentYAML);
    List<EnvVar> envVars = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv();
    Assert.assertEquals(envVars.size(), 2, "Invalid number of environment variables found.");
    Assert.assertEquals(envVars.get(0).getName(), "SECRET_USERNAME", "Invalid environment variable name found.");
    Assert.assertEquals(envVars.get(0).getValueFrom().getSecretKeyRef().getName(), "test-secret", "Invalid environment variable value found.");
    Assert.assertEquals(envVars.get(0).getValueFrom().getSecretKeyRef().getKey(), "username", "Invalid environment variable value found.");
    Assert.assertEquals(envVars.get(1).getName(), "SECRET_PASSWORD", "Invalid environment variable name found.");
    Assert.assertEquals(envVars.get(1).getValueFrom().getSecretKeyRef().getName(), "test-secret", "Invalid environment variable value found.");
    Assert.assertEquals(envVars.get(1).getValueFrom().getSecretKeyRef().getKey(), "password", "Invalid environment variable value found.");
    KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
    KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
    KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
Also used : Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

File (java.io.File)62 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)52 Test (org.testng.annotations.Test)50 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)47 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)43 Container (io.fabric8.kubernetes.api.model.Container)32 Service (io.fabric8.kubernetes.api.model.Service)28 Test (org.junit.Test)28 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)27 InputStream (java.io.InputStream)26 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)25 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)25 Deployment (org.jboss.arquillian.container.test.api.Deployment)21 OSGiManifestBuilder (org.jboss.osgi.metadata.OSGiManifestBuilder)21 Asset (org.jboss.shrinkwrap.api.asset.Asset)21 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)21 IOException (java.io.IOException)20 ServiceTracker (org.osgi.util.tracker.ServiceTracker)20 FileInputStream (java.io.FileInputStream)19 CommandSupport (io.fabric8.itests.support.CommandSupport)18