use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project camel by apache.
the class KubernetesBuildConfigsProducer method doListBuildConfigsByLabels.
protected void doListBuildConfigsByLabels(Exchange exchange, String operation) throws Exception {
BuildConfigList buildConfigsList = null;
Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_BUILD_CONFIGS_LABELS, Map.class);
String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
if (!ObjectHelper.isEmpty(namespaceName)) {
NonNamespaceOperation<BuildConfig, BuildConfigList, DoneableBuildConfig, BuildConfigResource<BuildConfig, DoneableBuildConfig, Void, Build>> buildConfigs;
buildConfigs = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).buildConfigs().inNamespace(namespaceName);
for (Map.Entry<String, String> entry : labels.entrySet()) {
buildConfigs.withLabel(entry.getKey(), entry.getValue());
}
buildConfigsList = buildConfigs.list();
} else {
MixedOperation<BuildConfig, BuildConfigList, DoneableBuildConfig, BuildConfigResource<BuildConfig, DoneableBuildConfig, Void, Build>> buildConfigs;
buildConfigs = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).buildConfigs();
for (Map.Entry<String, String> entry : labels.entrySet()) {
buildConfigs.withLabel(entry.getKey(), entry.getValue());
}
buildConfigsList = buildConfigs.list();
}
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
exchange.getOut().setBody(buildConfigsList.getItems());
}
use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project camel by apache.
the class KubernetesBuildsProducer method doListBuildByLabels.
protected void doListBuildByLabels(Exchange exchange, String operation) throws Exception {
BuildList buildList = null;
Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_BUILDS_LABELS, Map.class);
String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
if (!ObjectHelper.isEmpty(namespaceName)) {
NonNamespaceOperation<Build, BuildList, DoneableBuild, BuildResource<Build, DoneableBuild, String, LogWatch>> builds = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).builds().inNamespace(namespaceName);
for (Map.Entry<String, String> entry : labels.entrySet()) {
builds.withLabel(entry.getKey(), entry.getValue());
}
buildList = builds.list();
} else {
MixedOperation<Build, BuildList, DoneableBuild, BuildResource<Build, DoneableBuild, String, LogWatch>> builds = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).builds();
for (Map.Entry<String, String> entry : labels.entrySet()) {
builds.withLabel(entry.getKey(), entry.getValue());
}
buildList = builds.list();
}
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
exchange.getOut().setBody(buildList.getItems());
}
use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project camel by apache.
the class KubernetesReplicationControllersProducer method doListReplicationControllersByLabels.
protected void doListReplicationControllersByLabels(Exchange exchange, String operation) throws Exception {
ReplicationControllerList rcList = null;
Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLERS_LABELS, Map.class);
String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
if (!ObjectHelper.isEmpty(namespaceName)) {
NonNamespaceOperation<ReplicationController, ReplicationControllerList, DoneableReplicationController, RollableScallableResource<ReplicationController, DoneableReplicationController>> replicationControllers;
replicationControllers = getEndpoint().getKubernetesClient().replicationControllers().inNamespace(namespaceName);
for (Map.Entry<String, String> entry : labels.entrySet()) {
replicationControllers.withLabel(entry.getKey(), entry.getValue());
}
rcList = replicationControllers.list();
} else {
MixedOperation<ReplicationController, ReplicationControllerList, DoneableReplicationController, RollableScallableResource<ReplicationController, DoneableReplicationController>> replicationControllers;
replicationControllers = getEndpoint().getKubernetesClient().replicationControllers();
for (Map.Entry<String, String> entry : labels.entrySet()) {
replicationControllers.withLabel(entry.getKey(), entry.getValue());
}
rcList = replicationControllers.list();
}
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
exchange.getOut().setBody(rcList.getItems());
}
use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation 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.NonNamespaceOperation 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();
});
}
Aggregations