Skip to content

Commit

Permalink
fix(backingimage): add upgrade path from 1.7.0 to 1.7.1 to add defaul…
Browse files Browse the repository at this point in the history
…t min number of copies

ref: longhorn/longhorn 9352

Signed-off-by: Jack Lin <jack.lin@suse.com>
  • Loading branch information
ChanYiLin authored and derekbit committed Aug 30, 2024
1 parent 68a4591 commit 69f8cdb
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
15 changes: 15 additions & 0 deletions upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"github.com/longhorn/longhorn-manager/upgrade/v151to152"
"github.com/longhorn/longhorn-manager/upgrade/v15xto160"
"github.com/longhorn/longhorn-manager/upgrade/v16xto170"
"github.com/longhorn/longhorn-manager/upgrade/v170to171"
"github.com/longhorn/longhorn-manager/upgrade/v17xto180"
"github.com/longhorn/longhorn-manager/upgrade/v1beta1"

longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
Expand Down Expand Up @@ -268,6 +270,19 @@ func doResourceUpgrade(namespace string, lhClient *lhclientset.Clientset, kubeCl
return err
}
}
if semver.Compare(lhVersionBeforeUpgrade, "v1.7.1") < 0 {
logrus.Info("Walking through the resource upgrade path v1.7.0 to v1.7.1")
if err := v170to171.UpgradeResources(namespace, lhClient, kubeClient, resourceMaps); err != nil {
return err
}
}
// When lhVersionBeforeUpgrade < v1.8.0, it is v1.7.x. The `CheckUpgradePathSupported` method would have failed us out earlier if it was not v1.7.x.
if semver.Compare(lhVersionBeforeUpgrade, "v1.8.0") < 0 {
logrus.Info("Walking through the resource upgrade path v1.7.x to v1.8.0")
if err := v17xto180.UpgradeResources(namespace, lhClient, kubeClient, resourceMaps); err != nil {
return err
}
}
if err := upgradeutil.UpdateResources(namespace, lhClient, resourceMaps); err != nil {
return err
}
Expand Down
49 changes: 49 additions & 0 deletions upgrade/v170to171/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package v170to171

import (
"github.com/pkg/errors"

apierrors "k8s.io/apimachinery/pkg/api/errors"
clientset "k8s.io/client-go/kubernetes"

"github.com/longhorn/longhorn-manager/types"

lhclientset "github.com/longhorn/longhorn-manager/k8s/pkg/client/clientset/versioned"
upgradeutil "github.com/longhorn/longhorn-manager/upgrade/util"
)

const (
upgradeLogPrefix = "upgrade from v1.7.0 to v1.7.1: "
)

func UpgradeResources(namespace string, lhClient *lhclientset.Clientset, kubeClient *clientset.Clientset, resourceMaps map[string]interface{}) error {
return upgradeBackingImages(namespace, lhClient, resourceMaps)
}

func upgradeBackingImages(namespace string, lhClient *lhclientset.Clientset, resourceMaps map[string]interface{}) (err error) {
defer func() {
err = errors.Wrapf(err, upgradeLogPrefix+"upgrade backing image failed")
}()

backingImageMap, err := upgradeutil.ListAndUpdateBackingImagesInProvidedCache(namespace, lhClient, resourceMaps)
if err != nil {
if apierrors.IsNotFound(err) {
return nil
}
return errors.Wrapf(err, "failed to list all existing Longhorn backing images during the backing image upgrade")
}

for _, bi := range backingImageMap {
if bi.Spec.MinNumberOfCopies == 0 {
bi.Spec.MinNumberOfCopies = types.DefaultMinNumberOfCopies
}
}

return nil
}

func UpgradeResourcesStatus(namespace string, lhClient *lhclientset.Clientset, kubeClient *clientset.Clientset, resourceMaps map[string]interface{}) error {
// Currently there are no statuses to upgrade. See UpgradeResources -> upgradeVolumes or previous Longhorn versions
// for examples.
return nil
}
49 changes: 49 additions & 0 deletions upgrade/v17xto180/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package v17xto180

import (
"github.com/pkg/errors"

apierrors "k8s.io/apimachinery/pkg/api/errors"
clientset "k8s.io/client-go/kubernetes"

"github.com/longhorn/longhorn-manager/types"

lhclientset "github.com/longhorn/longhorn-manager/k8s/pkg/client/clientset/versioned"
upgradeutil "github.com/longhorn/longhorn-manager/upgrade/util"
)

const (
upgradeLogPrefix = "upgrade from v1.7.x to v1.8.0: "
)

func UpgradeResources(namespace string, lhClient *lhclientset.Clientset, kubeClient *clientset.Clientset, resourceMaps map[string]interface{}) error {
return upgradeBackingImages(namespace, lhClient, resourceMaps)
}

func upgradeBackingImages(namespace string, lhClient *lhclientset.Clientset, resourceMaps map[string]interface{}) (err error) {
defer func() {
err = errors.Wrapf(err, upgradeLogPrefix+"upgrade backing image failed")
}()

backingImageMap, err := upgradeutil.ListAndUpdateBackingImagesInProvidedCache(namespace, lhClient, resourceMaps)
if err != nil {
if apierrors.IsNotFound(err) {
return nil
}
return errors.Wrapf(err, "failed to list all existing Longhorn backing images during the backing image upgrade")
}

for _, bi := range backingImageMap {
if bi.Spec.MinNumberOfCopies == 0 {
bi.Spec.MinNumberOfCopies = types.DefaultMinNumberOfCopies
}
}

return nil
}

func UpgradeResourcesStatus(namespace string, lhClient *lhclientset.Clientset, kubeClient *clientset.Clientset, resourceMaps map[string]interface{}) error {
// Currently there are no statuses to upgrade. See UpgradeResources -> upgradeVolumes or previous Longhorn versions
// for examples.
return nil
}

0 comments on commit 69f8cdb

Please sign in to comment.