Search in sources :

Example 66 with Client

use of io.fabric8.kubernetes.client.Client in project fabric8 by fabric8io.

the class OpenShiftAssert method buildConfigs.

public BuildConfigsAssert buildConfigs() {
    BuildConfigList listObject = client.buildConfigs().list();
    assertThat(listObject).describedAs("No BuildConfigsList found!").isNotNull();
    List<BuildConfig> list = listObject.getItems();
    assertThat(list).describedAs("No BuildConfig Items found!").isNotNull();
    return new BuildConfigsAssert(list, client);
}
Also used : BuildConfig(io.fabric8.openshift.api.model.BuildConfig) BuildConfigList(io.fabric8.openshift.api.model.BuildConfigList)

Example 67 with Client

use of io.fabric8.kubernetes.client.Client in project fabric8 by fabric8io.

the class Example method main.

public static void main(String[] args) {
    try {
        final KubernetesClient client = new DefaultKubernetesClient();
        assertThat(client).pods().runningStatus().hasSize(6);
        assertThat(client).pods().runningStatus().filterLabel("provider", "fabric8").assertSize().isGreaterThan(0);
        assertThat(client.services().inNamespace("default").withName("fabric8").get().getMetadata()).name().isEqualTo("fabric8");
        Map<String, String> consoleLabels = new HashMap<>();
        consoleLabels.put("component", "console");
        consoleLabels.put("provider", "fabric8");
        assertThat(client).podsForService("fabric8").runningStatus().extracting("metadata").extracting("labels").contains(consoleLabels);
        assertThat(client).podsForService("fabric8").runningStatus().hasSize(1).extracting("metadata").extracting("labels").contains(consoleLabels);
        assertThat(client).podsForService("fabric8").logs().doesNotContainText("Exception", "Error");
        assertThat(client).pods().logs().doesNotContainText("Exception", "Error");
        assertAssertionError(new Block() {

            @Override
            public void invoke() throws Exception {
                try {
                    assertThat(client.services().inNamespace("default").withName("doesNotExist").get().getMetadata()).name().isEqualTo("fabric8-console-controller");
                } catch (KubernetesClientException e) {
                    if (e.getCode() != 404) {
                        throw e;
                    } else {
                        throw new AssertionError(e);
                    }
                }
            }
        });
        assertAssertionError(new Block() {

            @Override
            public void invoke() throws Exception {
                try {
                    assertThat(client).pods().runningStatus().filterLabel("component", "doesNotExist").hasSize(1);
                } catch (KubernetesClientException e) {
                    if (e.getCode() != 404) {
                        throw e;
                    } else {
                        throw new AssertionError(e);
                    }
                }
            }
        });
        System.out.println("Done!");
    } catch (Throwable e) {
        System.out.println("Caught: " + e);
        e.printStackTrace();
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) HashMap(java.util.HashMap) Asserts.assertAssertionError(io.fabric8.utils.Asserts.assertAssertionError) Block(io.fabric8.utils.Block) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 68 with Client

use of io.fabric8.kubernetes.client.Client in project fabric8 by fabric8io.

the class DeploymentConfigPodsAssert method pods.

public PodSelectionAssert pods() {
    spec().isNotNull().selector().isNotNull();
    DeploymentConfigSpec spec = this.actual.getSpec();
    Integer replicas = spec.getReplicas();
    Map<String, String> matchLabels = spec.getSelector();
    List<LabelSelectorRequirement> matchExpressions = new ArrayList<>();
    return new PodSelectionAssert(client, replicas, matchLabels, matchExpressions, "DeploymentConfig " + KubernetesHelper.getName(actual));
}
Also used : ArrayList(java.util.ArrayList) LabelSelectorRequirement(io.fabric8.kubernetes.api.model.LabelSelectorRequirement) DeploymentConfigSpec(io.fabric8.openshift.api.model.DeploymentConfigSpec)

Example 69 with Client

use of io.fabric8.kubernetes.client.Client in project fabric8 by fabric8io.

the class KubernetesAssert method services.

public ServicesAssert services() {
    ServiceList serviceList = client.services().inNamespace(namespace()).list();
    assertThat(serviceList).isNotNull();
    List<Service> services = serviceList.getItems();
    return new ServicesAssert(client, services);
}
Also used : ServiceList(io.fabric8.kubernetes.api.model.ServiceList) Service(io.fabric8.kubernetes.api.model.Service)

Example 70 with Client

use of io.fabric8.kubernetes.client.Client in project fabric8 by fabric8io.

the class KubernetesAssert method deployments.

/**
 * Finds all the resources that create pod selections (Deployment, DeploymentConfig, ReplicaSet, ReplicationController)
 * and create a {@link HasPodSelectionAssert} to make assertions on their pods that they startup etc.
 *
 * @return the assertion object for the deployment
 */
public HasPodSelectionAssert deployments() {
    List<HasPodSelectionAssert> asserters = new ArrayList<>();
    List<HasMetadata> resources = new ArrayList<>();
    try {
        resources = KubernetesHelper.findKubernetesResourcesOnClasspath(new Controller(client));
    } catch (IOException e) {
        fail("Failed to load kubernetes resources on the classpath: " + e, e);
    }
    for (HasMetadata resource : resources) {
        HasPodSelectionAssert asserter = createPodSelectionAssert(resource);
        if (asserter != null) {
            asserters.add(asserter);
        }
    }
    String message = "No pod selection kinds found on the classpath such as Deployment, DeploymentConfig, ReplicaSet, ReplicationController";
    // TODO we don't yet support size > 1
    assertThat(asserters).describedAs(message).isNotEmpty();
    if (asserters.size() == 1) {
        return asserters.get(0);
    }
    return new MultiHasPodSelectionAssert(asserters);
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Controller(io.fabric8.kubernetes.api.Controller) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController)

Aggregations

KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)42 Test (org.junit.Test)34 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)29 Service (io.fabric8.kubernetes.api.model.Service)24 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)23 IOException (java.io.IOException)23 File (java.io.File)22 ArrayList (java.util.ArrayList)21 HashMap (java.util.HashMap)20 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)18 Pod (io.fabric8.kubernetes.api.model.Pod)14 DefaultOpenShiftClient (io.fabric8.openshift.client.DefaultOpenShiftClient)14 ClientInvokerImpl (io.fabric8.dosgi.tcp.ClientInvokerImpl)8 ServerInvokerImpl (io.fabric8.dosgi.tcp.ServerInvokerImpl)8 URL (java.net.URL)8 Map (java.util.Map)8 ServerInvoker (io.fabric8.dosgi.io.ServerInvoker)7 DockerClient (io.fabric8.docker.client.DockerClient)6 MalformedURLException (java.net.MalformedURLException)6 Session (io.fabric8.arquillian.kubernetes.Session)5