From e36aaf6f701eca637fb9ba67f60540695930f876 Mon Sep 17 00:00:00 2001 From: Derek Su Date: Wed, 3 Apr 2024 04:33:12 +0000 Subject: [PATCH] feat(rwx): share manager pod respects the newly introduced storageClass.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 --- controller/share_manager_controller.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/controller/share_manager_controller.go b/controller/share_manager_controller.go index 0ddeec8685..95f5ca1cc0 100644 --- a/controller/share_manager_controller.go +++ b/controller/share_manager_controller.go @@ -789,6 +789,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() @@ -846,6 +861,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 { @@ -861,6 +877,13 @@ func (c *ShareManagerController) createShareManagerPod(sm *longhorn.ShareManager for k, v := range nodeSelectorFromStorageClass { nodeSelector[k] = v } + + // Find the tolerations from the storage class and merge it with the global tolerations + if tolerations == nil { + tolerations = []corev1.Toleration{} + } + tolerationsFromStorageClass := c.getShareManagerTolerationsFromStorageClass(sc) + tolerations = append(tolerations, tolerationsFromStorageClass...) } }