use of io.fabric8.kubernetes.api.model.apps.Deployment in project kubernetes by ballerinax.
the class OpenShiftRouteTest method simpleRoute.
/**
* Test case openshift route with host.
*/
@Test(groups = { "openshift" })
public void simpleRoute() throws IOException, InterruptedException, KubernetesPluginException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "simple_route.bal"), 0);
File yamlFile = new File(KUBERNETES_TARGET_PATH + File.separator + "simple_route.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 "Route":
Route route = (Route) data;
// metadata
Assert.assertNotNull(route.getMetadata());
Assert.assertEquals(route.getMetadata().getName(), "helloep-openshift-route", "Invalid name found.");
// spec
Assert.assertNotNull(route.getSpec(), "Spec is missing.");
Assert.assertEquals(route.getSpec().getHost(), "www.bxoc.com", "Invalid host");
Assert.assertNotNull(route.getSpec().getPort());
Assert.assertEquals(route.getSpec().getPort().getTargetPort().getIntVal().intValue(), 9090, "Invalid port found");
Assert.assertNotNull(route.getSpec().getTo(), "To is missing.");
Assert.assertEquals(route.getSpec().getTo().getKind(), "Service", "Kind is missing.");
Assert.assertEquals(route.getSpec().getTo().getName(), "helloep-svc", "Service name is invalid.");
Assert.assertEquals(route.getSpec().getTo().getWeight().intValue(), 100, "Invalid route weight.");
break;
default:
Assert.fail("Unexpected k8s resource found: " + data.getKind());
break;
}
}
KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
KubernetesTestUtils.deleteDockerImage("simple_route:latest");
}
use of io.fabric8.kubernetes.api.model.apps.Deployment in project kubernetes by ballerinax.
the class ReadinessProbeTest method disabledTest.
/**
* Build bal file with deployment having readiness disabled.
*
* @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 disabledTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "disabled.bal"), 0);
// Check if docker image exists and correct
validateDockerfile();
validateDockerImage();
// Validate deployment yaml
File deploymentYAML = KUBERNETES_TARGET_PATH.resolve("disabled_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.assertNull(deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getReadinessProbe());
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 ReadinessProbeTest method enabledTest.
/**
* Build bal file with deployment having readiness 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).getReadinessProbe(), "Readiness probe is missing.");
Assert.assertEquals(deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getReadinessProbe().getInitialDelaySeconds().intValue(), 3, "initialDelay in readiness probe is missing.");
Assert.assertEquals(deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getReadinessProbe().getPeriodSeconds().intValue(), 1, "periodSeconds in readiness probe is missing.");
Assert.assertEquals(deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getReadinessProbe().getTcpSocket().getPort().getIntVal().intValue(), 9090, "TCP port in readiness 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 Sample2Test method compileSample.
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_k8s_config.bal"), 0);
File yamlFile = new File(KUBERNETES_TARGET_PATH + File.separator + "hello_world_k8s_config.yaml");
Assert.assertTrue(yamlFile.exists());
List<HasMetadata> k8sItems = KubernetesTestUtils.loadYaml(yamlFile);
for (HasMetadata data : k8sItems) {
switch(data.getKind()) {
case "Deployment":
deployment = (Deployment) data;
break;
case "Service":
service = (Service) data;
break;
case "Ingress":
ingress = (Ingress) data;
break;
default:
break;
}
}
}
use of io.fabric8.kubernetes.api.model.apps.Deployment in project kubernetes by ballerinax.
the class Sample4Test method validateDeployment.
@Test
public void validateDeployment() {
Assert.assertNotNull(deployment);
Assert.assertEquals(deployment.getMetadata().getName(), "hello-world-ssl-k8s-deployment");
Assert.assertEquals(deployment.getSpec().getReplicas().intValue(), 1);
Assert.assertEquals(deployment.getSpec().getTemplate().getSpec().getVolumes().get(0).getSecret().getSecretName(), "helloworldsecuredep-keystore");
Assert.assertEquals(deployment.getMetadata().getLabels().get(KubernetesConstants.KUBERNETES_SELECTOR_KEY), SELECTOR_APP);
Assert.assertEquals(deployment.getSpec().getTemplate().getSpec().getContainers().size(), 1);
// Assert Containers
Container container = deployment.getSpec().getTemplate().getSpec().getContainers().get(0);
Assert.assertEquals(container.getVolumeMounts().size(), 1);
Assert.assertEquals(container.getVolumeMounts().get(0).getMountPath(), "/home/ballerina/./security");
Assert.assertEquals(container.getVolumeMounts().get(0).getName(), "helloworldsecuredep-keystore-volume");
Assert.assertTrue(container.getVolumeMounts().get(0).getReadOnly());
Assert.assertEquals(container.getImage(), DOCKER_IMAGE);
Assert.assertEquals(container.getImagePullPolicy(), KubernetesConstants.ImagePullPolicy.IfNotPresent.name());
Assert.assertEquals(container.getPorts().size(), 1);
}
Aggregations