Java Code Examples for io.fabric8.kubernetes.api.model.HasMetadata#getKind()

The following examples show how to use io.fabric8.kubernetes.api.model.HasMetadata#getKind() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Sample14Test.java    From module-ballerina-kubernetes with Apache License 2.0 6 votes vote down vote up
@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;
        }
    }
}
 
Example 2
Source File: Sample4Test.java    From module-ballerina-kubernetes with Apache License 2.0 6 votes vote down vote up
@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;
        }
    }
}
 
Example 3
Source File: Sample9Test.java    From module-ballerina-kubernetes with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH,
            "hello_world_persistence_volume_k8s.bal"), 0);
    File yamlFile = KUBERNETES_TARGET_PATH.resolve("hello_world_persistence_volume_k8s.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 "PersistentVolumeClaim":
                volumeClaim = (PersistentVolumeClaim) data;
                break;
            default:
                break;
        }
    }
}
 
Example 4
Source File: Sample2Test.java    From module-ballerina-kubernetes with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_k8s_config.bal"), 0);
    File yamlFile = new File(KUBERNETES_TARGET_PATH + File.separator + "hello_world_k8s_config.yaml");
    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;
        }
    }
}
 
Example 5
Source File: Sample1Test.java    From module-ballerina-kubernetes with Apache License 2.0 6 votes vote down vote up
@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;
        }
    }
}
 
Example 6
Source File: Readiness.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
public static boolean isReady(HasMetadata item) {
  if (item instanceof Deployment) {
    return isDeploymentReady((Deployment) item);
  } else if (item instanceof ReplicaSet) {
    return isReplicaSetReady((ReplicaSet) item);
  } else if (item instanceof Pod) {
    return isPodReady((Pod) item);
  } else if (item instanceof DeploymentConfig) {
    return isDeploymentConfigReady((DeploymentConfig) item);
  } else if (item instanceof ReplicationController) {
    return isReplicationControllerReady((ReplicationController) item);
  } else if (item instanceof Endpoints) {
    return isEndpointsReady((Endpoints) item);
  } else if (item instanceof Node) {
    return isNodeReady((Node) item);
  } else if (item instanceof StatefulSet) {
    return isStatefulSetReady((StatefulSet) item);
  } else {
    throw new IllegalArgumentException("Item needs to be one of [Node, Deployment, ReplicaSet, StatefulSet, Pod, DeploymentConfig, ReplicationController], but was: [" + (item != null ? item.getKind() : "Unknown (null)") + "]");
  }
}
 
Example 7
Source File: Sample16Test.java    From module-ballerina-kubernetes with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaProject(SOURCE_DIR_PATH, true), 0);
    File yamlFile = TRAVEL_AGENCY_PKG_K8S_TARGET_PATH.resolve("travel_agency.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 "Gateway":
                gateway = (Gateway) data;
                break;
            case "VirtualService":
                virtualService = (VirtualService) data;
                break;
            default:
                break;
        }
    }
}
 
Example 8
Source File: ValidationUtil.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
public static String createValidationMessage(Set<ConstraintViolation<?>> constraintViolations) {
    if (constraintViolations.isEmpty()) {
        return "No Constraint Validations!";
    }
    StringBuilder builder = new StringBuilder("Constraint Validations: ");
    for (ConstraintViolation<?> violation : constraintViolations) {
        if (builder.length() > 0) {
            builder.append(", ");
        }
        Object leafBean = violation.getLeafBean();
        if (leafBean instanceof HasMetadata) {
            HasMetadata hasMetadata = (HasMetadata) leafBean;
            ObjectMeta metadata = hasMetadata.getMetadata();
            if (metadata != null) {
                leafBean = "" + hasMetadata.getKind() + ": " + metadata;
            }
        }
        builder.append(violation.getPropertyPath() + " " + violation.getMessage() + " on bean: " + leafBean);
    }
    return builder.toString();
}
 
Example 9
Source File: Sample7Test.java    From module-ballerina-kubernetes with Apache License 2.0 5 votes vote down vote up
@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;
        }
    }
}
 
Example 10
Source File: Sample8Test.java    From module-ballerina-kubernetes with Apache License 2.0 5 votes vote down vote up
@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;
        }
    }
}
 
Example 11
Source File: Sample19Test.java    From module-ballerina-kubernetes with Apache License 2.0 5 votes vote down vote up
@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;
        }
    }
}
 
Example 12
Source File: AbstractModel.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
/**
 * Set fields needed to generate the OwnerReference object
 *
 * @param parent The resource which should be used as parent. It will be used to gather the date needed for generating OwnerReferences.
 */
protected void setOwnerReference(HasMetadata parent)  {
    this.ownerApiVersion = parent.getApiVersion();
    this.ownerKind = parent.getKind();
    this.ownerUid = parent.getMetadata().getUid();
}
 
Example 13
Source File: OpenShiftRouteTest.java    From module-ballerina-kubernetes with Apache License 2.0 4 votes vote down vote up
/**
 * 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");
}
 
Example 14
Source File: OpenShiftRouteTest.java    From module-ballerina-kubernetes with Apache License 2.0 4 votes vote down vote up
/**
 * 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");
}
 
Example 15
Source File: OpenShiftBuildConfigTest.java    From module-ballerina-kubernetes with Apache License 2.0 4 votes vote down vote up
/**
 * 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("printer.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"));
}
 
Example 16
Source File: OpenShiftBuildConfigTest.java    From module-ballerina-kubernetes with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
}
 
Example 17
Source File: OpenShiftBuildConfigTest.java    From module-ballerina-kubernetes with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
}
 
Example 18
Source File: OpenShiftBuildConfigTest.java    From module-ballerina-kubernetes with Apache License 2.0 4 votes vote down vote up
/**
 * Test case openshift build config annotation with a main function.
 */
@Test(groups = {"openshift"})
public void mainFunctionTest() throws IOException, InterruptedException, KubernetesPluginException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "main_function.bal"), 0);
    File yamlFile = new File(KUBERNETES_TARGET_PATH + File.separator + "main_function.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(), "main-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"), "main-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(), "main_function: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(), "main_function", "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"), "main-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);
}
 
Example 19
Source File: Sample3Test.java    From module-ballerina-kubernetes with Apache License 2.0 4 votes vote down vote up
@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;
        }
    }
}
 
Example 20
Source File: OpenShiftBuildConfigTest.java    From module-ballerina-kubernetes with Apache License 2.0 4 votes vote down vote up
/**
 * Test case openshift build config annotation with default values.
 */
@Test(groups = {"openshift"})
public void simpleBuildConfigTest() throws IOException, InterruptedException, KubernetesPluginException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "simple_bc.bal"), 0);
    File yamlFile = new File(KUBERNETES_TARGET_PATH + File.separator + "simple_bc.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(), "simple_bc: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(), "simple_bc", "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);
}