use of io.fabric8.kubernetes.api.model.apps.Deployment in project kubernetes by ballerinax.
the class Sample14Test method compileSample.
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_k8s_namespace.bal"), 0);
File yamlFile = KUBERNETES_TARGET_PATH.resolve("hello_world_k8s_namespace.yaml").toFile();
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 Sample16Test method validateTravelAgencyDeployment.
@Test
public void validateTravelAgencyDeployment() {
// Assert Deployment
Assert.assertNotNull(deployment);
Assert.assertNotNull(deployment.getMetadata());
Assert.assertEquals(deployment.getMetadata().getName(), "gogo-travel-agency-1-0-0-deployment");
Assert.assertEquals(deployment.getSpec().getReplicas().intValue(), 1, "Invalid replica value");
Assert.assertEquals(deployment.getMetadata().getLabels().get(KubernetesConstants.KUBERNETES_SELECTOR_KEY), "gogo-travel_agency-1.0.0", "Invalid label");
Assert.assertEquals(deployment.getSpec().getTemplate().getSpec().getContainers().size(), 1, "Invalid number of containers.");
// Assert Containers
Container container = deployment.getSpec().getTemplate().getSpec().getContainers().get(0);
Assert.assertEquals(container.getImage(), TRAVEL_AGENCY_DOCKER_IMAGE, "Invalid container image");
Assert.assertEquals(container.getImagePullPolicy(), KubernetesConstants.ImagePullPolicy.IfNotPresent.name());
Assert.assertEquals(container.getPorts().size(), 1, "Invalid number of container ports");
Assert.assertEquals(container.getPorts().get(0).getContainerPort().intValue(), 9090, "Invalid container port");
}
use of io.fabric8.kubernetes.api.model.apps.Deployment in project kubernetes by ballerinax.
the class StrategyTest method recreateTest.
/**
* 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 recreateTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "recreate.bal"), 0);
// Check if docker image exists and correct
validateDockerfile();
validateDockerImage();
// Validate deployment yaml
File deploymentYAML = KUBERNETES_TARGET_PATH.resolve("recreate_deployment.yaml").toFile();
Assert.assertTrue(deploymentYAML.exists());
Deployment deployment = KubernetesTestUtils.loadYaml(deploymentYAML);
Assert.assertEquals(deployment.getSpec().getStrategy().getType(), "Recreate", "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 NoAnnotationsTest method serviceWithNoAnnotationTest.
@Test(timeOut = 90000)
public void serviceWithNoAnnotationTest() throws IOException, InterruptedException, DockerTestException, KubernetesPluginException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "no_annotation_service.bal"), 0);
File yamlFile = KUBERNETES_TARGET_PATH.resolve("no_annotation_service.yaml").toFile();
Assert.assertTrue(yamlFile.exists());
KubernetesClient client = new DefaultKubernetesClient();
List<HasMetadata> k8sItems = client.load(new FileInputStream(yamlFile)).get();
for (HasMetadata data : k8sItems) {
if ("Service".equals(data.getKind())) {
Service service = (Service) data;
Assert.assertEquals(service.getMetadata().getName(), "helloworld-svc");
Assert.assertEquals(service.getMetadata().getLabels().get(KubernetesConstants.KUBERNETES_SELECTOR_KEY), "no_annotation_service");
Assert.assertEquals(service.getSpec().getType(), KubernetesConstants.ServiceType.NodePort.name());
Assert.assertEquals(service.getSpec().getPorts().size(), 1);
Assert.assertEquals(service.getSpec().getPorts().get(0).getPort().intValue(), 9090);
}
if ("Deployment".equals(data.getKind())) {
Deployment deployment = (Deployment) data;
Assert.assertEquals(deployment.getMetadata().getName(), "no-annotation-service-deployment");
Assert.assertEquals(deployment.getSpec().getReplicas().intValue(), 1);
Assert.assertEquals(deployment.getMetadata().getLabels().get(KubernetesConstants.KUBERNETES_SELECTOR_KEY), "no_annotation_service");
Assert.assertEquals(deployment.getSpec().getTemplate().getSpec().getContainers().size(), 1);
Container container = deployment.getSpec().getTemplate().getSpec().getContainers().get(0);
Assert.assertEquals(container.getImage(), "no_annotation_service:latest");
Assert.assertEquals(container.getImagePullPolicy(), KubernetesConstants.ImagePullPolicy.IfNotPresent.name());
Assert.assertEquals(container.getPorts().size(), 1);
Assert.assertEquals(container.getEnv().size(), 0);
}
}
validateDockerfile();
validateDockerImage("no_annotation_service:latest");
KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
KubernetesTestUtils.deleteDockerImage("no_annotation_service:latest");
}
use of io.fabric8.kubernetes.api.model.apps.Deployment in project kubernetes by ballerinax.
the class NoAnnotationsTest method listenerWithNoAnnotationTest.
@Test(timeOut = 90000)
public void listenerWithNoAnnotationTest() throws IOException, InterruptedException, DockerTestException, KubernetesPluginException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "no_annotation_listener.bal"), 0);
File yamlFile = KUBERNETES_TARGET_PATH.resolve("no_annotation_listener.yaml").toFile();
Assert.assertTrue(yamlFile.exists());
KubernetesClient client = new DefaultKubernetesClient();
List<HasMetadata> k8sItems = client.load(new FileInputStream(yamlFile)).get();
for (HasMetadata data : k8sItems) {
if ("Service".equals(data.getKind())) {
Service service = (Service) data;
Assert.assertEquals(service.getMetadata().getName(), "helloworldep-svc");
Assert.assertEquals(service.getMetadata().getLabels().get(KubernetesConstants.KUBERNETES_SELECTOR_KEY), "no_annotation_listener");
Assert.assertEquals(service.getSpec().getType(), KubernetesConstants.ServiceType.NodePort.name());
Assert.assertEquals(service.getSpec().getPorts().size(), 1);
Assert.assertEquals(service.getSpec().getPorts().get(0).getPort().intValue(), 9090);
}
if ("Deployment".equals(data.getKind())) {
Deployment deployment = (Deployment) data;
Assert.assertEquals(deployment.getMetadata().getName(), "no-annotation-listener-deployment");
Assert.assertEquals(deployment.getSpec().getReplicas().intValue(), 1);
Assert.assertEquals(deployment.getMetadata().getLabels().get(KubernetesConstants.KUBERNETES_SELECTOR_KEY), "no_annotation_listener");
Assert.assertEquals(deployment.getSpec().getTemplate().getSpec().getContainers().size(), 1);
Container container = deployment.getSpec().getTemplate().getSpec().getContainers().get(0);
Assert.assertEquals(container.getImage(), "no_annotation_listener:latest");
Assert.assertEquals(container.getImagePullPolicy(), KubernetesConstants.ImagePullPolicy.IfNotPresent.name());
Assert.assertEquals(container.getPorts().size(), 1);
Assert.assertEquals(container.getEnv().size(), 0);
}
}
validateDockerfile();
validateDockerImage("no_annotation_listener:latest");
KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
KubernetesTestUtils.deleteDockerImage("no_annotation_listener:latest");
}
Aggregations