Skip to content

Commit

Permalink
Fix upgrade path for ReplicaTransitionTimeMap
Browse files Browse the repository at this point in the history
Longhorn 8114

Signed-off-by: Eric Weber <eric.weber@suse.com>
  • Loading branch information
ejweber authored and innobead committed Mar 13, 2024
1 parent 229a68d commit 340c10a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
20 changes: 20 additions & 0 deletions upgrade/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions upgrade/v16xto170/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 340c10a

Please sign in to comment.