From 340c10a7256dd89b49e862b3edb88499bc5d62c3 Mon Sep 17 00:00:00 2001 From: Eric Weber Date: Tue, 12 Mar 2024 17:35:36 -0500 Subject: [PATCH] Fix upgrade path for ReplicaTransitionTimeMap Longhorn 8114 Signed-off-by: Eric Weber --- upgrade/upgrade.go | 7 +++++++ upgrade/util/util.go | 20 ++++++++++++++++++++ upgrade/v16xto170/upgrade.go | 3 +++ 3 files changed, 30 insertions(+) diff --git a/upgrade/upgrade.go b/upgrade/upgrade.go index c997ee1959..280551a1ce 100644 --- a/upgrade/upgrade.go +++ b/upgrade/upgrade.go @@ -287,6 +287,13 @@ func doResourceUpgrade(namespace string, lhClient *lhclientset.Clientset, kubeCl return err } } + // When lhVersionBeforeUpgrade < v1.7.0, it is v1.6.x. The `CheckUpgradePathSupported` method would have failed us out earlier if it was not v1.6.x. + if semver.Compare(lhVersionBeforeUpgrade, "v1.7.0") < 0 { + logrus.Info("Walking through the resource status upgrade path v1.6.x to v1.7.0") + if err := v16xto170.UpgradeResourcesStatus(namespace, lhClient, kubeClient, resourceMaps); err != nil { + return err + } + } if err := upgradeutil.UpdateResourcesStatus(namespace, lhClient, resourceMaps); err != nil { return err } diff --git a/upgrade/util/util.go b/upgrade/util/util.go index 2046703eb9..653b9ae863 100644 --- a/upgrade/util/util.go +++ b/upgrade/util/util.go @@ -1099,6 +1099,8 @@ func UpdateResourcesStatus(namespace string, lhClient *lhclientset.Clientset, re err = updateNodesStatus(namespace, lhClient, resourceMap.(map[string]*longhorn.Node)) case types.LonghornKindEngineImage: err = updateEngineImageStatus(namespace, lhClient, resourceMap.(map[string]*longhorn.EngineImage)) + case types.LonghornKindEngine: + err = updateEngineStatus(namespace, lhClient, resourceMap.(map[string]*longhorn.Engine)) default: return fmt.Errorf("resource kind %v is not able to updated", resourceKind) } @@ -1147,3 +1149,21 @@ func updateEngineImageStatus(namespace string, lhClient *lhclientset.Clientset, } return nil } + +func updateEngineStatus(namespace string, lhClient *lhclientset.Clientset, engines map[string]*longhorn.Engine) error { + existingEngineList, err := lhClient.LonghornV1beta2().Engines(namespace).List(context.TODO(), metav1.ListOptions{}) + if err != nil { + return err + } + for _, existingEngine := range existingEngineList.Items { + engine, ok := engines[existingEngine.Name] + if !ok { + continue + } + + if _, err = lhClient.LonghornV1beta2().Engines(namespace).UpdateStatus(context.TODO(), engine, metav1.UpdateOptions{}); err != nil { + return err + } + } + return nil +} diff --git a/upgrade/v16xto170/upgrade.go b/upgrade/v16xto170/upgrade.go index cbdb74d0bf..6571b89b4d 100644 --- a/upgrade/v16xto170/upgrade.go +++ b/upgrade/v16xto170/upgrade.go @@ -70,6 +70,9 @@ func upgradeEngineStatus(namespace string, lhClient *lhclientset.Clientset, reso } for _, e := range engineMap { + if e.Status.ReplicaTransitionTimeMap == nil { + e.Status.ReplicaTransitionTimeMap = map[string]string{} + } for replicaName := range e.Status.ReplicaModeMap { // We don't have any historical information to rely on. Starting at the time of the upgrade. if _, ok := e.Status.ReplicaTransitionTimeMap[replicaName]; !ok {