controller: Sync trim related field based on the engine version
Longhorn 5218
@@ -852,6 +852,10 @@ func (m *EngineMonitor) refresh(engine *longhorn.Engine) error {
}
// TODO: find a more advanced way to handle invocations for incompatible running engines
+ im, err := m.ds.GetInstanceManagerRO(engine.Status.InstanceManagerName)
+ if err != nil {
+ return err
+ }
cliAPIVersion, err := m.ds.GetEngineImageCLIAPIVersion(engine.Status.CurrentImage)
if err != nil {
return err
@@ -905,6 +909,8 @@ func (m *EngineMonitor) refresh(engine *longhorn.Engine) error {
}
engine.Status.RebuildStatus = rebuildStatus
+ // It's meaningless to sync the trim related field for old engines or engines in old engine instance managers
+ if cliAPIVersion >= 7 && im.Status.APIVersion >= 3 {
// Check and correct flag UnmapMarkSnapChainRemoved for the engine and replicas
engine.Status.UnmapMarkSnapChainRemovedEnabled = volumeInfo.UnmapMarkSnapChainRemoved
if engine.Spec.UnmapMarkSnapChainRemovedEnabled != volumeInfo.UnmapMarkSnapChainRemoved {
@@ -913,6 +919,7 @@ func (m *EngineMonitor) refresh(engine *longhorn.Engine) error {
volumeInfo.UnmapMarkSnapChainRemoved, engine.Spec.UnmapMarkSnapChainRemovedEnabled)
}
}
+ }
} else {
// For incompatible running engine, the current size is always `engine.Spec.VolumeSize`.
engine.Status.CurrentSize = engine.Spec.VolumeSize
@@ -937,11 +944,6 @@ func (m *EngineMonitor) refresh(engine *longhorn.Engine) error {
existingEngine = engine.DeepCopy()
}
- im, err := m.ds.GetInstanceManagerRO(engine.Status.InstanceManagerName)
- if err != nil {
- return err
- }
-
requireExpansion, err := IsValidForExpansion(engine, cliAPIVersion, im.Status.APIVersion)
if err != nil {
engine.Status.LastExpansionError = err.Error()
