@@ -18,6 +18,7 @@ import (
1818 "github.com/k0sproject/rig/exec"
1919 "github.com/k0sproject/rig/os"
2020 "github.com/k0sproject/rig/os/registry"
21+ "github.com/k0sproject/version"
2122 log "github.com/sirupsen/logrus"
2223)
2324
@@ -83,6 +84,7 @@ type configurer interface {
8384 Arch (os.Host ) (string , error )
8485 K0sCmdf (string , ... interface {}) string
8586 K0sBinaryPath () string
87+ K0sBinaryVersion (os.Host ) (* version.Version , error )
8688 K0sConfigPath () string
8789 K0sJoinTokenPath () string
8890 WriteFile (os.Host , string , string , string ) error
@@ -93,7 +95,7 @@ type configurer interface {
9395 ReadFile (os.Host , string ) (string , error )
9496 FileExist (os.Host , string ) bool
9597 Chmod (os.Host , string , string , ... exec.Option ) error
96- DownloadK0s (os.Host , string , string ) error
98+ DownloadK0s (os.Host , * version. Version , string ) error
9799 DownloadURL (os.Host , string , string , ... exec.Option ) error
98100 InstallPackage (os.Host , ... string ) error
99101 FileContains (os.Host , string , string ) bool
@@ -296,7 +298,7 @@ func (h *Host) K0sServiceName() string {
296298}
297299
298300// UpdateK0sBinary updates the binary on the host either by downloading or uploading, based on the config
299- func (h * Host ) UpdateK0sBinary (version string ) error {
301+ func (h * Host ) UpdateK0sBinary (version * version. Version ) error {
300302 if h .UploadBinaryPath != "" {
301303 if err := h .Upload (h .UploadBinaryPath , h .Configurer .K0sBinaryPath (), exec .Sudo (h )); err != nil {
302304 return err
@@ -308,17 +310,18 @@ func (h *Host) UpdateK0sBinary(version string) error {
308310 if err := h .Configurer .DownloadK0s (h , version , h .Metadata .Arch ); err != nil {
309311 return err
310312 }
313+ }
311314
312- output , err := h .ExecOutput (h .Configurer .K0sCmdf ("version" ), exec .Sudo (h ))
313- if err != nil {
314- return fmt .Errorf ("downloaded k0s binary is invalid: %s" , err .Error ())
315- }
316- output = strings .TrimPrefix (output , "v" )
317- if output != version {
318- return fmt .Errorf ("downloaded k0s binary version is %s not %s" , output , version )
319- }
315+ updatedVersion , err := h .Configurer .K0sBinaryVersion (h )
316+ if err != nil {
317+ return fmt .Errorf ("failed to get updated k0s binary version: %w" , err )
320318 }
321- h .Metadata .K0sBinaryVersion = version
319+ if ! version .Equal (updatedVersion ) {
320+ return fmt .Errorf ("updated k0s binary version is %s not %s" , updatedVersion , version )
321+ }
322+
323+ h .Metadata .K0sBinaryVersion = version .String ()
324+
322325 return nil
323326}
324327
0 commit comments