use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project kubernetes by ballerinax.
the class ServiceTest method nodePortTest.
@Test
public void nodePortTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "node_port.bal"), 0);
File yamlFile = KUBERNETES_TARGET_PATH.resolve("node_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("node_port", service.getMetadata().getLabels().get(KubernetesConstants.KUBERNETES_SELECTOR_KEY));
Assert.assertEquals(KubernetesConstants.ServiceType.NodePort.name(), service.getSpec().getType());
Assert.assertEquals(1, service.getSpec().getPorts().size());
Assert.assertEquals(31100, service.getSpec().getPorts().get(0).getNodePort().intValue());
}
}
validateDockerfile();
validateDockerImage(DOCKER_IMAGE);
KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project kubernetes by ballerinax.
the class Sample12Test method compileSample.
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_copy_file.bal"), 0);
File artifactYaml = KUBERNETES_TARGET_PATH.resolve("hello_world_copy_file.yaml").toFile();
Assert.assertTrue(artifactYaml.exists());
KubernetesClient client = new DefaultKubernetesClient();
List<HasMetadata> k8sItems = client.load(new FileInputStream(artifactYaml)).get();
for (HasMetadata data : k8sItems) {
switch(data.getKind()) {
case "Deployment":
deployment = (Deployment) data;
break;
case "Service":
case "Ingress":
case "Secret":
break;
default:
Assert.fail("Unexpected k8s resource found: " + data.getKind());
break;
}
}
}
use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project kubernetes by ballerinax.
the class Sample18Test method compileSample.
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
Assert.assertEquals(KnativeTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_knative.bal"), 0);
File artifactYaml = KUBERNETES_TARGET_PATH.resolve(KNATIVE).resolve("hello_world_knative.yaml").toFile();
Assert.assertTrue(artifactYaml.exists());
Handlers.register(new KnativeTestUtils.ServiceHandler());
KubernetesClient client = new DefaultKubernetesClient();
List<HasMetadata> k8sItems = client.load(new FileInputStream(artifactYaml)).get();
for (HasMetadata data : k8sItems) {
if ("Service".equals(data.getKind())) {
this.knativeService = (Service) data;
} else {
Assert.fail("Unexpected k8s/knative resource found: " + data.getKind());
}
}
}
use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project kubernetes by ballerinax.
the class Sample11Test method compileSample.
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_job.bal"), 0);
File artifactYaml = KUBERNETES_TARGET_PATH.resolve("hello_world_job.yaml").toFile();
Assert.assertTrue(artifactYaml.exists());
KubernetesClient client = new DefaultKubernetesClient();
List<HasMetadata> k8sItems = client.load(new FileInputStream(artifactYaml)).get();
for (HasMetadata data : k8sItems) {
if ("Job".equals(data.getKind())) {
job = (Job) data;
} else {
Assert.fail("Unexpected k8s resource found: " + data.getKind());
}
}
}
use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project kubernetes by ballerinax.
the class OpenShiftRouteTest method noDomainTest.
/**
* Test case openshift route with host domain.
*/
@Test(groups = { "openshift" })
public void noDomainTest() throws IOException, InterruptedException, KubernetesPluginException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "with_domain.bal"), 0);
File yamlFile = KUBERNETES_TARGET_PATH.resolve("with_domain.yaml").toFile();
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.");
Assert.assertEquals(route.getMetadata().getNamespace(), "ns", "Namespace is missing.");
// spec
Assert.assertNotNull(route.getSpec(), "Spec is missing.");
Assert.assertEquals(route.getSpec().getHost(), "helloep-openshift-route-ns.abc.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("with_domain:latest");
}
Aggregations