Search in sources :

Example 16 with MixedOperation

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

the class KubernetesResourcesQuotaProducer method doListResourceQuotasByLabels.

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

Example 17 with MixedOperation

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

the class OpenshiftAPIExample method main.

/**
 * @param args
 */
public static void main(String[] args) {
    DefaultOpenShiftClient client = createClient();
    client.pods();
    client.extensions().deployments();
    client.replicationControllers();
    client.secrets();
    MixedOperation<Deployment, DeploymentList, DoneableDeployment, ScalableResource<Deployment, DoneableDeployment>> deployment = client.extensions().deployments();
    System.out.println(deployment.list().getItems());
}
Also used : DoneableDeployment(io.fabric8.kubernetes.api.model.extensions.DoneableDeployment) ScalableResource(io.fabric8.kubernetes.client.dsl.ScalableResource) DeploymentList(io.fabric8.kubernetes.api.model.extensions.DeploymentList) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) DoneableDeployment(io.fabric8.kubernetes.api.model.extensions.DoneableDeployment) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient)

Example 18 with MixedOperation

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

the class KubernetesAPIExample method main.

/**
 * @param args
 */
public static void main(String[] args) {
    DefaultKubernetesClient client = createClient();
    client.pods();
    client.extensions().deployments();
    client.replicationControllers();
    client.secrets();
    MixedOperation<Deployment, DeploymentList, DoneableDeployment, ScalableResource<Deployment, DoneableDeployment>> deployment = client.extensions().deployments();
    System.out.println(deployment.list().getItems());
}
Also used : DoneableDeployment(io.fabric8.kubernetes.api.model.extensions.DoneableDeployment) ScalableResource(io.fabric8.kubernetes.client.dsl.ScalableResource) DeploymentList(io.fabric8.kubernetes.api.model.extensions.DeploymentList) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) DoneableDeployment(io.fabric8.kubernetes.api.model.extensions.DoneableDeployment) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 19 with MixedOperation

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

the class AbtractReadyResourceOperatorTest method waitUntilReadySuccessful.

public void waitUntilReadySuccessful(TestContext context, int unreadyCount) {
    T resource = resource();
    Resource mockResource = mock(resourceType());
    when(mockResource.get()).thenReturn(resource);
    AtomicInteger count = new AtomicInteger();
    when(mockResource.isReady()).then(invocation -> {
        int cnt = count.getAndIncrement();
        if (cnt < unreadyCount) {
            return Boolean.FALSE;
        } else if (cnt == unreadyCount) {
            return Boolean.TRUE;
        } else {
            context.fail("The resource has already been ready once!");
        }
        throw new RuntimeException();
    });
    NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
    when(mockNameable.withName(matches(resource.getMetadata().getName()))).thenReturn(mockResource);
    MixedOperation mockCms = mock(MixedOperation.class);
    when(mockCms.inNamespace(matches(resource.getMetadata().getNamespace()))).thenReturn(mockNameable);
    C mockClient = mock(clientType());
    mocker(mockClient, mockCms);
    AbstractReadyResourceOperator<C, T, L, D, R, P> op = createResourceOperations(vertx, mockClient);
    Async async = context.async();
    op.readiness(NAMESPACE, RESOURCE_NAME, 20, 5_000).setHandler(ar -> {
        assertTrue(ar.succeeded());
        verify(mockResource, times(Readiness.isReadinessApplicable(resource) ? unreadyCount + 1 : 1)).get();
        if (Readiness.isReadinessApplicable(resource)) {
            verify(mockResource, times(unreadyCount + 1)).isReady();
        }
        async.complete();
    });
}
Also used : Resource(io.fabric8.kubernetes.client.dsl.Resource) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Async(io.vertx.ext.unit.Async) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation)

Example 20 with MixedOperation

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

the class AbtractReadyResourceOperatorTest method waitUntilReadyExistenceCheckThrows.

@Test
public void waitUntilReadyExistenceCheckThrows(TestContext context) {
    T resource = resource();
    RuntimeException ex = new RuntimeException();
    Resource mockResource = mock(resourceType());
    when(mockResource.get()).thenThrow(ex);
    NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
    when(mockNameable.withName(matches(resource.getMetadata().getName()))).thenReturn(mockResource);
    MixedOperation mockCms = mock(MixedOperation.class);
    when(mockCms.inNamespace(matches(resource.getMetadata().getNamespace()))).thenReturn(mockNameable);
    C mockClient = mock(clientType());
    mocker(mockClient, mockCms);
    AbstractReadyResourceOperator<C, T, L, D, R, P> op = createResourceOperations(vertx, mockClient);
    Async async = context.async();
    op.readiness(NAMESPACE, RESOURCE_NAME, 20, 100).setHandler(ar -> {
        assertTrue(ar.failed());
        assertThat(ar.cause(), instanceOf(TimeoutException.class));
        verify(mockResource, never()).isReady();
        async.complete();
    });
}
Also used : Resource(io.fabric8.kubernetes.client.dsl.Resource) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Async(io.vertx.ext.unit.Async) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) 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