diff --git a/types/setting.go b/types/setting.go index 358eaa75b1..3a46102869 100644 --- a/types/setting.go +++ b/types/setting.go @@ -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) } diff --git a/upgrade/upgrade.go b/upgrade/upgrade.go index b2713ab753..8aef5f25ea 100644 --- a/upgrade/upgrade.go +++ b/upgrade/upgrade.go @@ -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 diff --git a/upgrade/v15xto160/upgrade.go b/upgrade/v15xto160/upgrade.go index 647e1e3bf4..dbf20a5467 100644 --- a/upgrade/v15xto160/upgrade.go +++ b/upgrade/v15xto160/upgrade.go @@ -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" ) @@ -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) { @@ -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 }