Search in sources :

Example 1 with Resource

use of io.fabric8.support.api.Resource in project camel by apache.

the class KubernetesServiceAccountsProducer method doListServiceAccountsByLabels.

protected void doListServiceAccountsByLabels(Exchange exchange, String operation) throws Exception {
    ServiceAccountList saList = null;
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_SERVICE_ACCOUNTS_LABELS, Map.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    if (!ObjectHelper.isEmpty(namespaceName)) {
        NonNamespaceOperation<ServiceAccount, ServiceAccountList, DoneableServiceAccount, Resource<ServiceAccount, DoneableServiceAccount>> serviceAccounts;
        serviceAccounts = getEndpoint().getKubernetesClient().serviceAccounts().inNamespace(namespaceName);
        for (Map.Entry<String, String> entry : labels.entrySet()) {
            serviceAccounts.withLabel(entry.getKey(), entry.getValue());
        }
        saList = serviceAccounts.list();
    } else {
        MixedOperation<ServiceAccount, ServiceAccountList, DoneableServiceAccount, Resource<ServiceAccount, DoneableServiceAccount>> serviceAccounts;
        serviceAccounts = getEndpoint().getKubernetesClient().serviceAccounts();
        for (Map.Entry<String, String> entry : labels.entrySet()) {
            serviceAccounts.withLabel(entry.getKey(), entry.getValue());
        }
        saList = serviceAccounts.list();
    }
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(saList.getItems());
}
Also used : DoneableServiceAccount(io.fabric8.kubernetes.api.model.DoneableServiceAccount) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) DoneableServiceAccount(io.fabric8.kubernetes.api.model.DoneableServiceAccount) Resource(io.fabric8.kubernetes.client.dsl.Resource) Map(java.util.Map) ServiceAccountList(io.fabric8.kubernetes.api.model.ServiceAccountList)

Example 2 with Resource

use of io.fabric8.support.api.Resource in project camel by apache.

the class KubernetesNamespacesProducer method doListNamespaceByLabel.

protected void doListNamespaceByLabel(Exchange exchange, String operation) {
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_LABELS, Map.class);
    if (ObjectHelper.isEmpty(labels)) {
        LOG.error("Get a specific namespace by labels require specify a labels set");
        throw new IllegalArgumentException("Get a specific namespace by labels require specify a labels set");
    }
    NonNamespaceOperation<Namespace, NamespaceList, DoneableNamespace, Resource<Namespace, DoneableNamespace>> namespaces = getEndpoint().getKubernetesClient().namespaces();
    for (Map.Entry<String, String> entry : labels.entrySet()) {
        namespaces.withLabel(entry.getKey(), entry.getValue());
    }
    NamespaceList namespace = namespaces.list();
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(namespace.getItems());
}
Also used : DoneableNamespace(io.fabric8.kubernetes.api.model.DoneableNamespace) Resource(io.fabric8.kubernetes.client.dsl.Resource) Map(java.util.Map) DoneableNamespace(io.fabric8.kubernetes.api.model.DoneableNamespace) Namespace(io.fabric8.kubernetes.api.model.Namespace) NamespaceList(io.fabric8.kubernetes.api.model.NamespaceList)

Example 3 with Resource

use of io.fabric8.support.api.Resource in project camel by apache.

the class KubernetesNodesProducer method doListNodesByLabels.

protected void doListNodesByLabels(Exchange exchange, String operation) throws Exception {
    NodeList nodeList = null;
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NODES_LABELS, Map.class);
    NonNamespaceOperation<Node, NodeList, DoneableNode, Resource<Node, DoneableNode>> nodes = getEndpoint().getKubernetesClient().nodes();
    for (Map.Entry<String, String> entry : labels.entrySet()) {
        nodes.withLabel(entry.getKey(), entry.getValue());
    }
    nodeList = nodes.list();
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(nodeList.getItems());
}
Also used : DoneableNode(io.fabric8.kubernetes.api.model.DoneableNode) NodeList(io.fabric8.kubernetes.api.model.NodeList) DoneableNode(io.fabric8.kubernetes.api.model.DoneableNode) Node(io.fabric8.kubernetes.api.model.Node) Resource(io.fabric8.kubernetes.client.dsl.Resource) Map(java.util.Map)

