Search in sources :

Example 1 with MixedOperation

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

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

use of io.fabric8.kubernetes.client.dsl.MixedOperation in project camel by apache.

the class KubernetesPodsProducer method doListPodsByLabel.

protected void doListPodsByLabel(Exchange exchange, String operation) {
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_PODS_LABELS, Map.class);
    if (ObjectHelper.isEmpty(labels)) {
        LOG.error("Get pods by labels require specify a labels set");
        throw new IllegalArgumentException("Get pods by labels require specify a labels set");
    }
    MixedOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> pods = getEndpoint().getKubernetesClient().pods();
    for (Map.Entry<String, String> entry : labels.entrySet()) {
        pods.withLabel(entry.getKey(), entry.getValue());
    }
    PodList podList = pods.list();
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(podList.getItems());
}
Also used : PodList(io.fabric8.kubernetes.api.model.PodList) PodResource(io.fabric8.kubernetes.client.dsl.PodResource) DoneablePod(io.fabric8.kubernetes.api.model.DoneablePod) Pod(io.fabric8.kubernetes.api.model.Pod) DoneablePod(io.fabric8.kubernetes.api.model.DoneablePod) Map(java.util.Map)

Example 4 with MixedOperation

use of io.fabric8.kubernetes.client.dsl.MixedOperation in project camel by apache.

the class KubernetesSecretsProducer method doListSecretsByLabels.

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

Example 5 with MixedOperation

use of io.fabric8.kubernetes.client.dsl.MixedOperation in project strimzi by strimzi.

the class AbstractResourceOperatorTest method deleteWhenResourceExistsStillDeletes.

@Test
public void deleteWhenResourceExistsStillDeletes(TestContext context) {
    T resource = resource();
    Resource mockResource = mock(resourceType());
    when(mockResource.get()).thenReturn(resource);
    NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
    when(mockNameable.withName(matches(RESOURCE_NAME))).thenReturn(mockResource);
    MixedOperation mockCms = mock(MixedOperation.class);
    when(mockCms.inNamespace(matches(NAMESPACE))).thenReturn(mockNameable);
    C mockClient = mock(clientType());
    mocker(mockClient, mockCms);
    AbstractResourceOperator<C, T, L, D, R, P> op = createResourceOperations(vertx, mockClient);
    Async async = context.async();
    op.reconcile(resource.getMetadata().getNamespace(), resource.getMetadata().getName(), null).setHandler(ar -> {
        assertTrue(ar.succeeded());
        verify(mockResource).delete();
        async.complete();
    });
}
Also used : Async(io.vertx.ext.unit.Async) Resource(io.fabric8.kubernetes.client.dsl.Resource) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.junit.Test)

Aggregations

Resource (io.fabric8.kubernetes.client.dsl.Resource)21 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)15 Async (io.vertx.ext.unit.Async)15 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)13 Test (org.junit.Test)12 Map (java.util.Map)10 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)4 DeploymentList (io.fabric8.kubernetes.api.model.extensions.DeploymentList)4 DoneableDeployment (io.fabric8.kubernetes.api.model.extensions.DoneableDeployment)4 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)4 ScalableResource (io.fabric8.kubernetes.client.dsl.ScalableResource)4 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)3 ConfigMapList (io.fabric8.kubernetes.api.model.ConfigMapList)3 DoneableConfigMap (io.fabric8.kubernetes.api.model.DoneableConfigMap)3 DoneablePersistentVolumeClaim (io.fabric8.kubernetes.api.model.DoneablePersistentVolumeClaim)3 DoneablePod (io.fabric8.kubernetes.api.model.DoneablePod)3 DoneableService (io.fabric8.kubernetes.api.model.DoneableService)3 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)3 PersistentVolumeClaimList (io.fabric8.kubernetes.api.model.PersistentVolumeClaimList)3 Pod (io.fabric8.kubernetes.api.model.Pod)3