File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8 Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change 2323import io .fabric8 .kubernetes .client .KubernetesClient ;
2424import io .fabric8 .kubernetes .client .KubernetesClientBuilder ;
2525
26+ import org .springframework .beans .factory .BeanFactoryUtils ;
2627import org .springframework .boot .autoconfigure .AutoConfigureAfter ;
2728import org .springframework .boot .autoconfigure .condition .ConditionalOnCloudPlatform ;
2829import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingBean ;
2930import org .springframework .boot .cloud .CloudPlatform ;
3031import org .springframework .cloud .kubernetes .commons .KubernetesClientProperties ;
3132import org .springframework .cloud .kubernetes .commons .KubernetesCommonsAutoConfiguration ;
33+ import org .springframework .context .ApplicationContext ;
34+ import org .springframework .context .ApplicationListener ;
3235import org .springframework .context .annotation .Bean ;
3336import org .springframework .context .annotation .Configuration ;
37+ import org .springframework .context .event .ContextClosedEvent ;
38+ import org .springframework .context .event .EventListener ;
3439
3540/**
3641 * Auto configuration for Kubernetes.
@@ -117,4 +122,11 @@ public Fabric8PodUtils kubernetesPodUtils(KubernetesClient client) {
117122 return new Fabric8PodUtils (client );
118123 }
119124
125+ @ EventListener
126+ public void onContextClosed (ContextClosedEvent event ) {
127+ ApplicationContext context = event .getApplicationContext ();
128+ BeanFactoryUtils .beansOfTypeIncludingAncestors (context , KubernetesClient .class ).values ()
129+ .forEach (c -> c .close ());
130+ }
131+
120132}
You can’t perform that action at this time.
0 commit comments