|
29 | 29 | import io.kubernetes.client.openapi.models.V1EndpointsList; |
30 | 30 | import io.kubernetes.client.openapi.models.V1Service; |
31 | 31 | import io.kubernetes.client.openapi.models.V1ServiceList; |
| 32 | +import io.kubernetes.client.util.CallGenerator; |
32 | 33 | import io.kubernetes.client.util.Namespaces; |
33 | | -import io.kubernetes.client.util.generic.GenericKubernetesApi; |
34 | 34 | import org.apache.commons.logging.Log; |
35 | 35 | import org.apache.commons.logging.LogFactory; |
36 | 36 |
|
|
47 | 47 | import org.springframework.core.env.Environment; |
48 | 48 |
|
49 | 49 | import static org.springframework.cloud.kubernetes.client.KubernetesClientUtils.kubernetesApiClient; |
| 50 | +import static org.springframework.cloud.kubernetes.client.discovery.KubernetesClientDiscoveryClientUtils.endpointsCallGenerator; |
| 51 | +import static org.springframework.cloud.kubernetes.client.discovery.KubernetesClientDiscoveryClientUtils.servicesCallGenerator; |
50 | 52 |
|
51 | 53 | /** |
52 | 54 | * @author Ryan Baxter |
@@ -81,24 +83,30 @@ public void initialize(BootstrapRegistry registry) { |
81 | 83 | ApiClient defaultApiClient = kubernetesApiClient(); |
82 | 84 | defaultApiClient.setUserAgent(propertyResolver.get("spring.cloud.kubernetes.client.user-agent", |
83 | 85 | String.class, KubernetesClientProperties.DEFAULT_USER_AGENT)); |
| 86 | + |
84 | 87 | KubernetesClientAutoConfiguration clientAutoConfiguration = new KubernetesClientAutoConfiguration(); |
85 | 88 | ApiClient apiClient = context.getOrElseSupply(ApiClient.class, () -> defaultApiClient); |
86 | 89 |
|
87 | 90 | KubernetesNamespaceProvider kubernetesNamespaceProvider = clientAutoConfiguration |
88 | 91 | .kubernetesNamespaceProvider(getNamespaceEnvironment(propertyResolver)); |
| 92 | + |
89 | 93 | KubernetesDiscoveryProperties discoveryProperties = context.get(KubernetesDiscoveryProperties.class); |
90 | 94 | String namespace = getInformerNamespace(kubernetesNamespaceProvider, discoveryProperties); |
91 | 95 | SharedInformerFactory sharedInformerFactory = new SharedInformerFactory(apiClient); |
92 | | - GenericKubernetesApi<V1Service, V1ServiceList> servicesApi = new GenericKubernetesApi<>(V1Service.class, |
93 | | - V1ServiceList.class, "", "v1", "services", apiClient); |
| 96 | + CoreV1Api coreV1Api = new CoreV1Api(apiClient); |
| 97 | + |
| 98 | + CallGenerator serviceCallGenerator = servicesCallGenerator(coreV1Api, |
| 99 | + discoveryProperties.serviceLabels(), namespace); |
94 | 100 | SharedIndexInformer<V1Service> serviceSharedIndexInformer = sharedInformerFactory |
95 | | - .sharedIndexInformerFor(servicesApi, V1Service.class, 0L, namespace); |
| 101 | + .sharedIndexInformerFor(serviceCallGenerator, V1Service.class, V1ServiceList.class); |
96 | 102 | Lister<V1Service> serviceLister = new Lister<>(serviceSharedIndexInformer.getIndexer()); |
97 | | - GenericKubernetesApi<V1Endpoints, V1EndpointsList> endpointsApi = new GenericKubernetesApi<>( |
98 | | - V1Endpoints.class, V1EndpointsList.class, "", "v1", "endpoints", apiClient); |
| 103 | + |
| 104 | + CallGenerator endpointsCallGenerator = endpointsCallGenerator(coreV1Api, |
| 105 | + discoveryProperties.serviceLabels(), namespace); |
99 | 106 | SharedIndexInformer<V1Endpoints> endpointsSharedIndexInformer = sharedInformerFactory |
100 | | - .sharedIndexInformerFor(endpointsApi, V1Endpoints.class, 0L, namespace); |
| 107 | + .sharedIndexInformerFor(endpointsCallGenerator, V1Endpoints.class, V1EndpointsList.class); |
101 | 108 | Lister<V1Endpoints> endpointsLister = new Lister<>(endpointsSharedIndexInformer.getIndexer()); |
| 109 | + |
102 | 110 | Predicate<V1Service> predicate = x -> true; |
103 | 111 | KubernetesClientInformerDiscoveryClient discoveryClient = new KubernetesClientInformerDiscoveryClient( |
104 | 112 | List.of(sharedInformerFactory), List.of(serviceLister), List.of(endpointsLister), |
|
0 commit comments