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());
}
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());
}
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());
}
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();
});
}
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();
});
}
Aggregations