Skip to content
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

Reload functionality clean-up part 4 #1036

Merged
merged 36 commits into from
Jul 7, 2022

Conversation

wind57
Copy link
Contributor

@wind57 wind57 commented Jun 15, 2022

No description provided.

@wind57 wind57 changed the title Reload simplify configs part 4 Reload functionality clean-up part 4 Jun 15, 2022
@@ -43,10 +44,10 @@
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnKubernetesAndConfigEnabled
@ConditionalOnClass(EndpointAutoConfiguration.class)
@ConditionalOnKubernetesReloadEnabled
@ConditionalOnClass({ EndpointAutoConfiguration.class, RestartEndpoint.class, ContextRefresher.class })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two : RestartEndpoint.class, ContextRefresher.class where part of @ConditionalOnClass, so I just moved them in here, since we dropped the inner class. Initially I put them on @AutoConfigureAfter, but this was a brain fart from my side, as I placed them under the wrong annotation. sorry about that

@@ -63,32 +64,34 @@ public TaskSchedulerWrapper<TaskScheduler> taskScheduler() {
@Bean
@ConditionalOnMissingBean
public ConfigurationUpdateStrategy configurationUpdateStrategy(ConfigReloadProperties properties,
ConfigurableApplicationContext ctx, @Autowired(required = false) RestartEndpoint restarter,
ConfigurableApplicationContext ctx, Optional<RestartEndpoint> restarter,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Optional for the optional dependency

@@ -47,7 +46,9 @@ public class PollingConfigMapChangeDetector extends ConfigurationChangeDetector

private final TaskScheduler taskExecutor;

private final Duration period;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor simplifications here + made a method private

@@ -58,11 +58,11 @@
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnKubernetesAndConfigEnabled
@ConditionalOnClass(EndpointAutoConfiguration.class)
@ConditionalOnKubernetesReloadEnabled
@ConditionalOnClass({ EndpointAutoConfiguration.class, RestartEndpoint.class, ContextRefresher.class })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved RestartEndpoint.class, ContextRefresher.class to @ConditionalOnClass

@@ -58,11 +58,11 @@
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnKubernetesAndConfigEnabled
@ConditionalOnClass(EndpointAutoConfiguration.class)
@ConditionalOnKubernetesReloadEnabled
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created a new annotation @ConditionalOnKubernetesReloadEnabled to simplify reading the code


private KubernetesClient kubernetesClient;
private SharedIndexInformer<ConfigMap> informer;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use informer instead of watcher (just like we do in k8s-native), this will fix an issue I have opened about this subject

this.watches = new HashMap<>();
}

@PreDestroy
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we had two @PreDestroy methods, now there is just one; it shutsdown the informer and the client

*/
@ConditionalOnProperty("spring.cloud.kubernetes.reload.enabled")
@ConditionalOnClass({ RestartEndpoint.class, ContextRefresher.class })
protected static class ConfigReloadAutoConfigurationBeans {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same simplification has been done in fabric8 - drop the inner class, move annotations

@@ -44,17 +41,15 @@
*/
public class KubernetesClientEventBasedConfigMapChangeDetector extends ConfigurationChangeDetector {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some minor cleanups in this class

@@ -114,5 +114,8 @@
<module>spring-cloud-kubernetes-client-reactive-discoveryclient-it</module>
<module>spring-cloud-kubernetes-configuration-watcher-it</module>
<module>spring-cloud-kubernetes-core-k8s-client-it</module>
</modules>
<module>spring-cloud-kubernetes-fabric8-client-configmap-polling-reload</module>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added 3 more integration tests

Optional.ofNullable(exception).map(e -> {
log.debug("Exception received during watch", e);
return exception.asClientException();
}).map(KubernetesClientException::getStatus).map(Status::getCode)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've asked fabric8 team about this HTTP_GONE and they told me that with informers this should not be a problem anymore. Still, if we face it, I've let the commented code in the repo. In future, we will know where to look and how to fix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm was that fixed in a specific k8s version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so here is where I asked if we should be handling this in case of informers too and where I was told - not really.

Initially, I thought about adding it via the onNothing method:

@Override
public void onNothing() {
	boolean isStoreEmpty = informer.getStore().list().isEmpty();
	if(!isStoreEmpty) {
		// HTTP_GONE, thus re-inform
		inform();
	}
}

Marc said that this should not be needed and I am inclined to trust him, since informers are much more resilient than watchers. I am also inclined to trust this statement, since such a method (where you can track a HTTP_GONE) does not even exist in k8s-native implementation.

@wind57 wind57 marked this pull request as ready for review July 6, 2022 10:05
@wind57
Copy link
Contributor Author

wind57 commented Jul 6, 2022

@ryanjbaxter last clean-up on the reload functionality.

@ryanjbaxter ryanjbaxter added this to the 3.0.0-M4 milestone Jul 7, 2022
@ryanjbaxter ryanjbaxter merged commit 797af02 into spring-cloud:main Jul 7, 2022
@ryanjbaxter ryanjbaxter linked an issue Jul 7, 2022 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Informers instead of Watcher in reload for fabric8
3 participants