diff --git a/controller/share_manager_controller.go b/controller/share_manager_controller.go index eba94370a7..665bd96ca7 100644 --- a/controller/share_manager_controller.go +++ b/controller/share_manager_controller.go @@ -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() @@ -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 { @@ -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...) } }