Skip to content

Commit

Permalink
Remove unnecessary upgrade placeholders
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Weber <eric.weber@suse.com>
  • Loading branch information
ejweber committed Aug 15, 2023
1 parent d7e23a9 commit 548824a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 138 deletions.
2 changes: 2 additions & 0 deletions types/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,8 @@ func ValidateSetting(name, value string) (err error) {
case SettingNameAllowEmptyDiskSelectorVolume:
fallthrough
case SettingNameAllowCollectingLonghornUsage:
fallthrough
case SettingNameReplicaDiskSoftAntiAffinity:
if value != "true" && value != "false" {
return fmt.Errorf("value %v of setting %v should be true or false", value, sName)
}
Expand Down
2 changes: 1 addition & 1 deletion upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func doResourceUpgrade(namespace string, lhClient *lhclientset.Clientset, kubeCl

// When lhVersionBeforeUpgrade < v1.6.0, it is v1.5.x. The `CheckUpgradePathSupported` method would have failed us out earlier if it was not v1.5.x.
resourceMaps = map[string]interface{}{}
if semver.Compare(lhVersionBeforeUpgrade, "v1.5.0") < 0 {
if semver.Compare(lhVersionBeforeUpgrade, "v1.6.0") < 0 {
logrus.Info("Walking through the resource status upgrade path v1.5.x to v1.6.0")
if err := v15xto160.UpgradeResourcesStatus(namespace, lhClient, kubeClient, resourceMaps); err != nil {
return err
Expand Down
142 changes: 5 additions & 137 deletions upgrade/v15xto160/upgrade.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package v15xto160

import (
"context"

"github.com/pkg/errors"

apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes"

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

Expand All @@ -20,47 +16,9 @@ const (
)

func UpgradeResources(namespace string, lhClient *lhclientset.Clientset, kubeClient *clientset.Clientset, resourceMaps map[string]interface{}) error {
if err := upgradeCSIPlugin(namespace, kubeClient); err != nil {
return err
}

if err := upgradeVolumes(namespace, lhClient, resourceMaps); err != nil {
return err
}

if err := upgradeNodes(namespace, lhClient, resourceMaps); err != nil {
return err
}

if err := upgradeEngines(namespace, lhClient, resourceMaps); err != nil {
return err
}

if err := upgradeReplicas(namespace, lhClient, resourceMaps); err != nil {
return err
}

return upgradeOrphans(namespace, lhClient, resourceMaps)
}

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

nodeMap, err := upgradeutil.ListAndUpdateNodesInProvidedCache(namespace, lhClient, resourceMaps)
if err != nil {
if apierrors.IsNotFound(err) {
return nil
}
return errors.Wrapf(err, "failed to list all existing Longhorn nodes during the node upgrade")
}

for _, n := range nodeMap {
_ = n // Nothing to do.
}

return nil
// We will probably need to upgrade other resources as well. See upgradeVolumes or previous Longhorn versions for
// examples.
return upgradeVolumes(namespace, lhClient, resourceMaps)
}

func upgradeVolumes(namespace string, lhClient *lhclientset.Clientset, resourceMaps map[string]interface{}) (err error) {
Expand All @@ -85,98 +43,8 @@ func upgradeVolumes(namespace string, lhClient *lhclientset.Clientset, resourceM
return nil
}

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

replicaMap, err := upgradeutil.ListAndUpdateReplicasInProvidedCache(namespace, lhClient, resourceMaps)
if err != nil {
if apierrors.IsNotFound(err) {
return nil
}
return errors.Wrapf(err, "failed to list all existing Longhorn replicas during the replica upgrade")
}

for _, r := range replicaMap {
_ = r // Nothing to do.
}

return nil
}

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

engineMap, err := upgradeutil.ListAndUpdateEnginesInProvidedCache(namespace, lhClient, resourceMaps)
if err != nil {
if apierrors.IsNotFound(err) {
return nil
}
return errors.Wrapf(err, "failed to list all existing Longhorn engines during the engine upgrade")
}

for _, e := range engineMap {
_ = e // Nothing to do.
}

return nil
}

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

orphanMap, err := upgradeutil.ListAndUpdateOrphansInProvidedCache(namespace, lhClient, resourceMaps)
if err != nil {
if apierrors.IsNotFound(err) {
return nil
}
return errors.Wrapf(err, "failed to list all existing Longhorn orphans during the orphan upgrade")
}

for _, o := range orphanMap {
if o.Spec.Parameters == nil {
continue
}

_ = o // Nothing to do.
}

return nil
}

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

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

nodeMap, err := upgradeutil.ListAndUpdateNodesInProvidedCache(namespace, lhClient, resourceMaps)
if err != nil {
if apierrors.IsNotFound(err) {
return nil
}
return errors.Wrapf(err, "failed to list all existing Longhorn nodes during the node upgrade")
}

for _, n := range nodeMap {
_ = n // Nothing to do.
}

return nil
}

func upgradeCSIPlugin(namespace string, kubeClient *clientset.Clientset) error {
err := kubeClient.AppsV1().DaemonSets(namespace).Delete(context.TODO(), types.CSIPluginName, metav1.DeleteOptions{})
if err != nil && !apierrors.IsNotFound(err) {
return errors.Wrapf(err, upgradeLogPrefix+"failed to delete the %v daemonset during the upgrade", types.CSIPluginName)
}
// Currently there are no statuses to upgrade. See UpgradeResources -> upgradeVolumes or previous Longhorn versions
// for examples.
return nil
}

0 comments on commit 548824a

Please sign in to comment.