@@ -18,12 +18,7 @@ package windows
18
18
19
19
import (
20
20
"context"
21
- "crypto/tls"
22
- "encoding/json"
23
21
"fmt"
24
- "io/ioutil"
25
- "net/http"
26
- "regexp"
27
22
"strconv"
28
23
"time"
29
24
@@ -32,11 +27,8 @@ import (
32
27
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
33
28
"k8s.io/apimachinery/pkg/labels"
34
29
"k8s.io/apimachinery/pkg/util/uuid"
35
- "k8s.io/client-go/kubernetes/scheme"
36
- kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
37
- kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
38
30
"k8s.io/kubernetes/test/e2e/framework"
39
- e2ekubectl "k8s.io/kubernetes/test/e2e/framework/kubectl "
31
+ e2ekubelet "k8s.io/kubernetes/test/e2e/framework/kubelet "
40
32
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
41
33
imageutils "k8s.io/kubernetes/test/utils/image"
42
34
@@ -197,7 +189,7 @@ func getNodeMemory(f *framework.Framework) nodeMemory {
197
189
198
190
nodeName := nodeList .Items [0 ].ObjectMeta .Name
199
191
200
- kubeletConfig , err := getCurrentKubeletConfig (nodeName , f .Namespace .Name )
192
+ kubeletConfig , err := e2ekubelet . GetCurrentKubeletConfig (nodeName , f .Namespace .Name , true )
201
193
framework .ExpectNoError (err )
202
194
203
195
systemReserve , err := resource .ParseQuantity (kubeletConfig .SystemReserved ["memory" ])
@@ -250,91 +242,3 @@ func getTotalAllocatableMemory(f *framework.Framework) *resource.Quantity {
250
242
251
243
return totalAllocatable
252
244
}
253
-
254
- // getCurrentKubeletConfig modified from test/e2e_node/util.go
255
- func getCurrentKubeletConfig (nodeName , namespace string ) (* kubeletconfig.KubeletConfiguration , error ) {
256
-
257
- resp := pollConfigz (5 * time .Minute , 5 * time .Second , nodeName , namespace )
258
- kubeCfg , err := decodeConfigz (resp )
259
- if err != nil {
260
- return nil , err
261
- }
262
- return kubeCfg , nil
263
- }
264
-
265
- // Causes the test to fail, or returns a status 200 response from the /configz endpoint
266
- func pollConfigz (timeout time.Duration , pollInterval time.Duration , nodeName , namespace string ) * http.Response {
267
- // start local proxy, so we can send graceful deletion over query string, rather than body parameter
268
- ginkgo .By ("Opening proxy to cluster" )
269
- tk := e2ekubectl .NewTestKubeconfig (framework .TestContext .CertDir , framework .TestContext .Host , framework .TestContext .KubeConfig , framework .TestContext .KubeContext , framework .TestContext .KubectlPath , namespace )
270
- cmd := tk .KubectlCmd ("proxy" , "-p" , "0" )
271
- stdout , stderr , err := framework .StartCmdAndStreamOutput (cmd )
272
- framework .ExpectNoError (err )
273
- defer stdout .Close ()
274
- defer stderr .Close ()
275
- defer framework .TryKill (cmd )
276
- buf := make ([]byte , 128 )
277
- var n int
278
- n , err = stdout .Read (buf )
279
- framework .ExpectNoError (err )
280
- output := string (buf [:n ])
281
- proxyRegexp := regexp .MustCompile ("Starting to serve on 127.0.0.1:([0-9]+)" )
282
- match := proxyRegexp .FindStringSubmatch (output )
283
- framework .ExpectEqual (len (match ), 2 )
284
- port , err := strconv .Atoi (match [1 ])
285
- framework .ExpectNoError (err )
286
- ginkgo .By ("http requesting node kubelet /configz" )
287
- endpoint := fmt .Sprintf ("http://127.0.0.1:%d/api/v1/nodes/%s/proxy/configz" , port , nodeName )
288
- tr := & http.Transport {
289
- TLSClientConfig : & tls.Config {InsecureSkipVerify : true },
290
- }
291
- client := & http.Client {Transport : tr }
292
- req , err := http .NewRequest ("GET" , endpoint , nil )
293
- framework .ExpectNoError (err )
294
- req .Header .Add ("Accept" , "application/json" )
295
-
296
- var resp * http.Response
297
- gomega .Eventually (func () bool {
298
- resp , err = client .Do (req )
299
- if err != nil {
300
- framework .Logf ("Failed to get /configz, retrying. Error: %v" , err )
301
- return false
302
- }
303
- if resp .StatusCode != 200 {
304
- framework .Logf ("/configz response status not 200, retrying. Response was: %+v" , resp )
305
- return false
306
- }
307
-
308
- return true
309
- }, timeout , pollInterval ).Should (gomega .Equal (true ))
310
- return resp
311
- }
312
-
313
- // Decodes the http response from /configz and returns a kubeletconfig.KubeletConfiguration (internal type).
314
- func decodeConfigz (resp * http.Response ) (* kubeletconfig.KubeletConfiguration , error ) {
315
- // This hack because /configz reports the following structure:
316
- // {"kubeletconfig": {the JSON representation of kubeletconfigv1beta1.KubeletConfiguration}}
317
- type configzWrapper struct {
318
- ComponentConfig kubeletconfigv1beta1.KubeletConfiguration `json:"kubeletconfig"`
319
- }
320
-
321
- configz := configzWrapper {}
322
- kubeCfg := kubeletconfig.KubeletConfiguration {}
323
-
324
- contentsBytes , err := ioutil .ReadAll (resp .Body )
325
- if err != nil {
326
- return nil , err
327
- }
328
-
329
- err = json .Unmarshal (contentsBytes , & configz )
330
- if err != nil {
331
- return nil , err
332
- }
333
-
334
- err = scheme .Scheme .Convert (& configz .ComponentConfig , & kubeCfg , nil )
335
- if err != nil {
336
- return nil , err
337
- }
338
-
339
- return & kubeCfg , nil
340
- }
0 commit comments