2222import io .fabric8 .kubernetes .client .ConfigBuilder ;
2323import io .fabric8 .kubernetes .client .KubernetesClient ;
2424import io .fabric8 .kubernetes .client .KubernetesClientBuilder ;
25+ import jakarta .annotation .PreDestroy ;
2526
27+ import org .springframework .beans .factory .annotation .Autowired ;
2628import org .springframework .boot .autoconfigure .AutoConfigureAfter ;
2729import org .springframework .boot .autoconfigure .condition .ConditionalOnCloudPlatform ;
2830import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingBean ;
2931import org .springframework .boot .cloud .CloudPlatform ;
3032import org .springframework .cloud .kubernetes .commons .KubernetesClientProperties ;
3133import org .springframework .cloud .kubernetes .commons .KubernetesCommonsAutoConfiguration ;
34+ import org .springframework .context .ApplicationContext ;
3235import org .springframework .context .annotation .Bean ;
3336import org .springframework .context .annotation .Configuration ;
3437
4447@ AutoConfigureAfter (KubernetesCommonsAutoConfiguration .class )
4548public class Fabric8AutoConfiguration {
4649
50+ @ Autowired
51+ private ApplicationContext context ;
52+
4753 private static <D > D or (D left , D right ) {
4854 return left != null ? left : right ;
4955 }
@@ -52,10 +58,6 @@ private static Integer orDurationInt(Duration left, Integer right) {
5258 return left != null ? (int ) left .toMillis () : right ;
5359 }
5460
55- private static Long orDurationLong (Duration left , Long right ) {
56- return left != null ? left .toMillis () : right ;
57- }
58-
5961 @ Bean
6062 @ ConditionalOnMissingBean (Config .class )
6163 public Config kubernetesClientConfig (KubernetesClientProperties kubernetesClientProperties ) {
@@ -117,4 +119,9 @@ public Fabric8PodUtils kubernetesPodUtils(KubernetesClient client) {
117119 return new Fabric8PodUtils (client );
118120 }
119121
122+ @ PreDestroy
123+ void preDestroy () {
124+ context .getBeansOfType (KubernetesClient .class ).values ().forEach (KubernetesClient ::close );
125+ }
126+
120127}
0 commit comments