24
24
25
25
import com .github .tomakehurst .wiremock .junit .WireMockRule ;
26
26
import com .google .gson .Gson ;
27
- import io .kubernetes .client .informer .SharedInformer ;
27
+ import io .kubernetes .client .informer .SharedIndexInformer ;
28
28
import io .kubernetes .client .informer .SharedInformerFactory ;
29
29
import io .kubernetes .client .informer .cache .Lister ;
30
30
import io .kubernetes .client .openapi .ApiClient ;
34
34
import io .kubernetes .client .openapi .models .V1ObjectMeta ;
35
35
import io .kubernetes .client .openapi .models .V1Pod ;
36
36
import io .kubernetes .client .openapi .models .V1PodList ;
37
- import io .kubernetes .client .spring .extended .controller .annotation .GroupVersionResource ;
38
- import io .kubernetes .client .spring .extended .controller .annotation .KubernetesInformer ;
39
- import io .kubernetes .client .spring .extended .controller .annotation .KubernetesInformers ;
40
37
import io .kubernetes .client .util .ClientBuilder ;
38
+ import io .kubernetes .client .util .generic .GenericKubernetesApi ;
41
39
import java .util .Arrays ;
42
40
import org .junit .Rule ;
43
41
import org .junit .Test ;
44
42
import org .junit .runner .RunWith ;
45
43
import org .springframework .beans .factory .annotation .Autowired ;
46
- import org .springframework .boot .autoconfigure .EnableAutoConfiguration ;
47
44
import org .springframework .boot .autoconfigure .SpringBootApplication ;
48
45
import org .springframework .boot .test .context .SpringBootTest ;
49
46
import org .springframework .context .annotation .Bean ;
50
47
import org .springframework .test .context .junit4 .SpringRunner ;
51
48
52
49
@ RunWith (SpringRunner .class )
53
- @ SpringBootTest ( classes = { KubernetesInformerCreatorTest . App . class })
50
+ @ SpringBootTest
54
51
public class KubernetesInformerCreatorTest {
55
52
56
53
@ Rule public WireMockRule wireMockRule = new WireMockRule (8188 );
57
54
58
55
@ SpringBootApplication
59
- @ EnableAutoConfiguration
60
56
static class App {
61
57
62
58
@ Bean
@@ -66,43 +62,34 @@ public ApiClient testingApiClient() {
66
62
}
67
63
68
64
@ Bean
69
- @ KubernetesInformers ({
70
- @ KubernetesInformer (
71
- apiTypeClass = V1Pod .class ,
72
- apiListTypeClass = V1PodList .class ,
73
- groupVersionResource =
74
- @ GroupVersionResource (apiGroup = "" , apiVersion = "v1" , resourcePlural = "pods" )),
75
- @ KubernetesInformer (
76
- apiTypeClass = V1ConfigMap .class ,
77
- apiListTypeClass = V1ConfigMapList .class ,
78
- namespace = "default" ,
79
- groupVersionResource =
80
- @ GroupVersionResource (
81
- apiGroup = "" ,
82
- apiVersion = "v1" ,
83
- resourcePlural = "configmaps" )),
84
- })
85
- public SharedInformerFactory testSharedInformerFactory () {
86
- return new SharedInformerFactory ();
65
+ public SharedIndexInformer <V1Pod > podInformer (
66
+ ApiClient apiClient , SharedInformerFactory sharedInformerFactory ) {
67
+ GenericKubernetesApi <V1Pod , V1PodList > genericApi =
68
+ new GenericKubernetesApi <>(V1Pod .class , V1PodList .class , "" , "v1" , "pods" , apiClient );
69
+ return sharedInformerFactory .sharedIndexInformerFor (genericApi , V1Pod .class , 0 );
70
+ }
71
+
72
+ @ Bean
73
+ public SharedIndexInformer <V1ConfigMap > configMapInformer (
74
+ ApiClient apiClient , SharedInformerFactory sharedInformerFactory ) {
75
+ GenericKubernetesApi <V1ConfigMap , V1ConfigMapList > genericApi =
76
+ new GenericKubernetesApi <>(
77
+ V1ConfigMap .class , V1ConfigMapList .class , "" , "v1" , "configmaps" , apiClient );
78
+ return sharedInformerFactory .sharedIndexInformerFor (
79
+ genericApi , V1ConfigMap .class , 0 , "default" );
87
80
}
88
81
}
89
82
90
83
@ Autowired private SharedInformerFactory informerFactory ;
91
84
92
- @ Autowired private SharedInformer <V1Pod > podInformer ;
93
-
94
- @ Autowired private SharedInformer <V1ConfigMap > configMapInformer ;
95
-
96
- @ Autowired private Lister <V1Pod > podLister ;
85
+ @ Autowired private SharedIndexInformer <V1Pod > podInformer ;
97
86
98
- @ Autowired private Lister <V1ConfigMap > configMapLister ;
87
+ @ Autowired private SharedIndexInformer <V1ConfigMap > configMapInformer ;
99
88
100
89
@ Test
101
90
public void testInformerInjection () throws InterruptedException {
102
91
assertNotNull (podInformer );
103
92
assertNotNull (configMapInformer );
104
- assertNotNull (podLister );
105
- assertNotNull (configMapLister );
106
93
107
94
V1Pod foo1 =
108
95
new V1Pod ().kind ("Pod" ).metadata (new V1ObjectMeta ().namespace ("default" ).name ("foo1" ));
@@ -162,7 +149,7 @@ public void testInformerInjection() throws InterruptedException {
162
149
getRequestedFor (urlPathEqualTo ("/api/v1/namespaces/default/configmaps" ))
163
150
.withQueryParam ("watch" , equalTo ("true" )));
164
151
165
- assertEquals (1 , podLister .list ().size ());
166
- assertEquals (1 , configMapLister .list ().size ());
152
+ assertEquals (1 , new Lister <>( podInformer . getIndexer ()) .list ().size ());
153
+ assertEquals (1 , new Lister <>( configMapInformer . getIndexer ()) .list ().size ());
167
154
}
168
155
}
0 commit comments