diff --git a/upgrade/upgrade.go b/upgrade/upgrade.go index 280551a1ce..efb501a75a 100644 --- a/upgrade/upgrade.go +++ b/upgrade/upgrade.go @@ -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" @@ -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 } diff --git a/upgrade/v170to171/upgrade.go b/upgrade/v170to171/upgrade.go new file mode 100644 index 0000000000..56e3d4ff8b --- /dev/null +++ b/upgrade/v170to171/upgrade.go @@ -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 +} diff --git a/upgrade/v17xto180/upgrade.go b/upgrade/v17xto180/upgrade.go new file mode 100644 index 0000000000..2948aa8f5c --- /dev/null +++ b/upgrade/v17xto180/upgrade.go @@ -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 +}