diff --git a/cmd/upgrade/executor/resource.go b/cmd/upgrade/executor/resource.go index 5908986b..d181ee3a 100644 --- a/cmd/upgrade/executor/resource.go +++ b/cmd/upgrade/executor/resource.go @@ -76,37 +76,38 @@ func NewUpgradeResourceJob() *cobra.Command { util.CheckErr(options.InitializeDefaults(cmd), util.Fatal) err := options.RunResourceUpgrade(cmd) if err != nil { - utaskObj, err := client.OpenebsV1alpha1().UpgradeTasks(openebsNamespace). + utaskObj, uerr := client.OpenebsV1alpha1().UpgradeTasks(openebsNamespace). Get(cr.Name, metav1.GetOptions{}) - if err != nil { - util.Fatal(err.Error()) + if uerr != nil { + util.Fatal(uerr.Error()) } - backoffLimit, err := getBackoffLimit(openebsNamespace) - if err != nil { - util.Fatal(err.Error()) + backoffLimit, uerr := getBackoffLimit(openebsNamespace) + if uerr != nil { + util.Fatal(uerr.Error()) } utaskObj.Status.Retries = utaskObj.Status.Retries + 1 if utaskObj.Status.Retries == backoffLimit { utaskObj.Status.Phase = v1Alpha1API.UpgradeError utaskObj.Status.CompletedTime = metav1.Now() } - _, err = client.OpenebsV1alpha1().UpgradeTasks(openebsNamespace). + _, uerr = client.OpenebsV1alpha1().UpgradeTasks(openebsNamespace). Update(utaskObj) - if err != nil { - util.Fatal(err.Error()) + if uerr != nil { + util.Fatal(uerr.Error()) } + util.Fatal(err.Error()) } else { - utaskObj, err := client.OpenebsV1alpha1().UpgradeTasks(openebsNamespace). + utaskObj, uerr := client.OpenebsV1alpha1().UpgradeTasks(openebsNamespace). Get(cr.Name, metav1.GetOptions{}) - if err != nil { - util.Fatal(err.Error()) + if uerr != nil { + util.Fatal(uerr.Error()) } utaskObj.Status.Phase = v1Alpha1API.UpgradeSuccess utaskObj.Status.CompletedTime = metav1.Now() - _, err = client.OpenebsV1alpha1().UpgradeTasks(openebsNamespace). + _, uerr = client.OpenebsV1alpha1().UpgradeTasks(openebsNamespace). Update(utaskObj) - if err != nil { - util.Fatal(err.Error()) + if uerr != nil { + util.Fatal(uerr.Error()) } } } @@ -167,7 +168,7 @@ func (u *UpgradeOptions) RunResourceUpgradeChecks(cmd *cobra.Command) error { // RunResourceUpgrade upgrades the given upgradeTask func (u *UpgradeOptions) RunResourceUpgrade(cmd *cobra.Command) error { if version.IsCurrentVersionValid(u.fromVersion) && version.IsDesiredVersionValid(u.toVersion) { - klog.Infof("Upgrading to %s", u.toVersion) + klog.Infof("Upgrading %s from %s to %s", u.resourceKind, u.fromVersion, u.toVersion) err := upgrade.Exec(u.fromVersion, u.toVersion, u.resourceKind, u.name, diff --git a/pkg/upgrade/patch/cspc.go b/pkg/upgrade/patch/cspc.go index 37451587..f5098db9 100644 --- a/pkg/upgrade/patch/cspc.go +++ b/pkg/upgrade/patch/cspc.go @@ -59,10 +59,10 @@ func (c *CSPC) PreChecks(from, to string) error { return errors.Errorf("nil cspc object") } version := strings.Split(c.Object.VersionDetails.Status.Current, "-")[0] - if version != from && version != to { + if version != strings.Split(from, "-")[0] && version != strings.Split(to, "-")[0] { return errors.Errorf( "cspc version %s is neither %s nor %s", - version, + c.Object.VersionDetails.Status.Current, from, to, ) diff --git a/pkg/upgrade/patch/cspi.go b/pkg/upgrade/patch/cspi.go index 6b13fe48..460e3ca3 100644 --- a/pkg/upgrade/patch/cspi.go +++ b/pkg/upgrade/patch/cspi.go @@ -17,6 +17,8 @@ limitations under the License. package patch import ( + "strings" + apis "github.com/openebs/api/pkg/apis/cstor/v1" clientset "github.com/openebs/api/pkg/client/clientset/versioned" "github.com/pkg/errors" @@ -56,11 +58,11 @@ func (c *CSPI) PreChecks(from, to string) error { if c.Object == nil { return errors.Errorf("nil cspi object") } - version := c.Object.Labels["openebs.io/version"] - if version != from && version != to { + version := strings.Split(c.Object.Labels["openebs.io/version"], "-")[0] + if version != strings.Split(from, "-")[0] && version != strings.Split(to, "-")[0] { return errors.Errorf( "cspi version %s is neither %s nor %s", - version, + c.Object.Labels["openebs.io/version"], from, to, ) diff --git a/pkg/upgrade/patch/cv.go b/pkg/upgrade/patch/cv.go index f9db333b..6babde4c 100644 --- a/pkg/upgrade/patch/cv.go +++ b/pkg/upgrade/patch/cv.go @@ -59,10 +59,10 @@ func (c *CV) PreChecks(from, to string) error { return errors.Errorf("nil cv object") } version := strings.Split(c.Object.VersionDetails.Status.Current, "-")[0] - if version != from && version != to { + if version != strings.Split(from, "-")[0] && version != strings.Split(to, "-")[0] { return errors.Errorf( "cv version %s is neither %s nor %s", - version, + c.Object.VersionDetails.Status.Current, from, to, ) diff --git a/pkg/upgrade/patch/cvc.go b/pkg/upgrade/patch/cvc.go index ddbd9431..ee929aac 100644 --- a/pkg/upgrade/patch/cvc.go +++ b/pkg/upgrade/patch/cvc.go @@ -59,10 +59,10 @@ func (c *CVC) PreChecks(from, to string) error { return errors.Errorf("nil cvc object") } version := strings.Split(c.Object.VersionDetails.Status.Current, "-")[0] - if version != from && version != to { + if version != strings.Split(from, "-")[0] && version != strings.Split(to, "-")[0] { return errors.Errorf( "cvc version %s is neither %s nor %s", - version, + c.Object.VersionDetails.Status.Current, from, to, ) diff --git a/pkg/upgrade/patch/cvr.go b/pkg/upgrade/patch/cvr.go index 17719c41..1f0dc31a 100644 --- a/pkg/upgrade/patch/cvr.go +++ b/pkg/upgrade/patch/cvr.go @@ -59,10 +59,10 @@ func (c *CVR) PreChecks(from, to string) error { return errors.Errorf("nil cvr object") } version := strings.Split(c.Object.VersionDetails.Status.Current, "-")[0] - if version != from && version != to { + if version != strings.Split(from, "-")[0] && version != strings.Split(to, "-")[0] { return errors.Errorf( "cvr version %s is neither %s nor %s", - version, + c.Object.VersionDetails.Status.Current, from, to, ) diff --git a/pkg/upgrade/patch/deployment.go b/pkg/upgrade/patch/deployment.go index 1a2cc76e..4905eee7 100644 --- a/pkg/upgrade/patch/deployment.go +++ b/pkg/upgrade/patch/deployment.go @@ -17,6 +17,7 @@ limitations under the License. package patch import ( + "strings" "time" deploy "github.com/openebs/maya/pkg/kubernetes/deployment/appsv1/v1alpha1" @@ -60,11 +61,11 @@ func (d *Deployment) PreChecks(from, to string) error { if d.Object == nil { return errors.Errorf("nil deployment object") } - version := d.Object.Labels["openebs.io/version"] - if version != from && version != to { + version := strings.Split(d.Object.Labels["openebs.io/version"], "-")[0] + if version != strings.Split(from, "-")[0] && version != strings.Split(to, "-")[0] { return errors.Errorf( "deployment version %s is neither %s nor %s", - version, + d.Object.Labels["openebs.io/version"], from, to, ) diff --git a/pkg/upgrade/patch/service.go b/pkg/upgrade/patch/service.go index babcee71..1561a5a8 100644 --- a/pkg/upgrade/patch/service.go +++ b/pkg/upgrade/patch/service.go @@ -17,6 +17,8 @@ limitations under the License. package patch import ( + "strings" + "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -57,11 +59,11 @@ func (s *Service) PreChecks(from, to string) error { if name == "" { return errors.Errorf("missing service name") } - version := s.Object.Labels["openebs.io/version"] - if version != from && version != to { + version := strings.Split(s.Object.Labels["openebs.io/version"], "-")[0] + if version != strings.Split(from, "-")[0] && version != strings.Split(to, "-")[0] { return errors.Errorf( "service version %s is neither %s nor %s", - version, + s.Object.Labels["openebs.io/version"], from, to, )