diff --git a/internal/cloud/kubernetes.go b/internal/cloud/kubernetes.go index 40e4b6b0..612d4478 100644 --- a/internal/cloud/kubernetes.go +++ b/internal/cloud/kubernetes.go @@ -155,7 +155,7 @@ func (k8s *K8sClient) NewPod(ctx context.Context, name string, image string, nam } logWrapper("Waiting for pod to be ready") - err = wait.PollImmediate(time.Second, time.Duration(10)*time.Minute, func() (bool, error) { + err = wait.PollUntilContextTimeout(ctx, time.Second, time.Duration(10)*time.Minute, func() (bool, error) { pod, err := api.Pods(namespace).Get(context.Background(), name, meta.GetOptions{}) if err != nil { return false, err @@ -182,7 +182,7 @@ func (k8s *K8sClient) NewPod(ctx context.Context, name string, image string, nam }, nil } -func (p *Pod) Run(workDir string, cmdArgs []string) error { +func (p *Pod) Run(ctx context.Context, workDir string, cmdArgs []string) error { api := p.client.kubectl.CoreV1() if workDir != "" && workDir != p.workDir { @@ -218,7 +218,7 @@ func (p *Pod) Run(workDir string, cmdArgs []string) error { } logWrapper("Executing command %v", cmdArgs) - err = exec.Stream(remotecommand.StreamOptions{ + err = exec.StreamWithContext(ctx, remotecommand.StreamOptions{ Stdin: os.Stdin, Stdout: os.Stderr, Stderr: os.Stderr, diff --git a/internal/cloud/s3.go b/internal/cloud/s3.go index a630df43..009031f2 100644 --- a/internal/cloud/s3.go +++ b/internal/cloud/s3.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -104,7 +103,7 @@ func (a *AWSSession) UploadFile(localFile string, s3FilePath string) error { } func (a *AWSSession) UploadCompressedDirectory(localDirectoy string, s3FilePath string) error { - file, err := ioutil.TempFile("", "fyne-cross-s3") + file, err := os.CreateTemp("", "fyne-cross-s3") if err != nil { return err } @@ -255,7 +254,7 @@ func (a *AWSSession) DownloadFile(s3FilePath string, localFile string) error { } func (a *AWSSession) DownloadCompressedDirectory(s3FilePath string, localRootDirectory string) error { - file, err := ioutil.TempFile("", "fyne-cross-s3") + file, err := os.CreateTemp("", "fyne-cross-s3") if err != nil { return err } diff --git a/internal/command/command.go b/internal/command/command.go index 4559ed18..7c7116de 100644 --- a/internal/command/command.go +++ b/internal/command/command.go @@ -2,7 +2,6 @@ package command import ( "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -134,7 +133,7 @@ func prepareIcon(ctx Context, image containerImage) error { } log.Infof("[!] Default icon not found at %q", ctx.Icon) - err = ioutil.WriteFile(volume.JoinPathHost(ctx.WorkDirHost(), ctx.Icon), icon.FyneLogo, 0644) + err = os.WriteFile(volume.JoinPathHost(ctx.WorkDirHost(), ctx.Icon), icon.FyneLogo, 0644) if err != nil { return fmt.Errorf("could not create the temporary icon: %s", err) } diff --git a/internal/command/darwin_sdk_extract.go b/internal/command/darwin_sdk_extract.go index cf145464..70ded4ce 100644 --- a/internal/command/darwin_sdk_extract.go +++ b/internal/command/darwin_sdk_extract.go @@ -3,7 +3,6 @@ package command import ( "errors" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -78,7 +77,7 @@ func (cmd *DarwinSDKExtract) Run() error { } // mount the fyne-cross volume - workDir, err := ioutil.TempDir("", cmd.Name()) + workDir, err := os.MkdirTemp("", cmd.Name()) if err != nil { return err } diff --git a/internal/command/kubernetes.go b/internal/command/kubernetes.go index 594290f8..94b558d9 100644 --- a/internal/command/kubernetes.go +++ b/internal/command/kubernetes.go @@ -151,7 +151,7 @@ func (i *kubernetesContainerImage) close() error { } func (i *kubernetesContainerImage) Run(vol volume.Volume, opts options, cmdArgs []string) error { - return i.pod.Run(opts.WorkDir, cmdArgs) + return i.pod.Run(context.Background(), opts.WorkDir, cmdArgs) } func AddAWSParameters(aws *cloud.AWSSession, command string, s ...string) []string { @@ -237,7 +237,7 @@ func (i *kubernetesContainerImage) Prepare() error { download := func(vol volume.Volume, downloadPath string, containerPath string) error { log.Infof("Downloading %s to %s", downloadPath, containerPath) - return i.Run(i.runner.vol, options{}, + return i.Run(context.Background(), i.runner.vol, options{}, AddAWSParameters(i.runner.aws, "fyne-cross-s3", "download-directory", downloadPath, containerPath), ) } @@ -282,13 +282,13 @@ func (i *kubernetesContainerImage) Finalize(packageName string) (ret error) { // to compress it in a format that Darwin understand by default if strings.ToLower(filepath.Ext(packageName)) == ".app" { uploadPath += ".tar.xz" - ret = i.Run(i.runner.vol, options{}, + ret = i.Run(context.Background(), i.runner.vol, options{}, AddAWSParameters(i.runner.aws, "fyne-cross-s3", "upload-directory", volume.JoinPathContainer(i.runner.vol.TmpDirContainer(), i.ID(), packageName), uploadPath), ) } else { - ret = i.Run(i.runner.vol, options{}, + ret = i.Run(context.Background(), i.runner.vol, options{}, AddAWSParameters(i.runner.aws, "fyne-cross-s3", "upload-file", volume.JoinPathContainer(i.runner.vol.TmpDirContainer(), i.ID(), packageName), uploadPath), @@ -301,7 +301,7 @@ func (i *kubernetesContainerImage) Finalize(packageName string) (ret error) { // Upload cached data to S3 for _, mountPoint := range i.cloudLocalMount { log.Infof("Uploading %s to %s", mountPoint.inContainer, i.runner.s3Path+"/"+mountPoint.name+"-"+i.ID()+".tar.zstd") - err := i.Run(i.runner.vol, options{}, + err := i.Run(context.Background(), i.runner.vol, options{}, AddAWSParameters(i.runner.aws, "fyne-cross-s3", "upload-directory", mountPoint.inContainer, i.runner.s3Path+"/"+mountPoint.name+"-"+i.ID()+".tar.zstd"), diff --git a/internal/metadata/load.go b/internal/metadata/load.go index 25d214a0..e05a94d8 100644 --- a/internal/metadata/load.go +++ b/internal/metadata/load.go @@ -2,7 +2,6 @@ package metadata import ( "io" - "io/ioutil" "os" "path/filepath" @@ -12,7 +11,7 @@ import ( // Load attempts to read a FyneApp metadata from the provided reader. // If this cannot be done an error will be returned. func Load(r io.Reader) (*FyneApp, error) { - str, err := ioutil.ReadAll(r) + str, err := io.ReadAll(r) if err != nil { return nil, err } diff --git a/internal/volume/volume.go b/internal/volume/volume.go index 617ff410..c2461a87 100644 --- a/internal/volume/volume.go +++ b/internal/volume/volume.go @@ -7,7 +7,6 @@ import ( "archive/zip" "fmt" "io" - "io/ioutil" "os" "path" "path/filepath" @@ -31,11 +30,11 @@ const ( // Copy copies a resource from src to dest func Copy(src string, dst string) error { - data, err := ioutil.ReadFile(src) + data, err := os.ReadFile(src) if err != nil { return err } - return ioutil.WriteFile(dst, data, 0644) + return os.WriteFile(dst, data, 0644) } // DefaultCacheDirHost returns the default cache dir on the host