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