Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(version): fix version checks of resources #27

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions cmd/upgrade/executor/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}
Expand Down Expand Up @@ -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)
shubham14bajpai marked this conversation as resolved.
Show resolved Hide resolved
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,
Expand Down
4 changes: 2 additions & 2 deletions pkg/upgrade/patch/cspc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
shubham14bajpai marked this conversation as resolved.
Show resolved Hide resolved
return errors.Errorf(
"cspc version %s is neither %s nor %s",
version,
c.Object.VersionDetails.Status.Current,
from,
to,
)
Expand Down
8 changes: 5 additions & 3 deletions pkg/upgrade/patch/cspi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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] {
shubham14bajpai marked this conversation as resolved.
Show resolved Hide resolved
return errors.Errorf(
"cspi version %s is neither %s nor %s",
version,
c.Object.Labels["openebs.io/version"],
from,
to,
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/upgrade/patch/cv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/upgrade/patch/cvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/upgrade/patch/cvr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
7 changes: 4 additions & 3 deletions pkg/upgrade/patch/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package patch

import (
"strings"
"time"

deploy "github.com/openebs/maya/pkg/kubernetes/deployment/appsv1/v1alpha1"
Expand Down Expand Up @@ -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,
)
Expand Down
8 changes: 5 additions & 3 deletions pkg/upgrade/patch/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
)
Expand Down