-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Added reactive support for service discovery #470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6aece13
Initial reactive service discovery client implementation
TYsewyn f685d11
Merge branch 'master' into feature/reactive-discovery-client
TYsewyn 8193a17
Re-added optional spring-boot-autoconfigure dependency
TYsewyn a3466fd
Use string for @ConditionalOnClass
TYsewyn bf60abb
Fixed IT
TYsewyn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...re/src/main/java/org/springframework/cloud/kubernetes/ConditionalOnKubernetesEnabled.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * Copyright 2019-2019 the original author or authors. | ||
| * | ||
| * Licensed 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 | ||
| * | ||
| * https://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.springframework.cloud.kubernetes; | ||
|
|
||
| import java.lang.annotation.Documented; | ||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Inherited; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
|
|
||
| /** | ||
| * Provides a more succinct conditional <code>spring.cloud.kubernetes.enabled</code>. | ||
| * | ||
| * @author Tim Ysewyn | ||
| * @since 2.2.0 | ||
| */ | ||
| @Target(ElementType.TYPE) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Documented | ||
| @Inherited | ||
| @ConditionalOnProperty(value = "spring.cloud.kubernetes.enabled", matchIfMissing = true) | ||
| public @interface ConditionalOnKubernetesEnabled { | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...g/springframework/cloud/kubernetes/discovery/ConditionalOnKubernetesDiscoveryEnabled.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * Copyright 2019-2019 the original author or authors. | ||
| * | ||
| * Licensed 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 | ||
| * | ||
| * https://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.springframework.cloud.kubernetes.discovery; | ||
|
|
||
| import java.lang.annotation.Documented; | ||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Inherited; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
|
|
||
| /** | ||
| * Provides a more succinct conditional | ||
| * <code>spring.cloud.kubernetes.discovery.enabled</code>. | ||
| * | ||
| * @author Tim Ysewyn | ||
| * @since 2.2.0 | ||
| */ | ||
| @Target(ElementType.TYPE) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Documented | ||
| @Inherited | ||
| @ConditionalOnProperty(value = "spring.cloud.kubernetes.discovery.enabled", | ||
| matchIfMissing = true) | ||
| public @interface ConditionalOnKubernetesDiscoveryEnabled { | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...pringframework/cloud/kubernetes/discovery/reactive/KubernetesReactiveDiscoveryClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * Copyright 2019-2019 the original author or authors. | ||
| * | ||
| * Licensed 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 | ||
| * | ||
| * https://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.springframework.cloud.kubernetes.discovery.reactive; | ||
|
|
||
| import io.fabric8.kubernetes.client.KubernetesClient; | ||
| import reactor.core.publisher.Flux; | ||
| import reactor.core.scheduler.Schedulers; | ||
|
|
||
| import org.springframework.cloud.client.ServiceInstance; | ||
| import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient; | ||
| import org.springframework.cloud.kubernetes.discovery.KubernetesClientServicesFunction; | ||
| import org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryClient; | ||
| import org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryProperties; | ||
| import org.springframework.util.Assert; | ||
|
|
||
| /** | ||
| * Kubernetes implementation of {@link ReactiveDiscoveryClient}. Currently relies on the | ||
| * {@link KubernetesDiscoveryClient} for feature parity. | ||
| * | ||
| * @author Tim Ysewyn | ||
| */ | ||
| public class KubernetesReactiveDiscoveryClient implements ReactiveDiscoveryClient { | ||
|
|
||
| private final KubernetesDiscoveryClient kubernetesDiscoveryClient; | ||
|
|
||
| public KubernetesReactiveDiscoveryClient(KubernetesClient client, | ||
| KubernetesDiscoveryProperties properties, | ||
| KubernetesClientServicesFunction kubernetesClientServicesFunction) { | ||
| this.kubernetesDiscoveryClient = new KubernetesDiscoveryClient(client, properties, | ||
| kubernetesClientServicesFunction); | ||
| } | ||
|
|
||
| @Override | ||
| public String description() { | ||
| return "Kubernetes Reactive Discovery Client"; | ||
| } | ||
|
|
||
| @Override | ||
| public Flux<ServiceInstance> getInstances(String serviceId) { | ||
| Assert.notNull(serviceId, | ||
| "[Assertion failed] - the object argument must not be null"); | ||
| return Flux | ||
| .defer(() -> Flux | ||
| .fromIterable(kubernetesDiscoveryClient.getInstances(serviceId))) | ||
| .subscribeOn(Schedulers.boundedElastic()); | ||
| } | ||
|
|
||
| @Override | ||
| public Flux<String> getServices() { | ||
| return Flux | ||
| .defer(() -> Flux.fromIterable(kubernetesDiscoveryClient.getServices())) | ||
| .subscribeOn(Schedulers.boundedElastic()); | ||
| } | ||
|
|
||
| } |
76 changes: 76 additions & 0 deletions
76
...oud/kubernetes/discovery/reactive/KubernetesReactiveDiscoveryClientAutoConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * Copyright 2013-2019 the original author or authors. | ||
| * | ||
| * Licensed 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 | ||
| * | ||
| * https://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.springframework.cloud.kubernetes.discovery.reactive; | ||
|
|
||
| import io.fabric8.kubernetes.client.KubernetesClient; | ||
|
|
||
| import org.springframework.boot.autoconfigure.AutoConfigureAfter; | ||
| import org.springframework.boot.autoconfigure.AutoConfigureBefore; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
| import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled; | ||
| import org.springframework.cloud.client.ConditionalOnDiscoveryHealthIndicatorEnabled; | ||
| import org.springframework.cloud.client.ConditionalOnReactiveDiscoveryEnabled; | ||
| import org.springframework.cloud.client.ReactiveCommonsClientAutoConfiguration; | ||
| import org.springframework.cloud.client.discovery.composite.reactive.ReactiveCompositeDiscoveryClientAutoConfiguration; | ||
| import org.springframework.cloud.client.discovery.health.DiscoveryClientHealthIndicatorProperties; | ||
| import org.springframework.cloud.client.discovery.health.reactive.ReactiveDiscoveryClientHealthIndicator; | ||
| import org.springframework.cloud.client.discovery.simple.reactive.SimpleReactiveDiscoveryClientAutoConfiguration; | ||
| import org.springframework.cloud.kubernetes.ConditionalOnKubernetesEnabled; | ||
| import org.springframework.cloud.kubernetes.discovery.ConditionalOnKubernetesDiscoveryEnabled; | ||
| import org.springframework.cloud.kubernetes.discovery.KubernetesClientServicesFunction; | ||
| import org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryClientAutoConfiguration; | ||
| import org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryProperties; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| /** | ||
| * Auto configuration for reactive discovery client. | ||
| * | ||
| * @author Tim Ysewyn | ||
| */ | ||
| @Configuration | ||
| @ConditionalOnDiscoveryEnabled | ||
| @ConditionalOnReactiveDiscoveryEnabled | ||
| @ConditionalOnKubernetesEnabled | ||
| @ConditionalOnKubernetesDiscoveryEnabled | ||
| @AutoConfigureBefore({ SimpleReactiveDiscoveryClientAutoConfiguration.class, | ||
| ReactiveCommonsClientAutoConfiguration.class }) | ||
| @AutoConfigureAfter({ ReactiveCompositeDiscoveryClientAutoConfiguration.class, | ||
| KubernetesDiscoveryClientAutoConfiguration.class }) | ||
| public class KubernetesReactiveDiscoveryClientAutoConfiguration { | ||
|
|
||
| @Bean | ||
| @ConditionalOnMissingBean | ||
| public KubernetesReactiveDiscoveryClient kubernetesReactiveDiscoveryClient( | ||
| KubernetesClient client, KubernetesDiscoveryProperties properties, | ||
| KubernetesClientServicesFunction kubernetesClientServicesFunction) { | ||
| return new KubernetesReactiveDiscoveryClient(client, properties, | ||
| kubernetesClientServicesFunction); | ||
| } | ||
|
|
||
| @Bean | ||
| @ConditionalOnClass( | ||
| name = "org.springframework.boot.actuate.health.ReactiveHealthIndicator") | ||
| @ConditionalOnDiscoveryHealthIndicatorEnabled | ||
| public ReactiveDiscoveryClientHealthIndicator kubernetesReactiveDiscoveryClientHealthIndicator( | ||
| KubernetesReactiveDiscoveryClient client, | ||
| DiscoveryClientHealthIndicatorProperties properties) { | ||
| return new ReactiveDiscoveryClientHealthIndicator(client, properties); | ||
| } | ||
|
|
||
| } |
3 changes: 2 additions & 1 deletion
3
spring-cloud-kubernetes-discovery/src/main/resources/META-INF/spring.factories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ | ||
| org.springframework.cloud.kubernetes.discovery.KubernetesCatalogWatchAutoConfiguration, \ | ||
| org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryClientAutoConfiguration | ||
| org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryClientAutoConfiguration, \ | ||
| org.springframework.cloud.kubernetes.discovery.reactive.KubernetesReactiveDiscoveryClientAutoConfiguration | ||
| org.springframework.cloud.bootstrap.BootstrapConfiguration=\ | ||
| org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryClientConfigClientBootstrapConfiguration |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a nested class here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reactive service discovery needs the other beans too, and I didn't want to break backwards compatibility in case someone is doing weird stuff by disabling auto configuration and importing
KubernetesDiscoveryClientAutoConfiguration.