From 7101d1bf7b5abc72d308ed01225c3b913a855298 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 12 Jan 2024 23:57:30 -0500 Subject: [PATCH] fix: close the file before attempting to write it Also remove the unnecessary sleep call --- plugins/scheduler-k3s/subcommands.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/plugins/scheduler-k3s/subcommands.go b/plugins/scheduler-k3s/subcommands.go index ec1b5f7c1..5baa7c511 100644 --- a/plugins/scheduler-k3s/subcommands.go +++ b/plugins/scheduler-k3s/subcommands.go @@ -31,6 +31,10 @@ func CommandInitialize() error { } defer os.Remove(f.Name()) + if err := f.Close(); err != nil { + return fmt.Errorf("Unable to close k3s installer file: %w", err) + } + err = common.WriteSliceToFile(common.WriteSliceToFileInput{ Filename: f.Name(), Lines: strings.Split(resp.String(), "\n"), @@ -40,10 +44,6 @@ func CommandInitialize() error { return fmt.Errorf("Unable to write k3s installer to file: %w", err) } - if err := f.Close(); err != nil { - return fmt.Errorf("Unable to close k3s installer file: %w", err) - } - fi, err := os.Stat(f.Name()) if err != nil { return fmt.Errorf("Unable to get k3s installer file size: %w", err) @@ -53,8 +53,6 @@ func CommandInitialize() error { return fmt.Errorf("Invalid k3s installer filesize") } - time.Sleep(1 * time.Second) - // todo: allow this to be passed as an option or environment variable token := "password" if err := CommandSet("--global", "token", token); err != nil {