This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new fee4af5 Fix listCustomResourcesByLabels (#5434)
fee4af5 is described below
commit fee4af512b1214a2ee9bb3a9ddfcd71187b3394b
Author: Akihiko (Aki) Kuroda <[email protected]>
AuthorDate: Tue Apr 20 00:45:37 2021 -0400
Fix listCustomResourcesByLabels (#5434)
---
.../KubernetesCustomResourcesProducer.java | 3 +-
.../KubernetesCustomResourcesProducerTest.java | 34 ++++++++++++++++++++++
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git
a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/customresources/KubernetesCustomResourcesProducer.java
b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/customresources/KubernetesCustomResourcesProducer.java
index a3fc5ec..0d84399 100644
---
a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/customresources/KubernetesCustomResourcesProducer.java
+++
b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/customresources/KubernetesCustomResourcesProducer.java
@@ -114,7 +114,8 @@ public class KubernetesCustomResourcesProducer extends
DefaultProducer {
protected void doListByLabels(Exchange exchange, String operation, String
namespaceName) throws Exception {
Map<String, String> labels =
exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_CRD_LABELS,
Map.class);
JsonObject customResourcesListJSON = new JsonObject(
-
getEndpoint().getKubernetesClient().customResource(getCRDContext(exchange.getIn())).list(namespaceName));
+
getEndpoint().getKubernetesClient().customResource(getCRDContext(exchange.getIn())).list(namespaceName,
+ labels));
if (LOG.isDebugEnabled()) {
LOG.debug(customResourcesListJSON.toString());
}
diff --git
a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesCustomResourcesProducerTest.java
b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesCustomResourcesProducerTest.java
index 813eff4..9a54816 100644
---
a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesCustomResourcesProducerTest.java
+++
b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesCustomResourcesProducerTest.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.kubernetes.producer;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -105,6 +106,37 @@ public class KubernetesCustomResourcesProducerTest extends
KubernetesTestSupport
}
@Test
+ public void listByLabelsTest() throws Exception {
+ JsonObject instance = new
JsonObject(getClient().customResource(getCustomResourceContext()).load(gitHubSourceString));
+ JsonObject gitHubSourceList = new JsonObject();
+ JsonArray list = new JsonArray();
+ list.add(instance);
+ gitHubSourceList.put("items", list);
+
+
server.expect().get().withPath("/apis/sources.knative.dev/v1alpha1/namespaces/test/githubsources?labelSelector="
+ +
toUrlEncoded("key1=value1,key2=value2"))
+ .andReturn(200, gitHubSourceList.toJson()).once();
+
+ Exchange ex = template.request("direct:listCustomResourcesByLabels",
exchange -> {
+
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
"test");
+
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_CRD_NAME,
"githubsources.sources.knative.dev");
+
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_CRD_GROUP,
"sources.knative.dev");
+
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_CRD_SCOPE,
"Namespaced");
+
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_CRD_VERSION,
"v1alpha1");
+
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_CRD_PLURAL,
"githubsources");
+ Map<String, String> labels = new HashMap<>();
+ labels.put("key1", "value1");
+ labels.put("key2", "value2");
+
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_CRD_LABELS, labels);
+
+ });
+
+ List<Map<String, Object>> result = ex.getMessage().getBody(List.class);
+
+ assertTrue(1 == result.size());
+ }
+
+ @Test
public void createAndDeleteTest() throws Exception {
JsonObject instance = new
JsonObject(getClient().customResource(getCustomResourceContext()).load(gitHubSourceString));
JsonObject gitHubSourceList = new JsonObject();
@@ -175,6 +207,8 @@ public class KubernetesCustomResourcesProducerTest extends
KubernetesTestSupport
.toF("kubernetes-custom-resources:///?kubernetesClient=#kubernetesClient&operation=getCustomResource");
from("direct:listCustomResources").toF(
"kubernetes-custom-resources:///?kubernetesClient=#kubernetesClient&operation=listCustomResources");
+ from("direct:listCustomResourcesByLabels").toF(
+
"kubernetes-custom-resources:///?kubernetesClient=#kubernetesClient&operation=listCustomResourcesByLabels");
from("direct:deleteCustomResource").toF(
"kubernetes-custom-resources:///?kubernetesClient=#kubernetesClient&operation=deleteCustomResource");
from("direct:createCustomResource").toF(