This is an automated email from the ASF dual-hosted git repository. lburgazzoli 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 4b0fbda CAMEL-12569: service call : create a dns+srv resolver for kubernetes 4b0fbda is described below commit 4b0fbdabbca3f38fd03929f20b41725ba3ca82b8 Author: lburgazzoli <lburgazz...@gmail.com> AuthorDate: Mon Jun 11 14:48:55 2018 +0200 CAMEL-12569: service call : create a dns+srv resolver for kubernetes --- .gitignore | 1 + ...esServiceCallServiceDiscoveryConfiguration.java | 61 +++++++-- .../src/main/docs/kubernetes-component.adoc | 3 +- .../docs/kubernetes-config-maps-component.adoc | 3 +- .../docs/kubernetes-deployments-component.adoc | 3 +- .../main/docs/kubernetes-namespaces-component.adoc | 3 +- .../src/main/docs/kubernetes-nodes-component.adoc | 3 +- ...rnetes-persistent-volumes-claims-component.adoc | 3 +- .../kubernetes-persistent-volumes-component.adoc | 3 +- .../src/main/docs/kubernetes-pods-component.adoc | 3 +- ...bernetes-replication-controllers-component.adoc | 3 +- .../docs/kubernetes-resources-quota-component.adoc | 3 +- .../main/docs/kubernetes-secrets-component.adoc | 3 +- .../kubernetes-service-accounts-component.adoc | 3 +- .../main/docs/kubernetes-services-component.adoc | 3 +- .../docs/openshift-build-configs-component.adoc | 3 +- .../src/main/docs/openshift-builds-component.adoc | 3 +- .../kubernetes/KubernetesConfiguration.java | 14 ++ .../cloud/KubernetesClientServiceDiscovery.java | 23 +++- .../cloud/KubernetesDnsServiceDiscovery.java | 21 ++- .../cloud/KubernetesDnsSrvServiceDiscovery.java | 146 +++++++++++++++++++++ .../cloud/KubernetesEnvServiceDiscovery.java | 5 + .../cloud/KubernetesServiceDiscovery.java | 37 +----- .../cloud/KubernetesServiceDiscoveryFactory.java | 18 +++ ...iceCallServiceDiscoveryConfigurationCommon.java | 29 +++- ...netesServiceDiscoveryAutoConfigurationTest.java | 80 ++++++++++- 26 files changed, 407 insertions(+), 73 deletions(-) diff --git a/.gitignore b/.gitignore index 79c9cc9..67a1214 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ components/camel-solr/data .factorypath .pmd .sts4-cache +log-camel-lsp.out diff --git a/camel-core/src/main/java/org/apache/camel/model/cloud/KubernetesServiceCallServiceDiscoveryConfiguration.java b/camel-core/src/main/java/org/apache/camel/model/cloud/KubernetesServiceCallServiceDiscoveryConfiguration.java index 0aa9cbe..b26df06 100644 --- a/camel-core/src/main/java/org/apache/camel/model/cloud/KubernetesServiceCallServiceDiscoveryConfiguration.java +++ b/camel-core/src/main/java/org/apache/camel/model/cloud/KubernetesServiceCallServiceDiscoveryConfiguration.java @@ -29,8 +29,12 @@ import org.apache.camel.spi.Metadata; public class KubernetesServiceCallServiceDiscoveryConfiguration extends ServiceCallServiceDiscoveryConfiguration { @XmlAttribute @Metadata(defaultValue = "environment", enums = "environment,dns,client") private String lookup = "environment"; - @XmlAttribute + @XmlAttribute @Metadata(label = "dns,dnssrv") private String dnsDomain; + @XmlAttribute @Metadata(label = "dns,dnssrv") + private String portName; + @XmlAttribute @Metadata(label = "dns,dnssrv") + private String portProtocol = "tcp"; @XmlAttribute private String namespace; @XmlAttribute @@ -117,7 +121,9 @@ public class KubernetesServiceCallServiceDiscoveryConfiguration extends ServiceC * When using client, then the client queries the kubernetes master to obtain a list * of active pods that provides the service, and then random (or round robin) select a pod. * <p/> - * When using dns the service name is resolved as <tt>name.namespace.service.dnsDomain</tt>. + * When using dns the service name is resolved as <tt>name.namespace.svc.dnsDomain</tt>. + * <p/> + * When using dnssrv the service name is resolved with SRV query for <tt>_<port_name>._<port_proto>.<serviceName>.<namespace>.svc.<zone>.</tt>. * <p/> * When using environment then environment variables are used to lookup the service. * <p/> @@ -138,6 +144,28 @@ public class KubernetesServiceCallServiceDiscoveryConfiguration extends ServiceC this.dnsDomain = dnsDomain; } + public String getPortName() { + return portName; + } + + /** + * Sets the Port Name to use for DNS/DNSSRV lookup. + */ + public void setPortName(String portName) { + this.portName = portName; + } + + public String getPortProtocol() { + return portProtocol; + } + + /** + * Sets the Port Protocol to use for DNS/DNSSRV lookup. + */ + public void setPortProtocol(String portProtocol) { + this.portProtocol = portProtocol; + } + public String getUsername() { return username; } @@ -299,16 +327,7 @@ public class KubernetesServiceCallServiceDiscoveryConfiguration extends ServiceC } /** - * How to perform service lookup. Possible values: client, dns, environment. - * <p/> - * When using client, then the client queries the kubernetes master to obtain a list - * of active pods that provides the service, and then random (or round robin) select a pod. - * <p/> - * When using dns the service name is resolved as <tt>name.namespace.service.dnsDomain</tt>. - * <p/> - * When using environment then environment variables are used to lookup the service. - * <p/> - * By default environment is used. + * How to perform service lookup, @see {@link #setLookup(String)}. */ public KubernetesServiceCallServiceDiscoveryConfiguration lookup(String lookup) { setLookup(lookup); @@ -316,7 +335,7 @@ public class KubernetesServiceCallServiceDiscoveryConfiguration extends ServiceC } /** - * Sets the DNS domain to use for DNS lookup. + * Sets the DNS domain to use for DNS/SNDSRV lookup. */ public KubernetesServiceCallServiceDiscoveryConfiguration dnsDomain(String dnsDomain) { setDnsDomain(dnsDomain); @@ -324,6 +343,22 @@ public class KubernetesServiceCallServiceDiscoveryConfiguration extends ServiceC } /** + * Sets Port Name to use for DNS/SNDSRV lookup. + */ + public KubernetesServiceCallServiceDiscoveryConfiguration portName(String portName) { + setPortName(portName); + return this; + } + + /** + * Sets Port Protocol to use for DNS/SNDSRV lookup. + */ + public KubernetesServiceCallServiceDiscoveryConfiguration portProtocol(String portProtocol) { + setPortProtocol(portProtocol); + return this; + } + + /** * Sets the username for authentication when using client lookup */ public KubernetesServiceCallServiceDiscoveryConfiguration username(String username) { diff --git a/components/camel-kubernetes/src/main/docs/kubernetes-component.adoc b/components/camel-kubernetes/src/main/docs/kubernetes-component.adoc index 72c8c09..9779906 100644 --- a/components/camel-kubernetes/src/main/docs/kubernetes-component.adoc +++ b/components/camel-kubernetes/src/main/docs/kubernetes-component.adoc @@ -83,7 +83,7 @@ with the following path and query parameters: |=== -==== Query Parameters (28 parameters): +==== Query Parameters (29 parameters): [width="100%",cols="2,5,^1,2",options="header"] @@ -94,6 +94,7 @@ with the following path and query parameters: | *dnsDomain* (common) | The dns domain, used for ServiceCall EIP | | String | *kubernetesClient* (common) | Default KubernetesClient to use if provided | | KubernetesClient | *portName* (common) | The port name, used for ServiceCall EIP | | String +| *portProtocol* (common) | The port protocol, used for ServiceCall EIP | tcp | String | *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | *labelKey* (consumer) | The Consumer Label key when watching at some resources | | String | *labelValue* (consumer) | The Consumer Label value when watching at some resources | | String diff --git a/components/camel-kubernetes/src/main/docs/kubernetes-config-maps-component.adoc b/components/camel-kubernetes/src/main/docs/kubernetes-config-maps-component.adoc index eaabd89..089f246 100644 --- a/components/camel-kubernetes/src/main/docs/kubernetes-config-maps-component.adoc +++ b/components/camel-kubernetes/src/main/docs/kubernetes-config-maps-component.adoc @@ -35,7 +35,7 @@ with the following path and query parameters: |=== -==== Query Parameters (19 parameters): +==== Query Parameters (20 parameters): [width="100%",cols="2,5,^1,2",options="header"] @@ -46,6 +46,7 @@ with the following path and query parameters: | *kubernetesClient* (producer) | Default KubernetesClient to use if provided | | KubernetesClient | *operation* (producer) | Producer operation to do on Kubernetes | | String | *portName* (producer) | The port name, used for ServiceCall EIP | | String +| *portProtocol* (producer) | The port protocol, used for ServiceCall EIP | tcp | String | *connectionTimeout* (advanced) | Connection timeout in milliseconds to use when making requests to the Kubernetes API server. | | Integer | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean | *caCertData* (security) | The CA Cert Data | | String diff --git a/components/camel-kubernetes/src/main/docs/kubernetes-deployments-component.adoc b/components/camel-kubernetes/src/main/docs/kubernetes-deployments-component.adoc index d6c7fba..e3182f1 100644 --- a/components/camel-kubernetes/src/main/docs/kubernetes-deployments-component.adoc +++ b/components/camel-kubernetes/src/main/docs/kubernetes-deployments-component.adoc @@ -36,7 +36,7 @@ with the following path and query parameters: |=== -==== Query Parameters (27 parameters): +==== Query Parameters (28 parameters): [width="100%",cols="2,5,^1,2",options="header"] @@ -46,6 +46,7 @@ with the following path and query parameters: | *dnsDomain* (common) | The dns domain, used for ServiceCall EIP | | String | *kubernetesClient* (common) | Default KubernetesClient to use if provided | | KubernetesClient | *portName* (common) | The port name, used for ServiceCall EIP | | String +| *portProtocol* (common) | The port protocol, used for ServiceCall EIP | tcp | String | *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | *labelKey* (consumer) | The Consumer Label key when watching at some resources | | String | *labelValue* (consumer) | The Consumer Label value when watching at some resources | | String diff --git a/components/camel-kubernetes/src/main/docs/kubernetes-namespaces-component.adoc b/components/camel-kubernetes/src/main/docs/kubernetes-namespaces-component.adoc index 9b7c3cb..1f7f5d4 100644 --- a/components/camel-kubernetes/src/main/docs/kubernetes-namespaces-component.adoc +++ b/components/camel-kubernetes/src/main/docs/kubernetes-namespaces-component.adoc @@ -37,7 +37,7 @@ with the following path and query parameters: |=== -==== Query Parameters (27 parameters): +==== Query Parameters (28 parameters): [width="100%",cols="2,5,^1,2",options="header"] @@ -47,6 +47,7 @@ with the following path and query parameters: | *dnsDomain* (common) | The dns domain, used for ServiceCall EIP | | String | *kubernetesClient* (common) | Default KubernetesClient to use if provided | | KubernetesClient | *portName* (common) | The port name, used for ServiceCall EIP | | String +| *portProtocol* (common) | The port protocol, used for ServiceCall EIP | tcp | String | *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | *labelKey* (consumer) | The Consumer Label key when watching at some resources | | String | *labelValue* (consumer) | The Consumer Label value when watching at some resources | | String diff --git a/components/camel-kubernetes/src/main/docs/kubernetes-nodes-component.adoc b/components/camel-kubernetes/src/main/docs/kubernetes-nodes-component.adoc index af38a5a..68da836 100644 --- a/components/camel-kubernetes/src/main/docs/kubernetes-nodes-component.adoc +++ b/components/camel-kubernetes/src/main/docs/kubernetes-nodes-component.adoc @@ -37,7 +37,7 @@ with the following path and query parameters: |=== -==== Query Parameters (27 parameters): +==== Query Parameters (28 parameters): [width="100%",cols="2,5,^1,2",options="header"] @@ -47,6 +47,7 @@ with the following path and query parameters: | *dnsDomain* (common) | The dns domain, used for ServiceCall EIP | | String | *kubernetesClient* (common) | Default KubernetesClient to use if provided | | KubernetesClient | *portName* (common) | The port name, used for ServiceCall EIP | | String +| *portProtocol* (common) | The port protocol, used for ServiceCall EIP | tcp | String | *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | *labelKey* (consumer) | The Consumer Label key when watching at some resources | | String | *labelValue* (consumer) | The Consumer Label value when watching at some resources | | String diff --git a/components/camel-kubernetes/src/main/docs/kubernetes-persistent-volumes-claims-component.adoc b/components/camel-kubernetes/src/main/docs/kubernetes-persistent-volumes-claims-component.adoc index 305b43f..8ffcfd1 100644 --- a/components/camel-kubernetes/src/main/docs/kubernetes-persistent-volumes-claims-component.adoc +++ b/components/camel-kubernetes/src/main/docs/kubernetes-persistent-volumes-claims-component.adoc @@ -36,7 +36,7 @@ with the following path and query parameters: |=== -==== Query Parameters (19 parameters): +==== Query Parameters (20 parameters): [width="100%",cols="2,5,^1,2",options="header"] @@ -47,6 +47,7 @@ with the following path and query parameters: | *kubernetesClient* (producer) | Default KubernetesClient to use if provided | | KubernetesClient | *operation* (producer) | Producer operation to do on Kubernetes | | String | *portName* (producer) | The port name, used for ServiceCall EIP | | String +| *portProtocol* (producer) | The port protocol, used for ServiceCall EIP | tcp | String | *connectionTimeout* (advanced) | Connection timeout in milliseconds to use when making requests to the Kubernetes API server. | | Integer | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean | *caCertData* (security) | The CA Cert Data | | String diff --git a/components/camel-kubernetes/src/main/docs/kubernetes-persistent-volumes-component.adoc b/components/camel-kubernetes/src/main/docs/kubernetes-persistent-volumes-component.adoc index db74974..ec5e394 100644 --- a/components/camel-kubernetes/src/main/docs/kubernetes-persistent-volumes-component.adoc +++ b/components/camel-kubernetes/src/main/docs/kubernetes-persistent-volumes-component.adoc @@ -36,7 +36,7 @@ with the following path and query parameters: |=== -==== Query Parameters (19 parameters): +==== Query Parameters (20 parameters): [width="100%",cols="2,5,^1,2",options="header"] @@ -47,6 +47,7 @@ with the following path and query parameters: | *kubernetesClient* (producer) | Default KubernetesClient to use if provided | | KubernetesClient | *operation* (producer) | Producer operation to do on Kubernetes | | String | *portName* (producer) | The port name, used for ServiceCall EIP | | String +| *portProtocol* (producer) | The port protocol, used for ServiceCall EIP | tcp | String | *connectionTimeout* (advanced) | Connection timeout in milliseconds to use when making requests to the Kubernetes API server. | | Integer | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean | *caCertData* (security) | The CA Cert Data | | String diff --git a/components/camel-kubernetes/src/main/docs/kubernetes-pods-component.adoc b/components/camel-kubernetes/src/main/docs/kubernetes-pods-component.adoc index 7ebe882..6d10dcc 100644 --- a/components/camel-kubernetes/src/main/docs/kubernetes-pods-component.adoc +++ b/components/camel-kubernetes/src/main/docs/kubernetes-pods-component.adoc @@ -36,7 +36,7 @@ with the following path and query parameters: |=== -==== Query Parameters (27 parameters): +==== Query Parameters (28 parameters): [width="100%",cols="2,5,^1,2",options="header"] @@ -46,6 +46,7 @@ with the following path and query parameters: | *dnsDomain* (common) | The dns domain, used for ServiceCall EIP | | String | *kubernetesClient* (common) | Default KubernetesClient to use if provided | | KubernetesClient | *portName* (common) | The port name, used for ServiceCall EIP | | String +| *portProtocol* (common) | The port protocol, used for ServiceCall EIP | tcp | String | *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | *labelKey* (consumer) | The Consumer Label key when watching at some resources | | String | *labelValue* (consumer) | The Consumer Label value when watching at some resources | | String diff --git a/components/camel-kubernetes/src/main/docs/kubernetes-replication-controllers-component.adoc b/components/camel-kubernetes/src/main/docs/kubernetes-replication-controllers-component.adoc index caad62c..4301617 100644 --- a/components/camel-kubernetes/src/main/docs/kubernetes-replication-controllers-component.adoc +++ b/components/camel-kubernetes/src/main/docs/kubernetes-replication-controllers-component.adoc @@ -37,7 +37,7 @@ with the following path and query parameters: |=== -==== Query Parameters (27 parameters): +==== Query Parameters (28 parameters): [width="100%",cols="2,5,^1,2",options="header"] @@ -47,6 +47,7 @@ with the following path and query parameters: | *dnsDomain* (common) | The dns domain, used for ServiceCall EIP | | String | *kubernetesClient* (common) | Default KubernetesClient to use if provided | | KubernetesClient | *portName* (common) | The port name, used for ServiceCall EIP | | String +| *portProtocol* (common) | The port protocol, used for ServiceCall EIP | tcp | String | *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | *labelKey* (consumer) | The Consumer Label key when watching at some resources | | String | *labelValue* (consumer) | The Consumer Label value when watching at some resources | | String diff --git a/components/camel-kubernetes/src/main/docs/kubernetes-resources-quota-component.adoc b/components/camel-kubernetes/src/main/docs/kubernetes-resources-quota-component.adoc index 41e0112..f7c56c3 100644 --- a/components/camel-kubernetes/src/main/docs/kubernetes-resources-quota-component.adoc +++ b/components/camel-kubernetes/src/main/docs/kubernetes-resources-quota-component.adoc @@ -36,7 +36,7 @@ with the following path and query parameters: |=== -==== Query Parameters (19 parameters): +==== Query Parameters (20 parameters): [width="100%",cols="2,5,^1,2",options="header"] @@ -47,6 +47,7 @@ with the following path and query parameters: | *kubernetesClient* (producer) | Default KubernetesClient to use if provided | | KubernetesClient | *operation* (producer) | Producer operation to do on Kubernetes | | String | *portName* (producer) | The port name, used for ServiceCall EIP | | String +| *portProtocol* (producer) | The port protocol, used for ServiceCall EIP | tcp | String | *connectionTimeout* (advanced) | Connection timeout in milliseconds to use when making requests to the Kubernetes API server. | | Integer | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean | *caCertData* (security) | The CA Cert Data | | String diff --git a/components/camel-kubernetes/src/main/docs/kubernetes-secrets-component.adoc b/components/camel-kubernetes/src/main/docs/kubernetes-secrets-component.adoc index 6080b2b..67a7f63 100644 --- a/components/camel-kubernetes/src/main/docs/kubernetes-secrets-component.adoc +++ b/components/camel-kubernetes/src/main/docs/kubernetes-secrets-component.adoc @@ -36,7 +36,7 @@ with the following path and query parameters: |=== -==== Query Parameters (19 parameters): +==== Query Parameters (20 parameters): [width="100%",cols="2,5,^1,2",options="header"] @@ -47,6 +47,7 @@ with the following path and query parameters: | *kubernetesClient* (producer) | Default KubernetesClient to use if provided | | KubernetesClient | *operation* (producer) | Producer operation to do on Kubernetes | | String | *portName* (producer) | The port name, used for ServiceCall EIP | | String +| *portProtocol* (producer) | The port protocol, used for ServiceCall EIP | tcp | String | *connectionTimeout* (advanced) | Connection timeout in milliseconds to use when making requests to the Kubernetes API server. | | Integer | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean | *caCertData* (security) | The CA Cert Data | | String diff --git a/components/camel-kubernetes/src/main/docs/kubernetes-service-accounts-component.adoc b/components/camel-kubernetes/src/main/docs/kubernetes-service-accounts-component.adoc index 41570ae..c1174cd 100644 --- a/components/camel-kubernetes/src/main/docs/kubernetes-service-accounts-component.adoc +++ b/components/camel-kubernetes/src/main/docs/kubernetes-service-accounts-component.adoc @@ -34,7 +34,7 @@ with the following path and query parameters: |=== -==== Query Parameters (19 parameters): +==== Query Parameters (20 parameters): [width="100%",cols="2,5,^1,2",options="header"] @@ -45,6 +45,7 @@ with the following path and query parameters: | *kubernetesClient* (producer) | Default KubernetesClient to use if provided | | KubernetesClient | *operation* (producer) | Producer operation to do on Kubernetes | | String | *portName* (producer) | The port name, used for ServiceCall EIP | | String +| *portProtocol* (producer) | The port protocol, used for ServiceCall EIP | tcp | String | *connectionTimeout* (advanced) | Connection timeout in milliseconds to use when making requests to the Kubernetes API server. | | Integer | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean | *caCertData* (security) | The CA Cert Data | | String diff --git a/components/camel-kubernetes/src/main/docs/kubernetes-services-component.adoc b/components/camel-kubernetes/src/main/docs/kubernetes-services-component.adoc index e150b38..a21ee96 100644 --- a/components/camel-kubernetes/src/main/docs/kubernetes-services-component.adoc +++ b/components/camel-kubernetes/src/main/docs/kubernetes-services-component.adoc @@ -37,7 +37,7 @@ with the following path and query parameters: |=== -==== Query Parameters (27 parameters): +==== Query Parameters (28 parameters): [width="100%",cols="2,5,^1,2",options="header"] @@ -47,6 +47,7 @@ with the following path and query parameters: | *dnsDomain* (common) | The dns domain, used for ServiceCall EIP | | String | *kubernetesClient* (common) | Default KubernetesClient to use if provided | | KubernetesClient | *portName* (common) | The port name, used for ServiceCall EIP | | String +| *portProtocol* (common) | The port protocol, used for ServiceCall EIP | tcp | String | *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | *labelKey* (consumer) | The Consumer Label key when watching at some resources | | String | *labelValue* (consumer) | The Consumer Label value when watching at some resources | | String diff --git a/components/camel-kubernetes/src/main/docs/openshift-build-configs-component.adoc b/components/camel-kubernetes/src/main/docs/openshift-build-configs-component.adoc index 2966290..0cc6e0a 100644 --- a/components/camel-kubernetes/src/main/docs/openshift-build-configs-component.adoc +++ b/components/camel-kubernetes/src/main/docs/openshift-build-configs-component.adoc @@ -35,7 +35,7 @@ with the following path and query parameters: |=== -==== Query Parameters (19 parameters): +==== Query Parameters (20 parameters): [width="100%",cols="2,5,^1,2",options="header"] @@ -46,6 +46,7 @@ with the following path and query parameters: | *kubernetesClient* (producer) | Default KubernetesClient to use if provided | | KubernetesClient | *operation* (producer) | Producer operation to do on Kubernetes | | String | *portName* (producer) | The port name, used for ServiceCall EIP | | String +| *portProtocol* (producer) | The port protocol, used for ServiceCall EIP | tcp | String | *connectionTimeout* (advanced) | Connection timeout in milliseconds to use when making requests to the Kubernetes API server. | | Integer | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean | *caCertData* (security) | The CA Cert Data | | String diff --git a/components/camel-kubernetes/src/main/docs/openshift-builds-component.adoc b/components/camel-kubernetes/src/main/docs/openshift-builds-component.adoc index 6637fe8..fa5b376 100644 --- a/components/camel-kubernetes/src/main/docs/openshift-builds-component.adoc +++ b/components/camel-kubernetes/src/main/docs/openshift-builds-component.adoc @@ -35,7 +35,7 @@ with the following path and query parameters: |=== -==== Query Parameters (19 parameters): +==== Query Parameters (20 parameters): [width="100%",cols="2,5,^1,2",options="header"] @@ -46,6 +46,7 @@ with the following path and query parameters: | *kubernetesClient* (producer) | Default KubernetesClient to use if provided | | KubernetesClient | *operation* (producer) | Producer operation to do on Kubernetes | | String | *portName* (producer) | The port name, used for ServiceCall EIP | | String +| *portProtocol* (producer) | The port protocol, used for ServiceCall EIP | tcp | String | *connectionTimeout* (advanced) | Connection timeout in milliseconds to use when making requests to the Kubernetes API server. | | Integer | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean | *caCertData* (security) | The CA Cert Data | | String diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesConfiguration.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesConfiguration.java index ebbe64a..53bc6db 100644 --- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesConfiguration.java +++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesConfiguration.java @@ -94,6 +94,9 @@ public class KubernetesConfiguration implements Cloneable { @UriParam private String portName; + @UriParam(defaultValue = "tcp") + private String portProtocol = "tcp"; + @UriParam private String dnsDomain; @@ -312,6 +315,17 @@ public class KubernetesConfiguration implements Cloneable { this.portName = portName; } + public String getPortProtocol() { + return portProtocol; + } + + /** + * The port protocol, used for ServiceCall EIP + */ + public void setPortProtocol(String portProtocol) { + this.portProtocol = portProtocol; + } + public String getDnsDomain() { return dnsDomain; } diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesClientServiceDiscovery.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesClientServiceDiscovery.java index d243218..bfb0184 100644 --- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesClientServiceDiscovery.java +++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesClientServiceDiscovery.java @@ -36,28 +36,31 @@ import org.slf4j.LoggerFactory; public class KubernetesClientServiceDiscovery extends KubernetesServiceDiscovery { private static final Logger LOG = LoggerFactory.getLogger(KubernetesClientServiceDiscovery.class); - private static final int FIRST = 0; + private final String namespace; + private final String portName; private AutoAdaptableKubernetesClient client; public KubernetesClientServiceDiscovery(KubernetesConfiguration configuration) { super(configuration); + this.namespace = configuration.getNamespace() != null ? configuration.getNamespace() : System.getenv("KUBERNETES_NAMESPACE"); + this.portName = configuration.getPortName(); this.client = null; } @Override public List<ServiceDefinition> getServices(String name) { - LOG.debug("Discovering endpoints from namespace: {} with name: {}", getNamespace(), name); - Endpoints endpoints = client.endpoints().inNamespace(getNamespace()).withName(name).get(); + LOG.debug("Discovering endpoints from namespace: {} with name: {}", this.namespace, name); + Endpoints endpoints = client.endpoints().inNamespace(this.namespace).withName(name).get(); List<ServiceDefinition> result = new ArrayList<>(); if (endpoints != null) { if (LOG.isDebugEnabled()) { LOG.debug("Found {} endpoints in namespace: {} for name: {} and portName: {}", - endpoints.getSubsets().size(), getNamespace(), name, getPortName()); + endpoints.getSubsets().size(), this.namespace, name, this.portName); } for (EndpointSubset subset : endpoints.getSubsets()) { if (subset.getPorts().size() == 1) { - addServers(name, result, subset.getPorts().get(FIRST), subset); + addServers(name, result, subset.getPorts().get(0), subset); } else { final List<EndpointPort> ports = subset.getPorts(); final int portSize = ports.size(); @@ -65,7 +68,7 @@ public class KubernetesClientServiceDiscovery extends KubernetesServiceDiscovery EndpointPort port; for (int p = 0; p < portSize; p++) { port = ports.get(p); - if (ObjectHelper.isEmpty(getPortName()) || getPortName().endsWith(port.getName())) { + if (ObjectHelper.isEmpty(this.portName) || this.portName.endsWith(port.getName())) { addServers(name, result, port, subset); } } @@ -145,4 +148,12 @@ public class KubernetesClientServiceDiscovery extends KubernetesServiceDiscovery client = null; } } + + @Override + public String toString() { + return "KubernetesClientServiceDiscovery{" + + "namespace='" + namespace + '\'' + + ", portName='" + portName + '\'' + + '}'; + } } diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesDnsServiceDiscovery.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesDnsServiceDiscovery.java index 53b433a..c71b207 100644 --- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesDnsServiceDiscovery.java +++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesDnsServiceDiscovery.java @@ -25,12 +25,23 @@ import java.util.concurrent.ConcurrentMap; import org.apache.camel.cloud.ServiceDefinition; import org.apache.camel.component.kubernetes.KubernetesConfiguration; import org.apache.camel.impl.cloud.DefaultServiceDefinition; +import org.apache.camel.util.ObjectHelper; public class KubernetesDnsServiceDiscovery extends KubernetesServiceDiscovery { - private ConcurrentMap<String, List<ServiceDefinition>> cache; + private final ConcurrentMap<String, List<ServiceDefinition>> cache; + private final String namespace; + private final String zone; public KubernetesDnsServiceDiscovery(KubernetesConfiguration configuration) { super(configuration); + + this.namespace = configuration.getNamespace() != null ? configuration.getNamespace() : System.getenv("KUBERNETES_NAMESPACE"); + this.zone = configuration.getDnsDomain(); + + // validation + ObjectHelper.notNull(namespace, "Namespace"); + ObjectHelper.notNull(zone, "DNS Domain"); + this.cache = new ConcurrentHashMap<>(); } @@ -45,4 +56,12 @@ public class KubernetesDnsServiceDiscovery extends KubernetesServiceDiscovery { name + "." + getConfiguration().getNamespace() + ".svc." + getConfiguration().getDnsDomain(), -1); } + + @Override + public String toString() { + return "KubernetesDnsServiceDiscovery{" + + "namespace='" + namespace + '\'' + + ", zone='" + zone + '\'' + + '}'; + } } diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesDnsSrvServiceDiscovery.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesDnsSrvServiceDiscovery.java new file mode 100644 index 0000000..932f0fb --- /dev/null +++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesDnsSrvServiceDiscovery.java @@ -0,0 +1,146 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.component.kubernetes.cloud; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import javax.naming.NamingEnumeration; +import javax.naming.directory.DirContext; +import javax.naming.directory.InitialDirContext; + +import org.apache.camel.cloud.ServiceDefinition; +import org.apache.camel.component.kubernetes.KubernetesConfiguration; +import org.apache.camel.impl.cloud.DefaultServiceDefinition; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Discovers where services are running on which servers in Kubernetes. + */ +public class KubernetesDnsSrvServiceDiscovery extends KubernetesServiceDiscovery { + private static final Logger LOGGER; + private static final String[] ATTRIBUTE_IDS; + private static final Hashtable<String, String> ENV; + + static { + LOGGER = LoggerFactory.getLogger(KubernetesDnsSrvServiceDiscovery.class); + ATTRIBUTE_IDS = new String[] {"SRV"}; + + ENV = new Hashtable<>(); + ENV.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory"); + ENV.put("java.naming.provider.url", "dns:"); + } + + private final String namespace; + private final String portName; + private final String portProtocol; + private final String zone; + private final Map<String, String> cache; + + public KubernetesDnsSrvServiceDiscovery(KubernetesConfiguration configuration) { + super(configuration); + + this.namespace = configuration.getNamespace() != null ? configuration.getNamespace() : System.getenv("KUBERNETES_NAMESPACE"); + this.portName = configuration.getPortName(); + this.portProtocol = configuration.getPortProtocol(); + this.zone = configuration.getDnsDomain(); + + // validation + ObjectHelper.notNull(namespace, "Namespace"); + ObjectHelper.notNull(portName, "Port Name"); + ObjectHelper.notNull(portProtocol, "Port Protocol"); + ObjectHelper.notNull(zone, "DNS Domain"); + + this.cache = new HashMap<>(); + } + + /** + * Compute the query string to lookup SRV records. + * + * https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#supported-dns-schema + * https://github.com/kubernetes/dns/blob/master/docs/specification.md + * + * @param serviceName the service name + * @return the query + */ + protected String computeQueryString(String serviceName) { + // _<port_name>._<port_proto>.<serviceName>.<namespace>.svc.<zone>. + return String.format("_%s._%s.%s.%s.svc.%s", + this.portName, + this.portProtocol, + serviceName, + this.namespace, + this.zone + ); + } + + @Override + public List<ServiceDefinition> getServices(String name) { + try { + final String query = cache.computeIfAbsent(name, this::computeQueryString); + final DirContext ctx = new InitialDirContext(ENV); + final NamingEnumeration<?> resolved = ctx.getAttributes(query, ATTRIBUTE_IDS).get("srv").getAll(); + + if (resolved.hasMore()) { + List<ServiceDefinition> servers = new LinkedList<>(); + + while (resolved.hasMore()) { + String record = (String)resolved.next(); + String[] items = record.split(" ", -1); + String host = items[3].trim(); + String port = items[2].trim(); + + if (ObjectHelper.isEmpty(host) || ObjectHelper.isEmpty(port)) { + continue; + } + + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Found service address {}:{} for query: {}", host, port, query); + } + + if (!"0".equals(port)) { + servers.add(new DefaultServiceDefinition(name, host, Integer.parseInt(port))); + } + } + + return servers; + } else { + LOGGER.warn("Could not find any service for name={}, query={}", name, query); + } + } catch (Exception e) { + throw new RuntimeException("Could not resolve services via DNSSRV", e); + } + + return Collections.emptyList(); + } + + @Override + public String toString() { + return "KubernetesDnsSrvServiceDiscovery{" + + "namespace='" + namespace + '\'' + + ", portName='" + portName + '\'' + + ", portProtocol='" + portProtocol + '\'' + + ", zone='" + zone + '\'' + + '}'; + } +} diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesEnvServiceDiscovery.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesEnvServiceDiscovery.java index 4e62f0a..d55474a 100644 --- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesEnvServiceDiscovery.java +++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesEnvServiceDiscovery.java @@ -46,4 +46,9 @@ public class KubernetesEnvServiceDiscovery extends KubernetesServiceDiscovery { throw new RuntimeCamelException(e); } } + + @Override + public String toString() { + return "KubernetesEnvServiceDiscovery"; + } } diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesServiceDiscovery.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesServiceDiscovery.java index b6899c7..12630ff 100644 --- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesServiceDiscovery.java +++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesServiceDiscovery.java @@ -17,53 +17,20 @@ package org.apache.camel.component.kubernetes.cloud; -import io.fabric8.kubernetes.api.model.EndpointAddress; -import io.fabric8.kubernetes.api.model.EndpointPort; -import io.fabric8.kubernetes.client.AutoAdaptableKubernetesClient; -import org.apache.camel.cloud.ServiceDefinition; import org.apache.camel.component.kubernetes.KubernetesConfiguration; -import org.apache.camel.impl.cloud.DefaultServiceDefinition; import org.apache.camel.impl.cloud.DefaultServiceDiscovery; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Discovers where services are running on which servers in Kubernetes. */ -abstract class KubernetesServiceDiscovery extends DefaultServiceDiscovery { - private static final Logger LOG = LoggerFactory.getLogger(KubernetesServiceDiscovery.class); - private static final int FIRST = 0; - +public abstract class KubernetesServiceDiscovery extends DefaultServiceDiscovery { private final KubernetesConfiguration configuration; - private final String namespace; - private final String portName; - private AutoAdaptableKubernetesClient client; - KubernetesServiceDiscovery(KubernetesConfiguration configuration) { + public KubernetesServiceDiscovery(KubernetesConfiguration configuration) { this.configuration = configuration; - this.namespace = configuration.getNamespace() != null ? configuration.getNamespace() : System.getenv("KUBERNETES_NAMESPACE"); - this.portName = configuration.getPortName(); - this.client = null; - } - - @Override - public String toString() { - return "KubernetesServiceDiscovery"; - } - - protected ServiceDefinition newServer(String serviceName, EndpointAddress address, EndpointPort port) { - return new DefaultServiceDefinition(serviceName, address.getIp(), port.getPort()); } protected KubernetesConfiguration getConfiguration() { return this.configuration; } - - public String getNamespace() { - return namespace; - } - - public String getPortName() { - return portName; - } } diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesServiceDiscoveryFactory.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesServiceDiscoveryFactory.java index d93caa3..2b24ae2 100644 --- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesServiceDiscoveryFactory.java +++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesServiceDiscoveryFactory.java @@ -166,6 +166,22 @@ public class KubernetesServiceDiscoveryFactory implements ServiceDiscoveryFactor configuration.setDnsDomain(dnsDomain); } + public String getPortName() { + return configuration.getPortName(); + } + + public void setPortName(String portName) { + configuration.setPortName(portName); + } + + public String getPortProtocol() { + return configuration.getPortProtocol(); + } + + public void setPortProtocol(String portProtocol) { + configuration.setPortProtocol(portProtocol); + } + public String getLookup() { return lookup; } @@ -182,6 +198,8 @@ public class KubernetesServiceDiscoveryFactory implements ServiceDiscoveryFactor public ServiceDiscovery newInstance(CamelContext camelContext) throws Exception { if (ObjectHelper.equal("dns", lookup)) { return new KubernetesDnsServiceDiscovery(configuration); + } else if (ObjectHelper.equal("dnssrv", lookup)) { + return new KubernetesDnsSrvServiceDiscovery(configuration); } else if (ObjectHelper.equal("client", lookup)) { return new KubernetesClientServiceDiscovery(configuration); } diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/KubernetesServiceCallServiceDiscoveryConfigurationCommon.java b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/KubernetesServiceCallServiceDiscoveryConfigurationCommon.java index 1fea591..3f67d96 100644 --- a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/KubernetesServiceCallServiceDiscoveryConfigurationCommon.java +++ b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/KubernetesServiceCallServiceDiscoveryConfigurationCommon.java @@ -30,8 +30,9 @@ public class KubernetesServiceCallServiceDiscoveryConfigurationCommon { * When using client, then the client queries the kubernetes master to * obtain a list of active pods that provides the service, and then random * (or round robin) select a pod. When using dns the service name is - * resolved as name.namespace.service.dnsDomain. When using environment then - * environment variables are used to lookup the service. By default + * resolved as name.namespace.svc.dnsDomain. When using dnssrv the service + * name is resolved with SRV query for _._...svc... When using environment + * then environment variables are used to lookup the service. By default * environment is used. */ private String lookup = "environment"; @@ -40,6 +41,14 @@ public class KubernetesServiceCallServiceDiscoveryConfigurationCommon { */ private String dnsDomain; /** + * Sets the Port Name to use for DNS/DNSSRV lookup. + */ + private String portName; + /** + * Sets the Port Protocol to use for DNS/DNSSRV lookup. + */ + private String portProtocol; + /** * Sets the namespace to use. Will by default use namespace from the ENV * variable KUBERNETES_MASTER. */ @@ -128,6 +137,22 @@ public class KubernetesServiceCallServiceDiscoveryConfigurationCommon { this.dnsDomain = dnsDomain; } + public String getPortName() { + return portName; + } + + public void setPortName(String portName) { + this.portName = portName; + } + + public String getPortProtocol() { + return portProtocol; + } + + public void setPortProtocol(String portProtocol) { + this.portProtocol = portProtocol; + } + public String getNamespace() { return namespace; } diff --git a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/test/java/org/apache/camel/component/kubernetes/springboot/test/cloud/KubernetesServiceDiscoveryAutoConfigurationTest.java b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/test/java/org/apache/camel/component/kubernetes/springboot/test/cloud/KubernetesServiceDiscoveryAutoConfigurationTest.java index 5c9bd3f..8221a69 100644 --- a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/test/java/org/apache/camel/component/kubernetes/springboot/test/cloud/KubernetesServiceDiscoveryAutoConfigurationTest.java +++ b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/test/java/org/apache/camel/component/kubernetes/springboot/test/cloud/KubernetesServiceDiscoveryAutoConfigurationTest.java @@ -17,6 +17,10 @@ package org.apache.camel.component.kubernetes.springboot.test.cloud; import org.apache.camel.cloud.ServiceDiscovery; +import org.apache.camel.component.kubernetes.cloud.KubernetesClientServiceDiscovery; +import org.apache.camel.component.kubernetes.cloud.KubernetesDnsServiceDiscovery; +import org.apache.camel.component.kubernetes.cloud.KubernetesDnsSrvServiceDiscovery; +import org.apache.camel.component.kubernetes.cloud.KubernetesEnvServiceDiscovery; import org.apache.camel.model.cloud.springboot.KubernetesServiceCallServiceDiscoveryConfigurationProperties; import org.junit.Test; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -42,7 +46,6 @@ public class KubernetesServiceDiscoveryAutoConfigurationTest { ); } - @Test public void testServiceDiscoveryEnabled() { new ApplicationContextRunner() @@ -54,6 +57,81 @@ public class KubernetesServiceDiscoveryAutoConfigurationTest { context -> { assertThat(context).hasSingleBean(KubernetesServiceCallServiceDiscoveryConfigurationProperties.class); assertThat(context).getBeans(ServiceDiscovery.class).containsKeys("kubernetes-service-discovery"); + assertThat(context).getBean("kubernetes-service-discovery").isInstanceOf(KubernetesEnvServiceDiscovery.class); + } + ); + } + + @Test + public void testServiceDiscoveryWithEnv() { + new ApplicationContextRunner() + .withUserConfiguration(TestConfiguration.class) + .withPropertyValues( + "spring.main.banner-mode=off", + "camel.cloud.kubernetes.service-discovery.enabled=true", + "camel.cloud.kubernetes.service-discovery.lookup=env") + .run( + context -> { + assertThat(context).hasSingleBean(KubernetesServiceCallServiceDiscoveryConfigurationProperties.class); + assertThat(context).getBeans(ServiceDiscovery.class).containsKeys("kubernetes-service-discovery"); + assertThat(context).getBean("kubernetes-service-discovery").isInstanceOf(KubernetesEnvServiceDiscovery.class); + } + ); + } + + @Test + public void testServiceDiscoveryWithDns() { + new ApplicationContextRunner() + .withUserConfiguration(TestConfiguration.class) + .withPropertyValues( + "spring.main.banner-mode=off", + "camel.cloud.kubernetes.service-discovery.enabled=true", + "camel.cloud.kubernetes.service-discovery.lookup=dns", + "camel.cloud.kubernetes.service-discovery.dns-domain=mydomain", + "camel.cloud.kubernetes.service-discovery.namespace=mynamespace") + .run( + context -> { + assertThat(context).hasSingleBean(KubernetesServiceCallServiceDiscoveryConfigurationProperties.class); + assertThat(context).getBeans(ServiceDiscovery.class).containsKeys("kubernetes-service-discovery"); + assertThat(context).getBean("kubernetes-service-discovery").isInstanceOf(KubernetesDnsServiceDiscovery.class); + } + ); + } + + @Test + public void testServiceDiscoveryWithDnsSrv() { + new ApplicationContextRunner() + .withUserConfiguration(TestConfiguration.class) + .withPropertyValues( + "spring.main.banner-mode=off", + "camel.cloud.kubernetes.service-discovery.enabled=true", + "camel.cloud.kubernetes.service-discovery.lookup=dnssrv", + "camel.cloud.kubernetes.service-discovery.port-name=myportname", + "camel.cloud.kubernetes.service-discovery.port-proocole=myportproto", + "camel.cloud.kubernetes.service-discovery.dns-domain=mydomain", + "camel.cloud.kubernetes.service-discovery.namespace=mynamespace") + .run( + context -> { + assertThat(context).hasSingleBean(KubernetesServiceCallServiceDiscoveryConfigurationProperties.class); + assertThat(context).getBeans(ServiceDiscovery.class).containsKeys("kubernetes-service-discovery"); + assertThat(context).getBean("kubernetes-service-discovery").isInstanceOf(KubernetesDnsSrvServiceDiscovery.class); + } + ); + } + + @Test + public void testServiceDiscoveryWithClient() { + new ApplicationContextRunner() + .withUserConfiguration(TestConfiguration.class) + .withPropertyValues( + "spring.main.banner-mode=off", + "camel.cloud.kubernetes.service-discovery.enabled=true", + "camel.cloud.kubernetes.service-discovery.lookup=client") + .run( + context -> { + assertThat(context).hasSingleBean(KubernetesServiceCallServiceDiscoveryConfigurationProperties.class); + assertThat(context).getBeans(ServiceDiscovery.class).containsKeys("kubernetes-service-discovery"); + assertThat(context).getBean("kubernetes-service-discovery").isInstanceOf(KubernetesClientServiceDiscovery.class); } ); } -- To stop receiving notification emails like this one, please contact lburgazz...@apache.org.