From 53c1b6c9ea1a1b721b4e9d4e86cab62e69774786 Mon Sep 17 00:00:00 2001 From: Dimitris Karakasilis Date: Mon, 19 May 2025 18:37:25 +0300 Subject: [PATCH] Fix wrong error message when upgrading recovery (#788) * Fix wrong error message when upgrading recovery fix command help text and simplify variables in function Fixes https://github.com/kairos-io/kairos/issues/3393 Signed-off-by: Dimitris Karakasilis * Fix test Signed-off-by: Dimitris Karakasilis --------- Signed-off-by: Dimitris Karakasilis --- main.go | 22 ++++++++++------------ pkg/constants/constants.go | 3 ++- pkg/types/v1/config.go | 2 +- pkg/types/v1/config_test.go | 5 +++-- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/main.go b/main.go index 1401d1c..34dd97f 100644 --- a/main.go +++ b/main.go @@ -75,12 +75,13 @@ var cmds = []*cli.Command{ &cli.BoolFlag{Name: "recovery", Usage: "Upgrade recovery"}, }, Description: ` -Manually upgrade a kairos node Active image. Does not upgrade passive or recovery images. +Manually upgrade a kairos node Active image. Does not upgrade the passive image. It upgrades the recovery image when the --recovery flag is passed. -With no arguments, it defaults to latest available release. To specify a version, pass it as argument using the --source flag. -Passing just the Kairos version as the first argument is no longer supported. If you speficy a positional argument, it will be treated +To specify a version, pass it as argument using the --source flag. Passing just the Kairos version as the first argument is no longer supported. If you speficy a positional argument, it will be treated as a value for the --source flag. +You can also specify the upgrade image by setting "upgrade.system.uri" for the active image or "upgrade.recovery-system.uri" for the recovery image, in the cloud config. + To retrieve all the available versions, use "kairos upgrade list-releases" $ kairos upgrade list-releases @@ -167,24 +168,21 @@ See https://kairos.io/docs/upgrade/manual/ for documentation. return checkRoot() }, Action: func(c *cli.Context) error { - var v string var source string if c.Args().Len() == 1 { - v = c.Args().First() fmt.Println("Warning: Passing a version as a positional argument is deprecated. Use --source flag instead.") fmt.Println("The value will be used as a value for the --source flag") + source = c.Args().First() + } + + if v := c.String("source"); v != "" { source = v } - image := c.String("image") - if v := c.String("source"); v != "" { - source = c.String("source") - } - - if image != "" { + if v := c.String("image"); v != "" { fmt.Println("--image flag is deprecated, please use --source") // override source with image for now until we drop it - source = fmt.Sprintf("oci:%s", image) + source = fmt.Sprintf("oci:%s", v) } if c.Bool("recovery") && c.String("boot-entry") != "" { diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 0a3be46..b2f5340 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -126,7 +126,8 @@ const ( StateResetBootSuffix = " state reset (auto)" // Error - UpgradeNoSourceError = "Could not find a proper source for the upgrade.\nThis can be configured in the cloud config files under the 'upgrade.system.uri' key or via cmdline using the '--source' flag." + UpgradeNoSourceError = "could not find a proper source for the upgrade.\nThis can be configured in the cloud config files under the 'upgrade.system.uri' key or via cmdline using the '--source' flag" + UpgradeRecoveryNoSourceError = "could not find a proper source for the recovery upgrade.\nThis can be configured in the cloud config files under the 'upgrade.recovery-system.uri' key or via cmdline using the '--source' flag" MultipleEntriesAssessmentError = "multiple boot entries found for %s" NoBootAssessmentWarning = "No boot assessment found in current boot entry config file" ) diff --git a/pkg/types/v1/config.go b/pkg/types/v1/config.go index a393fa4..bd8551d 100644 --- a/pkg/types/v1/config.go +++ b/pkg/types/v1/config.go @@ -190,7 +190,7 @@ func (u *UpgradeSpec) RecoveryUpgrade() bool { func (u *UpgradeSpec) Sanitize() error { if u.RecoveryUpgrade() { if u.Recovery.Source.IsEmpty() { - return fmt.Errorf(constants.UpgradeNoSourceError) + return fmt.Errorf(constants.UpgradeRecoveryNoSourceError) } if u.Partitions.Recovery == nil || u.Partitions.Recovery.MountPoint == "" { return fmt.Errorf("undefined recovery partition") diff --git a/pkg/types/v1/config_test.go b/pkg/types/v1/config_test.go index 05bba2d..27bcd19 100644 --- a/pkg/types/v1/config_test.go +++ b/pkg/types/v1/config_test.go @@ -17,9 +17,10 @@ limitations under the License. package v1_test import ( - sdkTypes "github.com/kairos-io/kairos-sdk/types" "path/filepath" + sdkTypes "github.com/kairos-io/kairos-sdk/types" + "github.com/kairos-io/kairos-agent/v2/pkg/constants" v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1" . "github.com/onsi/ginkgo/v2" @@ -451,7 +452,7 @@ var _ = Describe("Types", Label("types", "config"), func() { It("fails with empty source", func() { err := spec.Sanitize() Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring(constants.UpgradeNoSourceError)) + Expect(err.Error()).To(ContainSubstring(constants.UpgradeRecoveryNoSourceError)) }) It("fails with missing recovery partition", func() { spec.Recovery.Source = v1.NewFileSrc("/tmp")