@@ -108,6 +108,36 @@ func (info *OrchestratorAndRegistryInfo) Download(filename string, url string) e
108108 return err
109109}
110110
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+
111141func (info * OrchestratorAndRegistryInfo ) ExtractBinaryFromArchive (binary string , archive string , archiveFilename string ) error {
112142 f , err := os .Open (archive )
113143 if err != nil {
@@ -116,33 +146,7 @@ func (info *OrchestratorAndRegistryInfo) ExtractBinaryFromArchive(binary string,
116146 defer f .Close ()
117147
118148 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 )
146150 }
147151
148152 var fileReader io.ReadCloser = f
@@ -171,7 +175,10 @@ func (info *OrchestratorAndRegistryInfo) ExtractBinaryFromArchive(binary string,
171175 if err != nil {
172176 return err
173177 }
174- io .Copy (writer , tarReader )
178+ _ , err = io .Copy (writer , tarReader )
179+ if err != nil {
180+ return err
181+ }
175182 err = os .Chmod (binary , os .FileMode (file .Mode ))
176183 if err != nil {
177184 return err
@@ -297,8 +304,8 @@ func runWithKindAndRegistry(t *testing.T, todo func(OrchestratorAndRegistryInfo)
297304 err := runner .Download (kind , fmt .Sprintf (`https://github.com/kubernetes-sigs/kind/releases/download/v0.6.0/kind-%s-amd64` , runtime .GOOS ))
298305 assert .NilError (t , err )
299306 // 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 )
302309 //get hosts's ip address
303310 ipaddress , err := getHostIPAddress ()
304311 assert .NilError (t , err )
@@ -322,15 +329,16 @@ containerdConfigPatches:
322329 runner .configuredCmd .Env = append (runner .configuredCmd .Env , "KUBECONFIG=" + runner .tmpDir .Join ("kube.conf" ))
323330 runner .orchestratorName = "kindcluster-control-plane"
324331 // 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 )
328336 time .Sleep (time .Second * 60 )
329337
330338 output := runner .localCmd (kubectl , `create` , `namespace` , `compose` )
331339 checkContains (t , output , []string {`namespace/compose created` })
332340
333- // wait untill all containers are in running state
341+ // wait until all containers are in running state
334342 waitReady := func () {
335343 areRunning := func (s []string ) bool {
336344 if len (s ) == 0 {
@@ -348,7 +356,7 @@ containerdConfigPatches:
348356 }
349357 err := wait .Poll (time .Second * 2 , time .Second * 240 , func () (bool , error ) {
350358 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` ), ` ` )
352360 return areRunning (containerStatus ), nil
353361 })
354362 assert .NilError (t , err )
@@ -361,10 +369,13 @@ containerdConfigPatches:
361369 checkContains (t , output , []string {`clusterrolebinding.rbac.authorization.k8s.io/tiller created` })
362370 waitReady ()
363371 // 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` )
368379 time .Sleep (time .Second * 30 )
369380 waitReady ()
370381
@@ -386,23 +397,26 @@ containerdConfigPatches:
386397 // download compose-on-kube binary
387398 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 ))
388399 assert .NilError (t , err )
389- os .Chmod (conk , os .FileMode (0111 ))
400+ err = os .Chmod (conk , os .FileMode (0111 ))
401+ assert .NilError (t , err )
390402 // Install Compose on Kube
391403 output = runner .localCmd (conk , `-namespace=compose` , `-etcd-servers=http://compose-etcd-client:2379` )
392404 checkContains (t , output , []string {`Controller: image: ` })
393405 time .Sleep (time .Second * 5 )
394406 waitReady ()
395407
396408 // 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" )))
398411 runner .configuredCmd .Env = append (runner .configuredCmd .Env , "DOCKER_CONTEXT=kind-context" , "DOCKER_INSTALLER_CONTEXT=kind-context" )
399412
400413 cleanAll := func () {
401- runner .localCmd ( kind , `delete ` , `cluster` )
414+ runner .dockerCmd ( `rm` , `--force ` , `--volumes` , runner . orchestratorName )
402415 runner .cleanup ()
403416 }
404417 defer cleanAll ()
405418 todo (* runner )
419+
406420}
407421
408422func build (t * testing.T , cmd icmd.Cmd , dockerCli dockerCliCommand , ref , path string ) {
0 commit comments