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>
(cherry picked from commit 686f4e2)
  • Loading branch information
ejweber committed Mar 29, 2024
1 parent 9070acf commit 9a7261c
Show file tree
Hide file tree
Showing 3 changed files with 51 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 @@ -26,6 +26,7 @@ import (
"github.com/longhorn/longhorn-manager/upgrade/v14xto150"
"github.com/longhorn/longhorn-manager/upgrade/v151to152"
"github.com/longhorn/longhorn-manager/upgrade/v153to154"
"github.com/longhorn/longhorn-manager/upgrade/v154to155"
"github.com/longhorn/longhorn-manager/upgrade/v1beta1"

longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
Expand Down Expand Up @@ -261,6 +262,12 @@ func doResourceUpgrade(namespace string, lhClient *lhclientset.Clientset, kubeCl
return err
}
}
if semver.Compare(lhVersionBeforeUpgrade, "v1.5.5") < 0 {
logrus.Info("Walking through the resource status upgrade path v1.5.4 to v1.5.5")
if err := v154to155.UpgradeResourcesStatus(namespace, lhClient, kubeClient, resourceMaps); err != nil {
return err
}
}
if err := upgradeutil.UpdateResourcesStatus(namespace, lhClient, resourceMaps); err != nil {
return err
}
Expand Down
41 changes: 41 additions & 0 deletions upgrade/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,8 @@ func UpdateResourcesStatus(namespace string, lhClient *lhclientset.Clientset, re
switch resourceKind {
case types.LonghornKindNode:
err = updateNodesStatus(namespace, lhClient, resourceMap.(map[string]*longhorn.Node))
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 @@ -1030,3 +1032,42 @@ func updateNodesStatus(namespace string, lhClient *lhclientset.Clientset, nodes
}
return nil
}
<<<<<<< HEAD
=======

func updateEngineImageStatus(namespace string, lhClient *lhclientset.Clientset, eis map[string]*longhorn.EngineImage) error {
existingEngineImageList, err := lhClient.LonghornV1beta2().EngineImages(namespace).List(context.TODO(), metav1.ListOptions{})
if err != nil {
return err
}
for _, existingEngineImage := range existingEngineImageList.Items {
ei, ok := eis[existingEngineImage.Name]
if !ok {
continue
}

if _, err = lhClient.LonghornV1beta2().EngineImages(namespace).UpdateStatus(context.TODO(), ei, metav1.UpdateOptions{}); err != nil {
return err
}
}
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
}
>>>>>>> 686f4e210 (Fix upgrade path for ReplicaTransitionTimeMap)
3 changes: 3 additions & 0 deletions upgrade/v154to155/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,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 9a7261c

Please sign in to comment.