use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project kubernetes by ballerinax.
the class OpenShiftBuildConfigTest method noCacheAndForcePullTest.
/**
* Test case openshift build config annotation with force pull and caching disabled when docker image building.
*/
@Test(groups = { "openshift" })
public void noCacheAndForcePullTest() throws IOException, InterruptedException, KubernetesPluginException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "cache_and_force_pull.bal"), 0);
File yamlFile = new File(KUBERNETES_TARGET_PATH + File.separator + "cache_and_force_pull.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(), "helloep-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"), "helloep-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(), "cache_and_force_pull: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.assertTrue(bc.getSpec().getStrategy().getDockerStrategy().getForcePull(), "Force pull image set to false");
Assert.assertTrue(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(), "cache_and_force_pull", "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"), "helloep-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 OpenShiftBuildConfigTest method buildProject.
/**
* Test case openshift build config annotation with a ballerina project.
*/
@Test(groups = { "openshift" })
public void buildProject() throws IOException, InterruptedException, KubernetesPluginException {
Path projectPath = BAL_DIRECTORY.resolve("print-project");
Path targetPath = projectPath.resolve("target");
Path moduleArtifacts = targetPath.resolve(KUBERNETES).resolve("printer");
Assert.assertEquals(KubernetesTestUtils.compileBallerinaProject(projectPath.toAbsolutePath()), 0);
File yamlFile = moduleArtifacts.resolve("doodle-printer-1.0.0.yaml").toAbsolutePath().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 "BuildConfig":
BuildConfig bc = (BuildConfig) data;
// metadata
Assert.assertNotNull(bc.getMetadata());
Assert.assertEquals(bc.getMetadata().getName(), "printep-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"), "printep-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(), "printer: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(), "printer", "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"), "printep-openshift-bc", "Invalid label 'build' label value.");
Assert.assertNull(is.getSpec());
break;
default:
Assert.fail("Unexpected k8s resource found: " + data.getKind());
break;
}
}
KubernetesUtils.deleteDirectory(targetPath);
KubernetesUtils.deleteDirectory(targetPath.resolve(DOCKER).resolve("printer"));
}
use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project kubernetes by ballerinax.
the class Sample8Test method compileSample.
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_config_map_k8s.bal"), 0);
File artifactYaml = KUBERNETES_TARGET_PATH.resolve("hello_world_config_map_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 "ConfigMap":
switch(data.getMetadata().getName()) {
case "helloworld-ballerina-conf-config-map":
ballerinaConf = (ConfigMap) data;
break;
case "helloworld-config-map":
dataMap = (ConfigMap) data;
break;
default:
break;
}
break;
case "Service":
case "Secret":
case "Ingress":
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 Sample4Test method compileSample.
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_ssl_k8s.bal"), 0);
File artifactYaml = KUBERNETES_TARGET_PATH.resolve("hello_world_ssl_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 "Secret":
secret = (Secret) data;
break;
case "Ingress":
ingress = (Ingress) data;
break;
case "Service":
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 Sample7Test method compileSample.
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_secret_mount_k8s.bal"), 0);
File artifactYaml = KUBERNETES_TARGET_PATH.resolve("hello_world_secret_mount_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 "Secret":
switch(data.getMetadata().getName()) {
case "helloworldep-secure-socket":
sslSecret = (Secret) data;
break;
case "private":
privateSecret = (Secret) data;
break;
case "public":
publicSecret = (Secret) data;
break;
case "helloworld-ballerina-conf-secret":
ballerinaConf = (Secret) data;
break;
default:
break;
}
break;
case "Service":
case "Ingress":
break;
default:
Assert.fail("Unexpected k8s resource found: " + data.getKind());
break;
}
}
}
Aggregations