Search in sources :

Example 56 with Deployment

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

the class LivenessProbeTest method ftpTest.

/**
 * Build bal file with deployment having liveness enabled using a boolean.
 *
 * @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 ftpTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "ftp.bal"), 0);
    // Check if docker image exists and correct
    validateDockerfile();
    validateDockerImage();
    // Validate deployment yaml
    File deploymentYAML = KUBERNETES_TARGET_PATH.resolve("ftp_deployment.yaml").toFile();
    Assert.assertTrue(deploymentYAML.exists());
    Deployment deployment = KubernetesTestUtils.loadYaml(deploymentYAML);
    Assert.assertNotNull(deployment.getSpec());
    Assert.assertNotNull(deployment.getSpec().getTemplate());
    Assert.assertNotNull(deployment.getSpec().getTemplate().getSpec());
    Assert.assertTrue(deployment.getSpec().getTemplate().getSpec().getContainers().size() > 0);
    Assert.assertNotNull(deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getLivenessProbe(), "Liveness probe is missing.");
    Assert.assertEquals(deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getLivenessProbe().getInitialDelaySeconds().intValue(), 10, "initialDelay in liveness probe is missing.");
    Assert.assertEquals(deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getLivenessProbe().getPeriodSeconds().intValue(), 5, "periodSeconds in liveness probe is missing.");
    Assert.assertEquals(deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getLivenessProbe().getTcpSocket().getPort().getIntVal().intValue(), 9090, "TCP port in liveness probe is missing.");
    KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
    KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
    KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
Also used : Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) File(java.io.File) Test(org.testng.annotations.Test)

Example 57 with Deployment

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

the class LivenessProbeTest method enabledTest.

/**
 * Build bal file with deployment having liveness enabled using a boolean.
 *
 * @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 enabledTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "enabled.bal"), 0);
    // Check if docker image exists and correct
    validateDockerfile();
    validateDockerImage();
    // Validate deployment yaml
    File deploymentYAML = KUBERNETES_TARGET_PATH.resolve("enabled_deployment.yaml").toFile();
    Assert.assertTrue(deploymentYAML.exists());
    Deployment deployment = KubernetesTestUtils.loadYaml(deploymentYAML);
    Assert.assertNotNull(deployment.getSpec());
    Assert.assertNotNull(deployment.getSpec().getTemplate());
    Assert.assertNotNull(deployment.getSpec().getTemplate().getSpec());
    Assert.assertTrue(deployment.getSpec().getTemplate().getSpec().getContainers().size() > 0);
    Assert.assertNotNull(deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getLivenessProbe(), "Liveness probe is missing.");
    Assert.assertEquals(deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getLivenessProbe().getInitialDelaySeconds().intValue(), 10, "initialDelay in liveness probe is missing.");
    Assert.assertEquals(deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getLivenessProbe().getPeriodSeconds().intValue(), 5, "periodSeconds in liveness probe is missing.");
    Assert.assertEquals(deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getLivenessProbe().getTcpSocket().getPort().getIntVal().intValue(), 9090, "TCP port in liveness probe is missing.");
    KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
    KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
    KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
Also used : Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) File(java.io.File) Test(org.testng.annotations.Test)

Example 58 with Deployment

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

the class DeploymentTest method annotationsTest.

/**
 * Build bal file with deployment having annotations.
 *
 * @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 annotationsTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "dep_annotations.bal"), 0);
    // Check if docker image exists and correct
    validateDockerfile();
    validateDockerImage();
    // Validate deployment yaml
    File deploymentYAML = KUBERNETES_TARGET_PATH.resolve("dep_annotations_deployment.yaml").toFile();
    Assert.assertTrue(deploymentYAML.exists());
    Deployment deployment = KubernetesTestUtils.loadYaml(deploymentYAML);
    Assert.assertEquals(deployment.getMetadata().getAnnotations().size(), 2, "Invalid number of annotations found.");
    Assert.assertEquals(deployment.getMetadata().getAnnotations().get("anno1"), "anno1Val", "Invalid annotation found.");
    Assert.assertEquals(deployment.getMetadata().getAnnotations().get("anno2"), "anno2Val", "Invalid annotation 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) File(java.io.File) Test(org.testng.annotations.Test)

Example 59 with Deployment

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

the class DeploymentTest method projectedVolumeTest.

/**
 * Build bal file with deployment having projectedVolume annotations.
 *
 * @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 projectedVolumeTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "projected.bal"), 0);
    // Check if docker image exists and correct
    validateDockerfile();
    validateDockerImage();
    // Validate deployment yaml
    File deploymentYAML = KUBERNETES_TARGET_PATH.resolve("projected_deployment.yaml").toFile();
    Assert.assertTrue(deploymentYAML.exists());
    Deployment deployment = KubernetesTestUtils.loadYaml(deploymentYAML);
    Assert.assertNotNull(deployment.getSpec());
    Assert.assertNotNull(deployment.getSpec().getTemplate());
    final PodSpec spec = deployment.getSpec().getTemplate().getSpec();
    Assert.assertNotNull(spec);
    Assert.assertEquals(spec.getServiceAccountName(), "build-robot");
    Assert.assertEquals(spec.getContainers().get(0).getVolumeMounts().size(), 1);
    Assert.assertEquals(spec.getContainers().get(0).getVolumeMounts().get(0).getMountPath(), "/tmp/");
    Assert.assertEquals(spec.getContainers().get(0).getVolumeMounts().get(0).getName(), "vault-volume");
    Assert.assertEquals(spec.getVolumes().get(0).getName(), "vault-volume");
    final ServiceAccountTokenProjection serviceAccountToken = spec.getVolumes().get(0).getProjected().getSources().get(0).getServiceAccountToken();
    Assert.assertEquals(serviceAccountToken.getAudience(), "test");
    Assert.assertEquals(serviceAccountToken.getPath(), "vault-volume");
    Assert.assertEquals(serviceAccountToken.getExpirationSeconds(), Long.valueOf("600"));
    KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
    KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
    KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
Also used : ServiceAccountTokenProjection(io.fabric8.kubernetes.api.model.ServiceAccountTokenProjection) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) File(java.io.File) Test(org.testng.annotations.Test)

Example 60 with Deployment

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

the class DeploymentTest method podAnnotationsTest.

/**
 * Build bal file with deployment having pod annotations.
 *
 * @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 podAnnotationsTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "pod_annotations.bal"), 0);
    // Check if docker image exists and correct
    validateDockerfile();
    validateDockerImage();
    // Validate deployment yaml
    File deploymentYAML = KUBERNETES_TARGET_PATH.resolve("pod_annotations_deployment.yaml").toFile();
    Assert.assertTrue(deploymentYAML.exists());
    Deployment deployment = KubernetesTestUtils.loadYaml(deploymentYAML);
    Assert.assertEquals(deployment.getSpec().getTemplate().getMetadata().getAnnotations().size(), 2, "Invalid number of annotations found.");
    Assert.assertEquals(deployment.getSpec().getTemplate().getMetadata().getAnnotations().get("anno1"), "anno1Val", "Invalid annotation found.");
    Assert.assertEquals(deployment.getSpec().getTemplate().getMetadata().getAnnotations().get("anno2"), "anno2Val", "Invalid annotation 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) 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