Skip to content

Commit

Permalink
csi: adding toleration to csi pods
Browse files Browse the repository at this point in the history
when PVC is scheduled on the master node CSI pod fails to run

Signed-off-by: rchikatw <[email protected]>
  • Loading branch information
rchikatw committed Nov 20, 2023
1 parent 1969a71 commit b94a9e9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/csi/cephfsdaemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"

"github.com/red-hat-storage/ocs-client-operator/pkg/templates"
"github.com/red-hat-storage/ocs-client-operator/pkg/utils"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -262,6 +263,9 @@ func GetCephFSDaemonSet(namespace string) *appsv1.DaemonSet {
},
},
},
Tolerations: []corev1.Toleration{
utils.GetTolerationForCSIPods(),
},
},
},
},
Expand Down
4 changes: 4 additions & 0 deletions pkg/csi/rbddaemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"fmt"

"github.com/red-hat-storage/ocs-client-operator/pkg/templates"
"github.com/red-hat-storage/ocs-client-operator/pkg/utils"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -390,6 +391,9 @@ func GetRBDDaemonSet(namespace string) *appsv1.DaemonSet {
},
},
},
Tolerations: []corev1.Toleration{
utils.GetTolerationForCSIPods(),
},
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions pkg/utils/k8sutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const StorageClientNamespaceEnvVar = "STORAGE_CLIENT_NAMESPACE"

const StatusReporterImageEnvVar = "STATUS_REPORTER_IMAGE"

const runCSIDaemonsetOnMaster = "RUN_CSI_DAEMONSET_ON_MASTER"

// GetOperatorNamespace returns the namespace where the operator is deployed.
func GetOperatorNamespace() string {
return os.Getenv(OperatorNamespaceEnvVar)
Expand Down
32 changes: 32 additions & 0 deletions pkg/utils/placements.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package utils

import (
"log"
"os"
"strconv"

corev1 "k8s.io/api/core/v1"
)

func GetTolerationForCSIPods() corev1.Toleration {

runOnMaster := true
var err error
rom := os.Getenv(runCSIDaemonsetOnMaster)
if rom != "" {
runOnMaster, err = strconv.ParseBool(rom)
if err != nil {
log.Fatal(err)
}
}

if runOnMaster {
toleration := corev1.Toleration{
Key: "node-role.kubernetes.io/master",
Operator: corev1.TolerationOpExists,
Effect: corev1.TaintEffectNoSchedule,
}
return toleration
}
return corev1.Toleration{}
}

0 comments on commit b94a9e9

Please sign in to comment.