Search in sources :

Example 71 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project fabric8 by jboss-fuse.

the class ProcessTemplateLocallyTest method testProcessTemplateLocally.

@Test
public void testProcessTemplateLocally() throws Exception {
    Template template = assertParseExampleFile("template.json", Template.class);
    List<HasMetadata> objects = template.getObjects();
    assertNotEmpty("objects", objects);
    KubernetesList list = Templates.processTemplatesLocally(template, true);
    assertThat(list).describedAs("results").isNotNull();
    List<HasMetadata> items = list.getItems();
    assertThat(items).describedAs("items").isNotNull();
    ReplicationController rc = (ReplicationController) items.get(1);
    assertEquals("Template value not replaced: items[1].spec.template.spec.containers[0].env[0].value", "https://github.com/fabric8io/jenkins-pipeline-dsl.git", rc.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv().get(0).getValue());
    System.out.println("Created JSON: " + toJson(list));
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Template(io.fabric8.openshift.api.model.Template) Test(org.junit.Test)

Example 72 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project fabric8 by jboss-fuse.

the class Util method cleanupAllMatching.

public static void cleanupAllMatching(KubernetesClient client, Session session, List<Throwable> errors, List<KubernetesList> kubeConfigs) throws MultiException {
    String sessionNamespace = session.getNamespace();
    session.getLogger().info("Removing provisioned resources in namespace " + sessionNamespace);
    /**
     * Lets use a loop to ensure we really do delete all the matching resources
     */
    for (int i = 0; i < 10; i++) {
        for (KubernetesList list : kubeConfigs) {
            List<HasMetadata> items = list.getItems();
            if (items != null) {
                for (HasMetadata item : items) {
                    cleanupItem(client, session, item, errors);
                }
            }
        }
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList)

Example 73 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method testCreateServiceResourceForInvalidResource.

@Test
public void testCreateServiceResourceForInvalidResource() throws Exception {
    OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
    KubernetesGatewayImpl kubernetesGateway = getKubernetesGatewayImpl(openShiftClient);
    HasMetadata invalidMetadata = Mockito.mock(Deployment.class);
    List<HasMetadata> serviceResources = new ArrayList<>();
    serviceResources.add(invalidMetadata);
    Mockito.when(openShiftClient.load(Mockito.any()).get()).thenReturn(serviceResources);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    try {
        kubernetesGateway.createContainerGateway(ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX, api);
    } catch (ContainerBasedGatewayException e) {
        Assert.assertEquals(e.getErrorHandler(), ExceptionCodes.LOADED_RESOURCE_DEFINITION_IS_NOT_VALID);
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) ArrayList(java.util.ArrayList) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) API(org.wso2.carbon.apimgt.core.models.API) Test(org.junit.Test)

Example 74 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method testCreateDeploymentResourceForInvalidResource.

@Test
public void testCreateDeploymentResourceForInvalidResource() throws Exception {
    OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
    KubernetesGatewayImpl kubernetesGateway = getKubernetesGatewayImpl(openShiftClient);
    HasMetadata invalidMetadata = Mockito.mock(Service.class);
    List<HasMetadata> deploymentResources = new ArrayList<>();
    deploymentResources.add(invalidMetadata);
    Mockito.when(openShiftClient.load(Mockito.any()).get()).thenReturn(getServiceResources(), deploymentResources);
    NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
    ScalableResource scalableResource = Mockito.mock(ScalableResource.class);
    Mockito.when(scalableResource.get()).thenReturn(null);
    Service service = createService(openShiftClient, nonNamespaceOperation);
    Mockito.when(nonNamespaceOperation.create(Mockito.any())).thenReturn(service);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    try {
        kubernetesGateway.createContainerGateway(ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX, api);
    } catch (ContainerBasedGatewayException e) {
        Assert.assertEquals(e.getErrorHandler(), ExceptionCodes.LOADED_RESOURCE_DEFINITION_IS_NOT_VALID);
    }
}
Also used : ScalableResource(io.fabric8.kubernetes.client.dsl.ScalableResource) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) ArrayList(java.util.ArrayList) Service(io.fabric8.kubernetes.api.model.Service) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) API(org.wso2.carbon.apimgt.core.models.API) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.junit.Test)

Example 75 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project vertx-openshift-it by cescoffier.

the class ConfigurationIT method deployApp.

private static String deployApp(String name, String templatePath) throws IOException {
    String appName;
    List<? extends HasMetadata> entities = deploymentAssistant.deploy(name, new File(templatePath));
    Optional<String> first = entities.stream().filter(hm -> hm instanceof DeploymentConfig).map(hm -> (DeploymentConfig) hm).map(dc -> dc.getMetadata().getName()).findFirst();
    if (first.isPresent()) {
        appName = first.get();
    } else {
        throw new IllegalStateException("Application deployment config not found");
    }
    Route route = deploymentAssistant.getRoute(appName);
    assertThat(route).isNotNull();
    return "http://" + route.getSpec().getHost();
}
Also used : BeforeClass(org.junit.BeforeClass) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) URISyntaxException(java.net.URISyntaxException) OC(io.vertx.it.openshift.utils.OC) JsonPath(io.restassured.path.json.JsonPath) Route(io.fabric8.openshift.api.model.Route) AbstractTestClass(io.vertx.it.openshift.utils.AbstractTestClass) Map(java.util.Map) RestAssured.get(io.restassured.RestAssured.get) Awaitility.await(org.awaitility.Awaitility.await) AfterClass(org.junit.AfterClass) ImmutableMap(com.google.common.collect.ImmutableMap) Pod(io.fabric8.kubernetes.api.model.Pod) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) Test(org.junit.Test) IOException(java.io.IOException) DoneableConfigMap(io.fabric8.kubernetes.api.model.DoneableConfigMap) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) File(java.io.File) Ensure.ensureThat(io.vertx.it.openshift.utils.Ensure.ensureThat) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Optional(java.util.Optional) RestAssured(io.restassured.RestAssured) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) File(java.io.File) Route(io.fabric8.openshift.api.model.Route)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)90 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)25 File (java.io.File)24 IOException (java.io.IOException)24 Template (io.fabric8.openshift.api.model.Template)19 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)18 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)18 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)18 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)17 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)16 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)14 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)14 Service (io.fabric8.kubernetes.api.model.Service)14 URL (java.net.URL)11 HashMap (java.util.HashMap)11 ReplicaSet (io.fabric8.kubernetes.api.model.extensions.ReplicaSet)10 Map (java.util.Map)10 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)9