Skip to content

Commit

Permalink
feat(rwx): share manager pod respects the newly introduced storageCla…
Browse files Browse the repository at this point in the history
…ss.Parameters["shareManagerTolerations"]

Share manager pod respects the newly introduced storageClass.Parameters["shareManagerTolerations"].
The tolerations are merged with the global setting taint-toleration and are applied to share manager pod.

Longhron 7872

Signed-off-by: Derek Su <derek.su@suse.com>
  • Loading branch information
derekbit committed Apr 3, 2024
1 parent 9cf759b commit f1b50cd
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion controller/share_manager_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,21 @@ func (c *ShareManagerController) getShareManagerNodeSelectorFromStorageClass(sc
return nodeSelector
}

func (c *ShareManagerController) getShareManagerTolerationsFromStorageClass(sc *storagev1.StorageClass) []corev1.Toleration {
value, ok := sc.Parameters["shareManagerTolerations"]
if !ok {
return []corev1.Toleration{}
}

tolerations, err := types.UnmarshalTolerations(value)
if err != nil {
c.logger.WithError(err).Warnf("Failed to unmarshal tolerations %v", value)
return []corev1.Toleration{}
}

return tolerations
}

// 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()
Expand Down Expand Up @@ -842,6 +857,7 @@ func (c *ShareManagerController) createShareManagerPod(sm *longhorn.ShareManager
}

var affinity *corev1.Affinity

if pv.Spec.StorageClassName != "" {
sc, err := c.ds.GetStorageClass(pv.Spec.StorageClassName)
if err != nil {
Expand All @@ -850,13 +866,18 @@ func (c *ShareManagerController) createShareManagerPod(sm *longhorn.ShareManager
if nodeSelector == nil {
nodeSelector = map[string]string{}
}

affinity = c.getAffinityFromStorageClass(sc)

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

affinity = c.getAffinityFromStorageClass(sc)
// Find the tolerations from the storage class and merge it with the global tolerations
tolerationsFromStorageClass := c.getShareManagerTolerationsFromStorageClass(sc)
tolerations = append(tolerations, tolerationsFromStorageClass...)
}
}

Expand Down

0 comments on commit f1b50cd

Please sign in to comment.