|
12 | 12 | */ |
13 | 13 | package io.kubernetes.client.spring.extended.network.endpoints; |
14 | 14 |
|
15 | | -import com.google.common.cache.Cache; |
16 | | -import com.google.common.cache.CacheBuilder; |
17 | 15 | import io.kubernetes.client.apimachinery.NamespaceName; |
18 | 16 | import io.kubernetes.client.openapi.ApiClient; |
| 17 | +import io.kubernetes.client.openapi.ApiException; |
19 | 18 | import io.kubernetes.client.openapi.apis.CoreV1Api; |
20 | 19 | import io.kubernetes.client.openapi.models.V1Endpoints; |
21 | 20 | import java.time.Duration; |
22 | | -import java.util.concurrent.ExecutionException; |
| 21 | + |
| 22 | +import com.github.benmanes.caffeine.cache.Cache; |
| 23 | +import com.github.benmanes.caffeine.cache.Caffeine; |
| 24 | + |
23 | 25 | import org.springframework.beans.factory.annotation.Autowired; |
24 | 26 |
|
25 | 27 | public class PollingEndpointsGetter implements EndpointsGetter { |
26 | 28 |
|
27 | | - private static final Cache<NamespaceName, V1Endpoints> lastObservedEndpoints = |
28 | | - CacheBuilder.newBuilder().expireAfterWrite(Duration.ofMinutes(5)).build(); |
| 29 | + private static final Cache<NamespaceName, V1Endpoints> lastObservedEndpoints = Caffeine.newBuilder() |
| 30 | + .expireAfterWrite(Duration.ofMinutes(5)).build(); |
29 | 31 |
|
30 | | - @Autowired private ApiClient apiClient; |
| 32 | + @Autowired |
| 33 | + private ApiClient apiClient; |
31 | 34 |
|
32 | 35 | @Override |
33 | 36 | public V1Endpoints get(String namespace, String name) { |
34 | 37 | CoreV1Api coreV1Api = new CoreV1Api(apiClient); |
35 | | - try { |
36 | | - return lastObservedEndpoints.get( |
37 | | - new NamespaceName(namespace, name), |
38 | | - () -> { |
39 | | - return coreV1Api.readNamespacedEndpoints(name, namespace, null, null, null); |
40 | | - }); |
41 | | - } catch (ExecutionException e) { |
42 | | - throw new RuntimeException(e); |
43 | | - } |
| 38 | + return lastObservedEndpoints.get(new NamespaceName(namespace, name), k -> { |
| 39 | + try { |
| 40 | + return coreV1Api.readNamespacedEndpoints(name, namespace, null, null, null); |
| 41 | + } catch (ApiException e) { |
| 42 | + throw new IllegalStateException(e); |
| 43 | + } |
| 44 | + }); |
44 | 45 | } |
45 | 46 | } |
0 commit comments