use of io.fabric8.kubernetes.api.model.apps.Deployment in project kubernetes by ballerinax.
the class OpenShiftBuildConfigTest method serviceAnnotationTest.
/**
* Test case openshift build config annotation with a service.
*/
@Test(groups = { "openshift" })
public void serviceAnnotationTest() throws IOException, InterruptedException, KubernetesPluginException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "annotation_on_service.bal"), 0);
File yamlFile = new File(KUBERNETES_TARGET_PATH + File.separator + "annotation_on_service.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(), "helloworld-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"), "helloworld-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(), "annotation_on_service: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(), "annotation_on_service", "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"), "helloworld-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);
}
use of io.fabric8.kubernetes.api.model.apps.Deployment in project kubernetes by ballerinax.
the class PrometheusTest method nodePortPrometheusTest.
/**
* Build bal file with NodePort prometheus settings.
*
* @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 nodePortPrometheusTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "nodeport.bal"), 0);
// Check if docker image exists and correct
validateDockerfile();
validateDockerImage();
// Validate deployment yaml
File deploymentYAML = KUBERNETES_TARGET_PATH.resolve("nodeport_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);
final List<ContainerPort> ports = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getPorts();
Assert.assertEquals(ports.size(), 2);
Assert.assertEquals(ports.get(0).getContainerPort().intValue(), 9090);
Assert.assertEquals(ports.get(1).getContainerPort().intValue(), 9898);
// Validate svc yaml
File svcYAML = KUBERNETES_TARGET_PATH.resolve("nodeport_svc.yaml").toFile();
Assert.assertTrue(svcYAML.exists());
Service svc = KubernetesTestUtils.loadYaml(svcYAML);
Assert.assertEquals(svc.getSpec().getPorts().size(), 1);
final ServicePort servicePort = svc.getSpec().getPorts().get(0);
Assert.assertEquals(servicePort.getPort().intValue(), 9090);
Assert.assertEquals(servicePort.getProtocol(), "TCP");
Assert.assertEquals(servicePort.getTargetPort().getIntVal().intValue(), 9090);
Assert.assertEquals(svc.getSpec().getType(), "ClusterIP");
Assert.assertEquals(svc.getMetadata().getName(), "helloep-svc");
Assert.assertEquals(svc.getSpec().getSelector().get("app"), "nodeport");
// Validate prometheus svc yaml
File svcPrometheusYAML = KUBERNETES_TARGET_PATH.resolve("nodeport_prometheus_svc.yaml").toFile();
Assert.assertTrue(svcPrometheusYAML.exists());
Service svcPrometheus = KubernetesTestUtils.loadYaml(svcPrometheusYAML);
Assert.assertEquals(svcPrometheus.getSpec().getPorts().size(), 1);
final ServicePort prometheusSvcPort = svcPrometheus.getSpec().getPorts().get(0);
Assert.assertEquals(prometheusSvcPort.getPort().intValue(), 9898);
Assert.assertEquals(prometheusSvcPort.getProtocol(), "TCP");
Assert.assertEquals(prometheusSvcPort.getTargetPort().getIntVal().intValue(), 9898);
Assert.assertEquals(svcPrometheus.getSpec().getType(), "NodePort");
Assert.assertEquals(svcPrometheus.getMetadata().getName(), "helloep-svc-prometheus");
Assert.assertEquals(svcPrometheus.getSpec().getSelector().get("app"), "nodeport");
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 StrategyTest method rollingUpdateTest.
/**
* Build bal file with deployment annotations having strategy 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 rollingUpdateTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "rolling_update.bal"), 0);
// Check if docker image exists and correct
validateDockerfile();
validateDockerImage();
// Validate deployment yaml
File deploymentYAML = KUBERNETES_TARGET_PATH.resolve("rolling_update_deployment.yaml").toFile();
Assert.assertTrue(deploymentYAML.exists());
Deployment deployment = KubernetesTestUtils.loadYaml(deploymentYAML);
Assert.assertEquals(deployment.getSpec().getStrategy().getType(), "RollingUpdate", "Invalid strategy 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 LivenessProbeTest method disabledTest.
/**
* Build bal file with deployment having liveness 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).getLivenessProbe());
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 configuredTest.
/**
* Build bal file with deployment having liveness configured.
*
* @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 configuredTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "configured.bal"), 0);
// Check if docker image exists and correct
validateDockerfile();
validateDockerImage();
// Validate deployment yaml
File deploymentYAML = KUBERNETES_TARGET_PATH.resolve("configured_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(), 20, "initialDelay in liveness probe is missing.");
Assert.assertEquals(deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getLivenessProbe().getPeriodSeconds().intValue(), 10, "periodSeconds in liveness probe is missing.");
Assert.assertEquals(deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getLivenessProbe().getTcpSocket().getPort().getIntVal().intValue(), 8080, "TCP port in liveness probe is missing.");
KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
Aggregations