@@ -29,6 +29,7 @@ import (
2929 "os"
3030 "os/exec"
3131 "path/filepath"
32+ "runtime"
3233 "strconv"
3334 "strings"
3435 "time"
@@ -40,6 +41,8 @@ import (
4041 "sigs.k8s.io/boskos/client"
4142 "sigs.k8s.io/kubetest2/pkg/artifacts"
4243 "sigs.k8s.io/kubetest2/pkg/boskos"
44+ ktexec "sigs.k8s.io/kubetest2/pkg/exec"
45+ "sigs.k8s.io/kubetest2/pkg/fs"
4346 "sigs.k8s.io/kubetest2/pkg/types"
4447)
4548
@@ -524,7 +527,7 @@ func (d *deployer) Down() error {
524527 if err := d .DumpClusterLogs (); err != nil {
525528 klog .Warningf ("Dumping cluster logs at the begin of Down() failed: %s" , err )
526529 }
527-
530+
528531 instName , fwRuleName , nwName := d .instanceName (), d .firewallRuleName (), d .networkName ()
529532 gcloudCmds := [][]string {
530533 {"--quiet" , "compute" , "instances" , "delete" , "--zone=" + d .GCPZone , instName },
@@ -579,36 +582,42 @@ func (d *deployer) DumpClusterLogs() error {
579582 return nil
580583}
581584
582- func (d * deployer ) Build () error {
583- ctx := context .TODO ()
584- runDir := d .commonOptions .RunDir ()
585+ // buildE2ERequirements was taken from https://github.com/kubernetes-sigs/kubetest2/pull/275
586+ func (d * deployer ) buildE2ERequirements () error {
587+ const target = "all"
588+ klog .V (0 ).Infof ("Build(): build e2e requirements...\n " )
589+ e2ePath := "test/e2e/e2e.test"
590+ kubectlPath := "cmd/kubectl"
591+ ginkgoPath := "vendor/github.com/onsi/ginkgo/v2/ginkgo"
592+
593+ // make sure we have e2e requirements
594+ cmd := ktexec .Command ("make" , target ,
595+ fmt .Sprintf ("WHAT=%s %s %s" , kubectlPath , e2ePath , ginkgoPath ))
596+ cmd .SetDir (d .KubeRoot )
597+ ktexec .InheritOutput (cmd )
598+ if err := cmd .Run (); err != nil {
599+ return err
600+ }
585601
586- // Prepare `runDir/{e2e.test, ginkgo}`
587- for _ , f := range []string {"e2e.test" , "ginkgo" , "kubectl" } {
588- src := filepath .Join (d .KubeRoot , "_output" , "bin" , f )
589- if _ , err := os .Stat (src ); err != nil {
590- if ! errors .Is (err , os .ErrNotExist ) {
591- return err
592- }
593- switch f {
594- case "e2e.test" :
595- klog .Warning (fmt .Errorf ("%w (Hint: `make WHAT=test/e2e/e2e.test -C $(go env GOPATH)/src/k8s.io/kubernetes`)" , err ))
596- continue
597- case "ginkgo" :
598- klog .Warning (fmt .Errorf ("%w (Hint: `make ginkgo -C $(go env GOPATH)/src/k8s.io/kubernetes`)" , err ))
599- continue
600- default :
601- klog .Warning (err )
602- continue
603- }
604- }
605- dst := filepath .Join (runDir , f )
606- cmd := exec .CommandContext (ctx , "cp" , "-af" , src , dst )
607- if err := execCmd (cmd ); err != nil {
608- return err
602+ //move files
603+ const dockerizedOutput = "_output/dockerized"
604+ for _ , binary := range commonTestBinaries {
605+ source := filepath .Join (d .KubeRoot , "_output/bin" , binary )
606+ dest := filepath .Join (d .KubeRoot , dockerizedOutput , "bin" , runtime .GOOS , runtime .GOARCH , binary )
607+ if err := fs .CopyFile (source , dest ); err != nil {
608+ klog .Warningf ("failed to copy %s to %s: %v" , source , dest , err )
609609 }
610610 }
611611
612+ storeCommonBinaries (d .KubeRoot , d .commonOptions .RunDir ())
613+ return nil
614+ }
615+
616+ func (d * deployer ) Build () error {
617+ ctx := context .TODO ()
618+ if err := d .buildE2ERequirements (); err != nil {
619+ return fmt .Errorf ("failed to build e2e requirements: %w" , err )
620+ }
612621 isUp , err := d .IsUp ()
613622 if err != nil {
614623 return err
@@ -689,3 +698,30 @@ func bindFlags(d *deployer) *pflag.FlagSet {
689698
690699 return flags
691700}
701+
702+ // commonTestBinaries is from https://github.com/kubernetes-sigs/kubetest2/blob/1ad71e1e364e6a6e75b102194eaed191fbae630c/pkg/build/build.go#L76-L82
703+ var commonTestBinaries = []string {
704+ "kubectl" ,
705+ "e2e.test" ,
706+ "ginkgo" ,
707+ }
708+
709+ // storeCommonBinaries will best effort try to store commonly built binaries
710+ // to the output directory.
711+ // From https://github.com/kubernetes-sigs/kubetest2/blob/1ad71e1e364e6a6e75b102194eaed191fbae630c/pkg/build/build.go#L84-L101
712+ func storeCommonBinaries (kuberoot string , outroot string ) {
713+ const dockerizedOutput = "_output/dockerized"
714+ root := filepath .Join (kuberoot , dockerizedOutput , "bin" , runtime .GOOS , runtime .GOARCH )
715+ for _ , binary := range commonTestBinaries {
716+ source := filepath .Join (root , binary )
717+ dest := filepath .Join (outroot , binary )
718+ if _ , err := os .Stat (source ); err == nil {
719+ klog .V (2 ).Infof ("copying %s to %s ..." , source , dest )
720+ if err := fs .CopyFile (source , dest ); err != nil {
721+ klog .Warningf ("failed to copy %s to %s: %v" , source , dest , err )
722+ }
723+ } else {
724+ klog .Warningf ("could not find %s: %v" , source , err )
725+ }
726+ }
727+ }
0 commit comments