Skip to content

Commit

Permalink
feat(controller): do not create any instance manager pods for v2 volu…
Browse files Browse the repository at this point in the history
…mes if one is already existing

An extra instance manager pod for v2 data engine requires an additional CPU core and 2 GiB of memory.
If the resources are insufficient, the instance manager pod will be recreated and retried.
To minimize unnecessary retries, do not create any new instance manager pods if one is already running.

Longhorn 8456

Signed-off-by: Derek Su <derek.su@suse.com>
  • Loading branch information
derekbit committed Jul 2, 2024
1 parent 4647dce commit 7d0f1cd
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions controller/instance_manager_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,19 @@ func (imc *InstanceManagerController) syncInstanceManager(key string) (err error
return err
}

// An instance manager pod for v2 volume need to consume huge pages, and disks managed by the
// pod is unable to managed by another pod. Therefore, if an instance manager pod is running on a node,
// an extra instance manager pod for v2 volume should not be created.
if types.IsDataEngineV2(im.Spec.DataEngine) {
syncable, err := imc.canProceedWithInstanceManagerSync(im)
if err != nil {
return err
}
if !syncable {
return nil
}
}

if err := imc.syncStatusWithNode(im); err != nil {
return err
}
Expand Down Expand Up @@ -365,6 +378,36 @@ func (imc *InstanceManagerController) syncInstanceManager(key string) (err error
return nil
}

func (imc *InstanceManagerController) canProceedWithInstanceManagerSync(currentIm *longhorn.InstanceManager) (bool, error) {
// If the instance manager is not stopped, proceed with the sync.
if currentIm.Status.CurrentState != longhorn.InstanceManagerStateStopped {
return true, nil
}

ims, err := imc.ds.ListInstanceManagersByNodeRO(currentIm.Spec.NodeID, longhorn.InstanceManagerTypeAllInOne, longhorn.DataEngineTypeV2)
if err != nil {
return false, err
}
// If there is another non-stooped instance manager pod for v2 volume, do not proceed with the sync.
for _, im := range ims {
if im.Name == currentIm.Name {
continue
}

if im.Status.CurrentState != longhorn.InstanceManagerStateStopped {
return false, nil
}
}

defaultInstanceManagerImage, err := imc.ds.GetSettingValueExisted(types.SettingNameDefaultInstanceManagerImage)
if err != nil {
return false, err
}

// Only active the sync when the default instance manager image is used.
return currentIm.Spec.Image == defaultInstanceManagerImage, nil
}

// syncStatusWithPod updates the InstanceManager based on the pod current phase only,
// regardless of the InstanceManager previous status.
func (imc *InstanceManagerController) syncStatusWithPod(im *longhorn.InstanceManager) error {
Expand Down

0 comments on commit 7d0f1cd

Please sign in to comment.