-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(backingimage): add upgrade path from 1.7.0 to 1.7.1 to add defaul…
…t min number of copies ref: longhorn/longhorn 9352 Signed-off-by: Jack Lin <jack.lin@suse.com>
- Loading branch information
Showing
3 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |