use of io.fabric8.kubernetes.client.DefaultKubernetesClient 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.client.DefaultKubernetesClient 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");
}
use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project kubernetes by ballerinax.
the class NoAnnotationsTest method mainWithNoAnnotationTest.
@Test(timeOut = 90000)
public void mainWithNoAnnotationTest() throws IOException, InterruptedException, DockerTestException, KubernetesPluginException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "no_annotations_main.bal"), 0);
File yamlFile = KUBERNETES_TARGET_PATH.resolve("no_annotations_main.yaml").toFile();
Assert.assertTrue(yamlFile.exists());
KubernetesClient client = new DefaultKubernetesClient();
List<HasMetadata> k8sItems = client.load(new FileInputStream(yamlFile)).get();
for (HasMetadata data : k8sItems) {
if ("Job".equals(data.getKind())) {
Job job = (Job) data;
Assert.assertEquals(job.getMetadata().getName(), "no-annotations-main-job");
Assert.assertEquals(job.getSpec().getTemplate().getSpec().getContainers().size(), 1);
Container container = job.getSpec().getTemplate().getSpec().getContainers().get(0);
Assert.assertEquals(container.getImage(), "no_annotations_main:latest");
Assert.assertEquals(container.getImagePullPolicy(), KubernetesConstants.ImagePullPolicy.IfNotPresent.name());
Assert.assertEquals(job.getSpec().getTemplate().getSpec().getRestartPolicy(), KubernetesConstants.RestartPolicy.Never.name());
}
}
validateDockerfile();
KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
KubernetesTestUtils.deleteDockerImage("no_annotations_main:latest");
}
use of io.fabric8.kubernetes.client.DefaultKubernetesClient 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.client.DefaultKubernetesClient in project kubernetes by ballerinax.
the class ServiceTest method portAndTargetPortTest.
@Test
public void portAndTargetPortTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "port_and_target_port.bal"), 0);
File yamlFile = KUBERNETES_TARGET_PATH.resolve("port_and_target_port.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.assertNotNull(service);
Assert.assertEquals("hello", service.getMetadata().getName());
Assert.assertEquals("port_and_target_port", service.getMetadata().getLabels().get(KubernetesConstants.KUBERNETES_SELECTOR_KEY));
Assert.assertEquals(KubernetesConstants.ServiceType.ClusterIP.name(), service.getSpec().getType());
Assert.assertEquals(1, service.getSpec().getPorts().size());
Assert.assertEquals(8080, service.getSpec().getPorts().get(0).getPort().intValue());
Assert.assertEquals(9090, service.getSpec().getPorts().get(0).getTargetPort().getIntVal().intValue());
}
}
validateDockerfile();
validateDockerImage(DOCKER_IMAGE);
KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
Aggregations