@@ -108,6 +108,36 @@ func (info *OrchestratorAndRegistryInfo) Download(filename string, url string) e
108
108
return err
109
109
}
110
110
111
+ func extractZIP (archive string , binary string , filename string ) error {
112
+ zipReader , err := zip .OpenReader (archive )
113
+ if err != nil {
114
+ return err
115
+ }
116
+ for _ , file := range zipReader .Reader .File {
117
+ if filename == file .Name {
118
+ zippedFile , err := file .Open ()
119
+ if err != nil {
120
+ return err
121
+ }
122
+ defer zippedFile .Close ()
123
+ binaryFile , err := os .OpenFile (
124
+ binary ,
125
+ os .O_WRONLY | os .O_CREATE | os .O_TRUNC ,
126
+ file .Mode (),
127
+ )
128
+ if err != nil {
129
+ return err
130
+ }
131
+ defer binaryFile .Close ()
132
+ _ , err = io .Copy (binaryFile , zippedFile )
133
+ if err != nil {
134
+ return err
135
+ }
136
+ }
137
+ }
138
+ return nil
139
+ }
140
+
111
141
func (info * OrchestratorAndRegistryInfo ) ExtractBinaryFromArchive (binary string , archive string , archiveFilename string ) error {
112
142
f , err := os .Open (archive )
113
143
if err != nil {
@@ -116,33 +146,7 @@ func (info *OrchestratorAndRegistryInfo) ExtractBinaryFromArchive(binary string,
116
146
defer f .Close ()
117
147
118
148
if strings .HasSuffix (archive , ".zip" ) {
119
- zipReader , err := zip .OpenReader (archive )
120
- if err != nil {
121
- return err
122
- }
123
- for _ , file := range zipReader .Reader .File {
124
- if archiveFilename == file .Name {
125
- zippedFile , err := file .Open ()
126
- if err != nil {
127
- return err
128
- }
129
- defer zippedFile .Close ()
130
- binaryFile , err := os .OpenFile (
131
- binary ,
132
- os .O_WRONLY | os .O_CREATE | os .O_TRUNC ,
133
- file .Mode (),
134
- )
135
- if err != nil {
136
- return err
137
- }
138
- defer binaryFile .Close ()
139
- _ , err = io .Copy (binaryFile , zippedFile )
140
- if err != nil {
141
- return err
142
- }
143
- }
144
- }
145
- return nil
149
+ return extractZIP (archive , binary , archiveFilename )
146
150
}
147
151
148
152
var fileReader io.ReadCloser = f
@@ -171,7 +175,10 @@ func (info *OrchestratorAndRegistryInfo) ExtractBinaryFromArchive(binary string,
171
175
if err != nil {
172
176
return err
173
177
}
174
- io .Copy (writer , tarReader )
178
+ _ , err = io .Copy (writer , tarReader )
179
+ if err != nil {
180
+ return err
181
+ }
175
182
err = os .Chmod (binary , os .FileMode (file .Mode ))
176
183
if err != nil {
177
184
return err
@@ -297,8 +304,8 @@ func runWithKindAndRegistry(t *testing.T, todo func(OrchestratorAndRegistryInfo)
297
304
err := runner .Download (kind , fmt .Sprintf (`https://github.com/kubernetes-sigs/kind/releases/download/v0.6.0/kind-%s-amd64` , runtime .GOOS ))
298
305
assert .NilError (t , err )
299
306
// make kind binary executable
300
- os .Chmod (kind , os .FileMode (0111 ))
301
-
307
+ err = os .Chmod (kind , os .FileMode (0111 ))
308
+ assert . NilError ( t , err )
302
309
//get hosts's ip address
303
310
ipaddress , err := getHostIPAddress ()
304
311
assert .NilError (t , err )
@@ -322,15 +329,16 @@ containerdConfigPatches:
322
329
runner .configuredCmd .Env = append (runner .configuredCmd .Env , "KUBECONFIG=" + runner .tmpDir .Join ("kube.conf" ))
323
330
runner .orchestratorName = "kindcluster-control-plane"
324
331
// download and install kubectl, helm and compose-on-kubernetes
325
- runner .Download (kubectl , fmt .Sprintf (`https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/%s/amd64/kubectl%s` , runtime .GOOS , extension ))
326
- os .Chmod (kubectl , os .FileMode (0111 ))
327
-
332
+ err = runner .Download (kubectl , fmt .Sprintf (`https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/%s/amd64/kubectl%s` , runtime .GOOS , extension ))
333
+ assert .NilError (t , err )
334
+ err = os .Chmod (kubectl , os .FileMode (0111 ))
335
+ assert .NilError (t , err )
328
336
time .Sleep (time .Second * 60 )
329
337
330
338
output := runner .localCmd (kubectl , `create` , `namespace` , `compose` )
331
339
checkContains (t , output , []string {`namespace/compose created` })
332
340
333
- // wait untill all containers are in running state
341
+ // wait until all containers are in running state
334
342
waitReady := func () {
335
343
areRunning := func (s []string ) bool {
336
344
if len (s ) == 0 {
@@ -348,7 +356,7 @@ containerdConfigPatches:
348
356
}
349
357
err := wait .Poll (time .Second * 2 , time .Second * 240 , func () (bool , error ) {
350
358
output := runner .localCmd (kubectl , `get` , `pods` , `-o=jsonpath={.items[*].status.phase}` , `--all-namespaces` )
351
- containerStatus := strings .Split (strings .Trim (output , ` \r \n` ), ` ` )
359
+ containerStatus := strings .Split (strings .Trim (output , `\n` ), ` ` )
352
360
return areRunning (containerStatus ), nil
353
361
})
354
362
assert .NilError (t , err )
@@ -361,10 +369,13 @@ containerdConfigPatches:
361
369
checkContains (t , output , []string {`clusterrolebinding.rbac.authorization.k8s.io/tiller created` })
362
370
waitReady ()
363
371
// download and install helm
364
- runner .Download (runner .tmpDir .Join ("helm" + archive ), fmt .Sprintf (`https://get.helm.sh/helm-v2.16.1-%s-amd64%s` , runtime .GOOS , archive ))
365
- runner .ExtractBinaryFromArchive (helm , runner .tmpDir .Join ("helm" + archive ), fmt .Sprintf ("%s-amd64/helm%s" , runtime .GOOS , extension ))
366
- os .Chmod (helm , os .FileMode (0111 ))
367
- output = runner .localCmd (helm , `init` , `--service-account` , `tiller` )
372
+ err = runner .Download (runner .tmpDir .Join ("helm" + archive ), fmt .Sprintf (`https://get.helm.sh/helm-v2.16.1-%s-amd64%s` , runtime .GOOS , archive ))
373
+ assert .NilError (t , err )
374
+ err = runner .ExtractBinaryFromArchive (helm , runner .tmpDir .Join ("helm" + archive ), fmt .Sprintf ("%s-amd64/helm%s" , runtime .GOOS , extension ))
375
+ assert .NilError (t , err )
376
+ err = os .Chmod (helm , os .FileMode (0111 ))
377
+ assert .NilError (t , err )
378
+ runner .localCmd (helm , `init` , `--service-account` , `tiller` )
368
379
time .Sleep (time .Second * 30 )
369
380
waitReady ()
370
381
@@ -386,23 +397,26 @@ containerdConfigPatches:
386
397
// download compose-on-kube binary
387
398
err = runner .Download (conk , fmt .Sprintf (`https://github.com/docker/compose-on-kubernetes/releases/download/v0.5.0-alpha1/installer-%s%s` , runtime .GOOS , extension ))
388
399
assert .NilError (t , err )
389
- os .Chmod (conk , os .FileMode (0111 ))
400
+ err = os .Chmod (conk , os .FileMode (0111 ))
401
+ assert .NilError (t , err )
390
402
// Install Compose on Kube
391
403
output = runner .localCmd (conk , `-namespace=compose` , `-etcd-servers=http://compose-etcd-client:2379` )
392
404
checkContains (t , output , []string {`Controller: image: ` })
393
405
time .Sleep (time .Second * 5 )
394
406
waitReady ()
395
407
396
408
// setup docker context
397
- runner .dockerCmd ("context" , "create" , "kind-context" , "--docker" , `"host=unix:///var/run/docker.sock"` , "--default-stack-orchestrator" , "kubernetes" , "--kubernetes" , fmt .Sprintf (`"config-file=%s"` , runner .tmpDir .Join ("kube.conf" )))
409
+ runner .dockerCmd (`context` , `create` , `kind-context` , `--docker` , `"host=unix:///var/run/docker.sock"` , `--default-stack-orchestrator` ,
410
+ `kubernetes` , `--kubernetes` , fmt .Sprintf (`"config-file=%s"` , runner .tmpDir .Join ("kube.conf" )))
398
411
runner .configuredCmd .Env = append (runner .configuredCmd .Env , "DOCKER_CONTEXT=kind-context" , "DOCKER_INSTALLER_CONTEXT=kind-context" )
399
412
400
413
cleanAll := func () {
401
- runner .localCmd ( kind , `delete ` , `cluster` )
414
+ runner .dockerCmd ( `rm` , `--force ` , `--volumes` , runner . orchestratorName )
402
415
runner .cleanup ()
403
416
}
404
417
defer cleanAll ()
405
418
todo (* runner )
419
+
406
420
}
407
421
408
422
func build (t * testing.T , cmd icmd.Cmd , dockerCli dockerCliCommand , ref , path string ) {
0 commit comments