Example 4 with Resource

use of io.fabric8.support.api.Resource in project camel by apache.

the class KubernetesPersistentVolumesClaimsProducer method doListPersistentVolumesClaimsByLabels.

protected void doListPersistentVolumesClaimsByLabels(Exchange exchange, String operation) throws Exception {
    PersistentVolumeClaimList pvcList = null;
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_PERSISTENT_VOLUMES_CLAIMS_LABELS, Map.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    if (!ObjectHelper.isEmpty(namespaceName)) {
        NonNamespaceOperation<PersistentVolumeClaim, PersistentVolumeClaimList, DoneablePersistentVolumeClaim, Resource<PersistentVolumeClaim, DoneablePersistentVolumeClaim>> pvcs = getEndpoint().getKubernetesClient().persistentVolumeClaims().inNamespace(namespaceName);
        for (Map.Entry<String, String> entry : labels.entrySet()) {
            pvcs.withLabel(entry.getKey(), entry.getValue());
        }
        pvcList = pvcs.list();
    } else {
        MixedOperation<PersistentVolumeClaim, PersistentVolumeClaimList, DoneablePersistentVolumeClaim, Resource<PersistentVolumeClaim, DoneablePersistentVolumeClaim>> pvcs = getEndpoint().getKubernetesClient().persistentVolumeClaims();
        for (Map.Entry<String, String> entry : labels.entrySet()) {
            pvcs.withLabel(entry.getKey(), entry.getValue());
        }
        pvcList = pvcs.list();
    }
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(pvcList.getItems());
}
Also used : PersistentVolumeClaimList(io.fabric8.kubernetes.api.model.PersistentVolumeClaimList) Resource(io.fabric8.kubernetes.client.dsl.Resource) DoneablePersistentVolumeClaim(io.fabric8.kubernetes.api.model.DoneablePersistentVolumeClaim) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) DoneablePersistentVolumeClaim(io.fabric8.kubernetes.api.model.DoneablePersistentVolumeClaim) Map(java.util.Map)

Example 5 with Resource

use of io.fabric8.support.api.Resource in project camel by apache.

the class KubernetesPersistentVolumesProducer method doListPersistentVolumesByLabels.

protected void doListPersistentVolumesByLabels(Exchange exchange, String operation) throws Exception {
    PersistentVolumeList pvList = null;
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_PERSISTENT_VOLUMES_LABELS, Map.class);
    NonNamespaceOperation<PersistentVolume, PersistentVolumeList, DoneablePersistentVolume, Resource<PersistentVolume, DoneablePersistentVolume>> pvs;
    pvs = getEndpoint().getKubernetesClient().persistentVolumes();
    for (Map.Entry<String, String> entry : labels.entrySet()) {
        pvs.withLabel(entry.getKey(), entry.getValue());
    }
    pvList = pvs.list();
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(pvList.getItems());
}
Also used : Resource(io.fabric8.kubernetes.client.dsl.Resource) DoneablePersistentVolume(io.fabric8.kubernetes.api.model.DoneablePersistentVolume) PersistentVolume(io.fabric8.kubernetes.api.model.PersistentVolume) DoneablePersistentVolume(io.fabric8.kubernetes.api.model.DoneablePersistentVolume) Map(java.util.Map) PersistentVolumeList(io.fabric8.kubernetes.api.model.PersistentVolumeList)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)30 IOException (java.io.IOException)30 Test (org.junit.Test)29 Resource (io.fabric8.kubernetes.client.dsl.Resource)25 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)23 Map (java.util.Map)23 HashMap (java.util.HashMap)19 ArrayList (java.util.ArrayList)18 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)17 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)15 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)15 Session (io.fabric8.arquillian.kubernetes.Session)14 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)14 File (java.io.File)14 Resource (org.osgi.resource.Resource)14 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)12 Service (io.fabric8.kubernetes.api.model.Service)12 Async (io.vertx.ext.unit.Async)12 List (java.util.List)11 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)10