From aa98709ce9f8ab39f715def03ee0c87820874de4 Mon Sep 17 00:00:00 2001 From: Derek Su Date: Tue, 23 Apr 2024 13:46:33 +0000 Subject: [PATCH] upgrade: set instanceManager.spec.desireState to running Longhorn 8456 Signed-off-by: Derek Su --- upgrade/v16xto170/upgrade.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/upgrade/v16xto170/upgrade.go b/upgrade/v16xto170/upgrade.go index b2aaa08641..36a35c4d95 100644 --- a/upgrade/v16xto170/upgrade.go +++ b/upgrade/v16xto170/upgrade.go @@ -28,7 +28,11 @@ func UpgradeResources(namespace string, lhClient *lhclientset.Clientset, kubeCli return err } - return upgradeNodes(namespace, lhClient, resourceMaps) + if err := upgradeNodes(namespace, lhClient, resourceMaps); err != nil { + return err + } + + return upgradeInstanceManagers(namespace, lhClient, resourceMaps) } func UpgradeResourcesStatus(namespace string, lhClient *lhclientset.Clientset, kubeClient *clientset.Clientset, resourceMaps map[string]interface{}) error { @@ -140,7 +144,7 @@ func upgradeEngineStatus(namespace string, lhClient *lhclientset.Clientset, reso func upgradeNodes(namespace string, lhClient *lhclientset.Clientset, resourceMaps map[string]interface{}) (err error) { defer func() { - err = errors.Wrapf(err, upgradeLogPrefix+"upgrade node failed") + err = errors.Wrapf(err, upgradeLogPrefix+"upgrade nodes failed") }() nodeMap, err := upgradeutil.ListAndUpdateNodesInProvidedCache(namespace, lhClient, resourceMaps) @@ -166,3 +170,23 @@ func upgradeNodes(namespace string, lhClient *lhclientset.Clientset, resourceMap return nil } + +func upgradeInstanceManagers(namespace string, lhClient *lhclientset.Clientset, resourceMaps map[string]interface{}) (err error) { + defer func() { + err = errors.Wrapf(err, upgradeLogPrefix+"upgrade instance managers failed") + }() + + imMap, err := upgradeutil.ListAndUpdateInstanceManagersInProvidedCache(namespace, lhClient, resourceMaps) + if err != nil { + if apierrors.IsNotFound(err) { + return nil + } + return errors.Wrapf(err, "failed to list all existing Longhorn instance managers during the instance manager upgrade") + } + + for _, im := range imMap { + im.Spec.DesireState = longhorn.InstanceManagerStateRunning + } + + return nil +}