Search in sources :

Example 1 with DoneableServiceAccount

use of io.fabric8.kubernetes.api.model.DoneableServiceAccount 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)

Aggregations

DoneableServiceAccount (io.fabric8.kubernetes.api.model.DoneableServiceAccount)1 ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)1 ServiceAccountList (io.fabric8.kubernetes.api.model.ServiceAccountList)1 Resource (io.fabric8.kubernetes.client.dsl.Resource)1 Map (java.util.Map)1