@@ -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,23 @@ 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
+ CheckAPIServerIsReady (controlPlane .RESTClientConfig ())
48
+
49
+ By ("getting a kubeclient & run it against the control plane" )
50
+ c := controlPlane .RESTClientConfig ()
51
+ c .APIPath = "/api"
52
+ c .ContentConfig .GroupVersion = & schema.GroupVersion {Version : "v1" }
53
+ kubeClient , err := rest .RESTClientFor (c )
54
+ Expect (err ).NotTo (HaveOccurred ())
55
+ result := & corev1.PodList {}
56
+ err = kubeClient .Get ().
57
+ Namespace ("default" ).
58
+ Resource ("pods" ).
59
+ VersionedParams (& metav1.ListOptions {}, scheme .ParameterCodec ).
60
+ Do ().
61
+ Into (result )
62
+ Expect (err ).NotTo (HaveOccurred ())
63
+ Expect (result .Items ).To (BeEmpty ())
42
64
43
65
By ("getting a kubectl & run it against the control plane" )
44
66
kubeCtl := controlPlane .KubeCtl ()
@@ -165,26 +187,98 @@ func isSomethingListeningOnPort(hostAndPort string) portChecker {
165
187
// this changed behaviour does what it should do, we used the same test as in
166
188
// k/k's test-cmd (see link above) and test if certain well-known known APIs
167
189
// 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
- }
190
+ func CheckAPIServerIsReady (c * rest.Config ) {
191
+ // check pods, replicationcontrollers and services
192
+ c .APIPath = "/api"
193
+ c .ContentConfig .GroupVersion = & schema.GroupVersion {Version : "v1" }
194
+ kubeClient , err := rest .RESTClientFor (c )
195
+ Expect (err ).NotTo (HaveOccurred ())
196
+
197
+ _ , err = kubeClient .Get ().
198
+ Namespace ("default" ).
199
+ Resource ("pods" ).
200
+ VersionedParams (& metav1.ListOptions {}, scheme .ParameterCodec ).
201
+ Do ().
202
+ Get ()
203
+ Expect (err ).NotTo (HaveOccurred ())
204
+
205
+ _ , err = kubeClient .Get ().
206
+ Namespace ("default" ).
207
+ Resource ("replicationcontrollers" ).
208
+ VersionedParams (& metav1.ListOptions {}, scheme .ParameterCodec ).
209
+ Do ().
210
+ Get ()
211
+ Expect (err ).NotTo (HaveOccurred ())
212
+
213
+ _ , err = kubeClient .Get ().
214
+ Namespace ("default" ).
215
+ Resource ("services" ).
216
+ VersionedParams (& metav1.ListOptions {}, scheme .ParameterCodec ).
217
+ Do ().
218
+ Get ()
219
+ Expect (err ).NotTo (HaveOccurred ())
220
+
221
+ // check daemonsets, deployments, replicasets and statefulsets,
222
+ c .APIPath = "/apis"
223
+ c .ContentConfig .GroupVersion = & schema.GroupVersion {Group : "apps" , Version : "v1" }
224
+ kubeClient , err = rest .RESTClientFor (c )
225
+ Expect (err ).NotTo (HaveOccurred ())
226
+
227
+ _ , err = kubeClient .Get ().
228
+ Namespace ("default" ).
229
+ Resource ("daemonsets" ).
230
+ VersionedParams (& metav1.ListOptions {}, scheme .ParameterCodec ).
231
+ Do ().
232
+ Get ()
233
+ Expect (err ).NotTo (HaveOccurred ())
234
+
235
+ _ , err = kubeClient .Get ().
236
+ Namespace ("default" ).
237
+ Resource ("deployments" ).
238
+ VersionedParams (& metav1.ListOptions {}, scheme .ParameterCodec ).
239
+ Do ().
240
+ Get ()
241
+ Expect (err ).NotTo (HaveOccurred ())
242
+
243
+ _ , err = kubeClient .Get ().
244
+ Namespace ("default" ).
245
+ Resource ("replicasets" ).
246
+ VersionedParams (& metav1.ListOptions {}, scheme .ParameterCodec ).
247
+ Do ().
248
+ Get ()
249
+ Expect (err ).NotTo (HaveOccurred ())
250
+
251
+ _ , err = kubeClient .Get ().
252
+ Namespace ("default" ).
253
+ Resource ("statefulsets" ).
254
+ VersionedParams (& metav1.ListOptions {}, scheme .ParameterCodec ).
255
+ Do ().
256
+ Get ()
257
+ Expect (err ).NotTo (HaveOccurred ())
258
+
259
+ // check horizontalpodautoscalers
260
+ c .ContentConfig .GroupVersion = & schema.GroupVersion {Group : "autoscaling" , Version : "v1" }
261
+ kubeClient , err = rest .RESTClientFor (c )
262
+ Expect (err ).NotTo (HaveOccurred ())
263
+
264
+ _ , err = kubeClient .Get ().
265
+ Namespace ("default" ).
266
+ Resource ("horizontalpodautoscalers" ).
267
+ VersionedParams (& metav1.ListOptions {}, scheme .ParameterCodec ).
268
+ Do ().
269
+ Get ()
270
+ Expect (err ).NotTo (HaveOccurred ())
271
+
272
+ // check jobs
273
+ c .ContentConfig .GroupVersion = & schema.GroupVersion {Group : "batch" , Version : "v1" }
274
+ kubeClient , err = rest .RESTClientFor (c )
275
+ Expect (err ).NotTo (HaveOccurred ())
276
+
277
+ _ , err = kubeClient .Get ().
278
+ Namespace ("default" ).
279
+ Resource ("jobs" ).
280
+ VersionedParams (& metav1.ListOptions {}, scheme .ParameterCodec ).
281
+ Do ().
282
+ Get ()
283
+ Expect (err ).NotTo (HaveOccurred ())
190
284
}
0 commit comments