@@ -8,6 +8,12 @@ import (
8
8
9
9
. "github.com/onsi/ginkgo"
10
10
. "github.com/onsi/gomega"
11
+
12
+ corev1 "k8s.io/api/core/v1"
13
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14
+ "k8s.io/apimachinery/pkg/runtime/schema"
15
+ "k8s.io/client-go/kubernetes/scheme"
16
+ "k8s.io/client-go/rest"
11
17
"sigs.k8s.io/controller-runtime/pkg/internal/testing/integration"
12
18
)
13
19
@@ -38,7 +44,24 @@ var _ = Describe("The Testing Framework", func() {
38
44
fmt .Sprintf ("Expected Etcd to listen for clients on %s," , etcdClientURL .Host ))
39
45
40
46
By ("Ensuring APIServer is listening" )
41
- CheckAPIServerIsReady (controlPlane .KubeCtl ())
47
+ c , err := controlPlane .RESTClientConfig ()
48
+ Expect (err ).NotTo (HaveOccurred ())
49
+ CheckAPIServerIsReady (c )
50
+
51
+ By ("getting a kubeclient & run it against the control plane" )
52
+ c .APIPath = "/api"
53
+ c .ContentConfig .GroupVersion = & schema.GroupVersion {Version : "v1" }
54
+ kubeClient , err := rest .RESTClientFor (c )
55
+ Expect (err ).NotTo (HaveOccurred ())
56
+ result := & corev1.PodList {}
57
+ err = kubeClient .Get ().
58
+ Namespace ("default" ).
59
+ Resource ("pods" ).
60
+ VersionedParams (& metav1.ListOptions {}, scheme .ParameterCodec ).
61
+ Do ().
62
+ Into (result )
63
+ Expect (err ).NotTo (HaveOccurred ())
64
+ Expect (result .Items ).To (BeEmpty ())
42
65
43
66
By ("getting a kubectl & run it against the control plane" )
44
67
kubeCtl := controlPlane .KubeCtl ()
@@ -165,26 +188,98 @@ func isSomethingListeningOnPort(hostAndPort string) portChecker {
165
188
// this changed behaviour does what it should do, we used the same test as in
166
189
// k/k's test-cmd (see link above) and test if certain well-known known APIs
167
190
// are actually available.
168
- func CheckAPIServerIsReady (kubeCtl * integration.KubeCtl ) {
169
- expectedAPIS := []string {
170
- "/api/v1/namespaces/default/pods 200 OK" ,
171
- "/api/v1/namespaces/default/replicationcontrollers 200 OK" ,
172
- "/api/v1/namespaces/default/services 200 OK" ,
173
- "/apis/apps/v1/namespaces/default/daemonsets 200 OK" ,
174
- "/apis/apps/v1/namespaces/default/deployments 200 OK" ,
175
- "/apis/apps/v1/namespaces/default/replicasets 200 OK" ,
176
- "/apis/apps/v1/namespaces/default/statefulsets 200 OK" ,
177
- "/apis/autoscaling/v1/namespaces/default/horizontalpodautoscalers 200" ,
178
- "/apis/batch/v1/namespaces/default/jobs 200 OK" ,
179
- }
180
-
181
- _ , output , err := kubeCtl .Run ("--v=6" , "--namespace" , "default" , "get" , "all" , "--chunk-size=0" )
182
- ExpectWithOffset (1 , err ).NotTo (HaveOccurred ())
183
-
184
- stdoutBytes , err := ioutil .ReadAll (output )
185
- ExpectWithOffset (1 , err ).NotTo (HaveOccurred ())
186
-
187
- for _ , api := range expectedAPIS {
188
- ExpectWithOffset (1 , string (stdoutBytes )).To (ContainSubstring (api ))
189
- }
191
+ func CheckAPIServerIsReady (c * rest.Config ) {
192
+ // check pods, replicationcontrollers and services
193
+ c .APIPath = "/api"
194
+ c .ContentConfig .GroupVersion = & schema.GroupVersion {Version : "v1" }
195
+ kubeClient , err := rest .RESTClientFor (c )
196
+ Expect (err ).NotTo (HaveOccurred ())
197
+
198
+ _ , err = kubeClient .Get ().
199
+ Namespace ("default" ).
200
+ Resource ("pods" ).
201
+ VersionedParams (& metav1.ListOptions {}, scheme .ParameterCodec ).
202
+ Do ().
203
+ Get ()
204
+ Expect (err ).NotTo (HaveOccurred ())
205
+
206
+ _ , err = kubeClient .Get ().
207
+ Namespace ("default" ).
208
+ Resource ("replicationcontrollers" ).
209
+ VersionedParams (& metav1.ListOptions {}, scheme .ParameterCodec ).
210
+ Do ().
211
+ Get ()
212
+ Expect (err ).NotTo (HaveOccurred ())
213
+
214
+ _ , err = kubeClient .Get ().
215
+ Namespace ("default" ).
216
+ Resource ("services" ).
217
+ VersionedParams (& metav1.ListOptions {}, scheme .ParameterCodec ).
218
+ Do ().
219
+ Get ()
220
+ Expect (err ).NotTo (HaveOccurred ())
221
+
222
+ // check daemonsets, deployments, replicasets and statefulsets,
223
+ c .APIPath = "/apis"
224
+ c .ContentConfig .GroupVersion = & schema.GroupVersion {Group : "apps" , Version : "v1" }
225
+ kubeClient , err = rest .RESTClientFor (c )
226
+ Expect (err ).NotTo (HaveOccurred ())
227
+
228
+ _ , err = kubeClient .Get ().
229
+ Namespace ("default" ).
230
+ Resource ("daemonsets" ).
231
+ VersionedParams (& metav1.ListOptions {}, scheme .ParameterCodec ).
232
+ Do ().
233
+ Get ()
234
+ Expect (err ).NotTo (HaveOccurred ())
235
+
236
+ _ , err = kubeClient .Get ().
237
+ Namespace ("default" ).
238
+ Resource ("deployments" ).
239
+ VersionedParams (& metav1.ListOptions {}, scheme .ParameterCodec ).
240
+ Do ().
241
+ Get ()
242
+ Expect (err ).NotTo (HaveOccurred ())
243
+
244
+ _ , err = kubeClient .Get ().
245
+ Namespace ("default" ).
246
+ Resource ("replicasets" ).
247
+ VersionedParams (& metav1.ListOptions {}, scheme .ParameterCodec ).
248
+ Do ().
249
+ Get ()
250
+ Expect (err ).NotTo (HaveOccurred ())
251
+
252
+ _ , err = kubeClient .Get ().
253
+ Namespace ("default" ).
254
+ Resource ("statefulsets" ).
255
+ VersionedParams (& metav1.ListOptions {}, scheme .ParameterCodec ).
256
+ Do ().
257
+ Get ()
258
+ Expect (err ).NotTo (HaveOccurred ())
259
+
260
+ // check horizontalpodautoscalers
261
+ c .ContentConfig .GroupVersion = & schema.GroupVersion {Group : "autoscaling" , Version : "v1" }
262
+ kubeClient , err = rest .RESTClientFor (c )
263
+ Expect (err ).NotTo (HaveOccurred ())
264
+
265
+ _ , err = kubeClient .Get ().
266
+ Namespace ("default" ).
267
+ Resource ("horizontalpodautoscalers" ).
268
+ VersionedParams (& metav1.ListOptions {}, scheme .ParameterCodec ).
269
+ Do ().
270
+ Get ()
271
+ Expect (err ).NotTo (HaveOccurred ())
272
+
273
+ // check jobs
274
+ c .ContentConfig .GroupVersion = & schema.GroupVersion {Group : "batch" , Version : "v1" }
275
+ kubeClient , err = rest .RESTClientFor (c )
276
+ Expect (err ).NotTo (HaveOccurred ())
277
+
278
+ _ , err = kubeClient .Get ().
279
+ Namespace ("default" ).
280
+ Resource ("jobs" ).
281
+ VersionedParams (& metav1.ListOptions {}, scheme .ParameterCodec ).
282
+ Do ().
283
+ Get ()
284
+ Expect (err ).NotTo (HaveOccurred ())
190
285
}
0 commit comments