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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations