diff --git a/pkg/csi/cephfsdaemonset.go b/pkg/csi/cephfsdaemonset.go index 04b902b2..d40fff46 100644 --- a/pkg/csi/cephfsdaemonset.go +++ b/pkg/csi/cephfsdaemonset.go @@ -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" @@ -262,6 +263,9 @@ func GetCephFSDaemonSet(namespace string) *appsv1.DaemonSet { }, }, }, + Tolerations: []corev1.Toleration{ + utils.GetTolerationForCSIPods(), + }, }, }, }, diff --git a/pkg/csi/rbddaemonset.go b/pkg/csi/rbddaemonset.go index 1068cde8..27d9a7b4 100644 --- a/pkg/csi/rbddaemonset.go +++ b/pkg/csi/rbddaemonset.go @@ -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" @@ -390,6 +391,9 @@ func GetRBDDaemonSet(namespace string) *appsv1.DaemonSet { }, }, }, + Tolerations: []corev1.Toleration{ + utils.GetTolerationForCSIPods(), + }, }, }, }, diff --git a/pkg/utils/k8sutils.go b/pkg/utils/k8sutils.go index 7173d220..57ac19dd 100644 --- a/pkg/utils/k8sutils.go +++ b/pkg/utils/k8sutils.go @@ -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) diff --git a/pkg/utils/placements.go b/pkg/utils/placements.go new file mode 100644 index 00000000..16808368 --- /dev/null +++ b/pkg/utils/placements.go @@ -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{} +}