Search in sources :

Example 1 with NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation 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 NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation 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 NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation 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 NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation 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 NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation 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

NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)28 Resource (io.fabric8.kubernetes.client.dsl.Resource)22 Test (org.junit.Test)19 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)17 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)13 Async (io.vertx.ext.unit.Async)13 Map (java.util.Map)12 Service (io.fabric8.kubernetes.api.model.Service)8 API (org.wso2.carbon.apimgt.core.models.API)8 BeforeTest (org.testng.annotations.BeforeTest)7 Test (org.testng.annotations.Test)7 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)7 ScalableResource (io.fabric8.kubernetes.client.dsl.ScalableResource)6 BaseOperation (io.fabric8.kubernetes.client.dsl.base.BaseOperation)6 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)5 URL (java.net.URL)5 ContainerBasedGatewayException (org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException)5 Ingress (io.fabric8.kubernetes.api.model.extensions.Ingress)3 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)1