use of io.fabric8.kubernetes.client.DefaultKubernetesClient 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.client.DefaultKubernetesClient in project kubernetes by ballerinax.
the class Sample1Test method compileSample.
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_k8s.bal"), 0);
File artifactYaml = KUBERNETES_TARGET_PATH.resolve("hello_world_k8s.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":
service = (Service) data;
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 Sample3Test method compileSample.
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "foodstore.bal"), 0);
File artifactYaml = KUBERNETES_TARGET_PATH.resolve("foodstore.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":
switch(data.getMetadata().getName()) {
case "pizzaep-svc":
pizzaSvc = (Service) data;
break;
case "burgerep-svc":
burgerSvc = (Service) data;
break;
default:
break;
}
break;
case "Ingress":
switch(data.getMetadata().getName()) {
case "pizzaep-ingress":
pizzaIngress = (Ingress) data;
break;
case "burgerep-ingress":
burgerIngress = (Ingress) data;
break;
default:
break;
}
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 Sample19Test method compileSample.
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
Assert.assertEquals(KnativeTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_knative_config_map.bal"), 0);
File artifactYaml = KUBERNETES_TARGET_PATH.resolve(KNATIVE).resolve("hello_world_knative_config_map.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) {
switch(data.getKind()) {
case "Service":
this.knativeService = (Service) data;
break;
case "ConfigMap":
switch(data.getMetadata().getName()) {
case "helloworld-ballerina-conf-config-map":
this.ballerinaConf = (ConfigMap) data;
break;
case "helloworld-config-map":
this.dataMap = (ConfigMap) data;
break;
default:
break;
}
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 Sample5Test method compileSample.
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "pizzashack.bal"), 0);
File artifactYaml = KUBERNETES_TARGET_PATH.resolve("pizzashack.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 "HorizontalPodAutoscaler":
podAutoscaler = (HorizontalPodAutoscaler) data;
break;
case "Service":
case "Ingress":
case "Secret":
case "Deployment":
break;
default:
Assert.fail("Unexpected k8s resource found: " + data.getKind());
break;
}
}
}
Aggregations