Search in sources :

Example 81 with Client

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

the class SessionListener method generateSecrets.

private Set<Secret> generateSecrets(KubernetesClient client, Session session, ObjectMeta meta) {
    Set<Secret> secrets = new HashSet<>();
    Map<String, String> annotations = meta.getAnnotations();
    if (annotations != null && !annotations.isEmpty()) {
        for (Map.Entry<String, String> entry : annotations.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            if (SecretKeys.isSecretKey(key)) {
                SecretKeys keyType = SecretKeys.fromValue(key);
                for (String name : Secrets.getNames(value)) {
                    Map<String, String> data = new HashMap<>();
                    Secret secret = null;
                    try {
                        secret = client.secrets().inNamespace(session.getNamespace()).withName(name).get();
                    } catch (Exception e) {
                    // ignore - probably doesn't exist
                    }
                    if (secret == null) {
                        for (String c : Secrets.getContents(value, name)) {
                            data.put(c, keyType.generate());
                        }
                        secret = client.secrets().inNamespace(session.getNamespace()).createNew().withNewMetadata().withName(name).endMetadata().withData(data).done();
                        secrets.add(secret);
                    }
                }
            }
        }
    }
    return secrets;
}
Also used : Util.readAsString(io.fabric8.arquillian.utils.Util.readAsString) SecretKeys(io.fabric8.arquillian.utils.SecretKeys) MultiException(io.fabric8.utils.MultiException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException)

Example 82 with Client

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

the class J4pClientProvider method lookup.

@Override
public Object lookup(ArquillianResource resource, Annotation... qualifiers) {
    KubernetesClient client = this.clientInstance.get();
    Session session = this.sessionInstance.get();
    JolokiaClients jolokiaClients = new JolokiaClients(client);
    String serviceName = getServiceName(qualifiers);
    String podName = getPodName(qualifiers);
    String replicationControllerName = getReplicationControllerName(qualifiers);
    if (Strings.isNotBlank(serviceName)) {
        Service service = client.services().inNamespace(session.getNamespace()).withName(serviceName).get();
        if (service != null) {
            return jolokiaClients.clientForService(service);
        }
    }
    if (Strings.isNotBlank(podName)) {
        Pod pod = client.pods().inNamespace(session.getNamespace()).withName(serviceName).get();
        if (pod != null) {
            return jolokiaClients.clientForPod(pod);
        }
    }
    if (Strings.isNotBlank(replicationControllerName)) {
        ReplicationController replicationController = client.replicationControllers().inNamespace(session.getNamespace()).withName(replicationControllerName).get();
        if (replicationController != null) {
            return jolokiaClients.clientForReplicationController(replicationController);
        }
    }
    return null;
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Pod(io.fabric8.kubernetes.api.model.Pod) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) Service(io.fabric8.kubernetes.api.model.Service) JolokiaClients(io.fabric8.kubernetes.jolokia.JolokiaClients) Session(io.fabric8.arquillian.kubernetes.Session)

Example 83 with Client

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

the class PodResourceProvider method lookup.

@Override
public Object lookup(ArquillianResource resource, Annotation... qualifiers) {
    KubernetesClient client = this.clientInstance.get();
    Session session = sessionInstance.get();
    String name = getPodName(qualifiers);
    if (name != null) {
        return client.pods().inNamespace(session.getNamespace()).withName(name).get();
    }
    // Gets the first pod found that matches the labels.
    Map<String, String> labels = getLabels(qualifiers);
    PodList list = client.pods().inNamespace(session.getNamespace()).withLabels(labels).list();
    List<Pod> pods = notNullList(list.getItems());
    if (!pods.isEmpty()) {
        return pods.get(0);
    }
    return null;
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) PodList(io.fabric8.kubernetes.api.model.PodList) Pod(io.fabric8.kubernetes.api.model.Pod) Session(io.fabric8.arquillian.kubernetes.Session)

Example 84 with Client

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

the class ReplicationControllerListResourceProvider method lookup.

@Override
public Object lookup(ArquillianResource resource, Annotation... qualifiers) {
    KubernetesClient client = this.clientInstance.get();
    Session session = sessionInstance.get();
    Map<String, String> labels = getLabels(qualifiers);
    if (labels.isEmpty()) {
        return client.replicationControllers().inNamespace(session.getNamespace()).list();
    } else {
        return client.replicationControllers().inNamespace(session.getNamespace()).withLabels(labels).list();
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Session(io.fabric8.arquillian.kubernetes.Session)

Example 85 with Client

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

the class ReplicationControllerResourceProvider method lookup.

@Override
public Object lookup(ArquillianResource resource, Annotation... qualifiers) {
    KubernetesClient client = this.clientInstance.get();
    Session session = sessionInstance.get();
    String name = getReplicationControllerName(qualifiers);
    return client.replicationControllers().inNamespace(session.getNamespace()).withName(name).get();
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Session(io.fabric8.arquillian.kubernetes.Session)

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