Skip to content

Commit

Permalink
feat(rwx): share manager pod respect the newly introduced storageClas…
Browse files Browse the repository at this point in the history
…s.Parameters["shareManagerNodeSelector"]

The commit introduces an enhancement for specifying the locality of a Read-Write-Many (RWX)
volume and its associated Share Manager Pod within the Longhorn storage system. Previously,
an RWX volume and its Share Manager Pod were created randomly on any node within the Longhorn
cluster, without the ability for users to specify a preferred locality.

Longhorn 7872

Signed-off-by: Derek Su <derek.su@suse.com>
  • Loading branch information
derekbit committed Apr 2, 2024
1 parent ffe359d commit 0a1aaec
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions controller/share_manager_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,16 +743,45 @@ func (c *ShareManagerController) syncShareManagerPod(sm *longhorn.ShareManager)
return nil
}

func (c *ShareManagerController) getShareManagerNodeSelectorFromStorageClass(pv *corev1.PersistentVolume) map[string]string {
if pv.Spec.StorageClassName == "" {
return map[string]string{}
}

sc, err := c.ds.GetStorageClass(pv.Spec.StorageClassName)
if err != nil {
c.logger.WithError(err).Warnf("Failed to get storage class %v", pv.Spec.StorageClassName)
return map[string]string{}
}

value, ok := sc.Parameters["shareManagerNodeSelector"]
if !ok {
return map[string]string{}
}

nodeSelector, err := types.UnmarshalNodeSelector(value)
if err != nil {
c.logger.WithError(err).Warnf("Failed to unmarshal node selector %v", value)
return map[string]string{}
}

return nodeSelector
}

// createShareManagerPod ensures existence of service, it's assumed that the pvc for this share manager already exists
func (c *ShareManagerController) createShareManagerPod(sm *longhorn.ShareManager) (*corev1.Pod, error) {
tolerations, err := c.ds.GetSettingTaintToleration()
if err != nil {
return nil, errors.Wrap(err, "failed to get taint toleration setting before creating share manager pod")
}

nodeSelector, err := c.ds.GetSettingSystemManagedComponentsNodeSelector()
if err != nil {
return nil, errors.Wrap(err, "failed to get node selector setting before creating share manager pod")
}
if nodeSelector == nil {
nodeSelector = map[string]string{}
}

tolerationsByte, err := json.Marshal(tolerations)
if err != nil {
Expand Down Expand Up @@ -798,6 +827,12 @@ func (c *ShareManagerController) createShareManagerPod(sm *longhorn.ShareManager
return nil, err
}

// Find the node selector from the storage class and merge it with the system managed components node selector
nodeSelectorFromStorageClass := c.getShareManagerNodeSelectorFromStorageClass(pv)
for k, v := range nodeSelectorFromStorageClass {
nodeSelector[k] = v
}

fsType := pv.Spec.CSI.FSType
mountOptions := pv.Spec.MountOptions

Expand Down

0 comments on commit 0a1aaec

Please sign in to comment.