Skip to content

Commit

Permalink
Add CSI tolerations to rook-ceph-operator-config via controller
Browse files Browse the repository at this point in the history
Enhance the configuration process by incorporating CSI tolerations
directly into the rook-ceph-operator-config configmap through the
controller. Previously, end users were required to manually edit the
configmap for adding CSI tolerations. With this update, users can now
seamlessly include CSI tolerations in the storage clusters, and the
ocs-operator will automatically propagate these tolerations to the
configmap.

This improvement simplifies the configuration workflow and ensures that
CSI tolerations are seamlessly applied to the Rook Ceph Operator without
the need for manual intervention in the configmap.

Signed-off-by: Nitin Goyal <[email protected]>
  • Loading branch information
iamniting committed Mar 8, 2024
1 parent bfcc85d commit bcdbc57
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 5 deletions.
12 changes: 12 additions & 0 deletions controllers/defaults/placements.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ var (
getOcsToleration(),
},
},

"csi-plugin": {
Tolerations: []corev1.Toleration{
getOcsToleration(),
},
},

"csi-provisioner": {
Tolerations: []corev1.Toleration{
getOcsToleration(),
},
},
}
)

Expand Down
79 changes: 75 additions & 4 deletions controllers/ocsinitialization/ocsinitialization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"github.com/go-logr/logr"
secv1client "github.com/openshift/client-go/security/clientset/versioned/typed/security/v1"
ocsv1 "github.com/red-hat-storage/ocs-operator/api/v4/v1"
"github.com/red-hat-storage/ocs-operator/v4/controllers/defaults"
"github.com/red-hat-storage/ocs-operator/v4/controllers/util"
"gopkg.in/yaml.v2"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -241,7 +243,8 @@ func (r *OCSInitializationReconciler) SetupWithManager(mgr ctrl.Manager) error {
}

// ensureRookCephOperatorConfigExists ensures that the rook-ceph-operator-config cm exists
// This configmap is purely reserved for any user overrides to be applied.
// This configmap is semi-reserved for any user overrides to be applied 4.16 onwards.
// Earlier it used to be purely reserved for user overrides.
// We don't reconcile it if it exists as it can reset any values the user has set
// The configmap is watched by the rook operator and values set here have higher precedence
// than the default values set in the rook operator pod env vars.
Expand All @@ -252,14 +255,82 @@ func (r *OCSInitializationReconciler) ensureRookCephOperatorConfigExists(initial
Namespace: initialData.Namespace,
},
}
err := r.Client.Create(r.ctx, rookCephOperatorConfig)
if err != nil && !errors.IsAlreadyExists(err) {
r.Log.Error(err, fmt.Sprintf("Failed to create %s configmap", util.RookCephOperatorConfigName))

csiPluginDefaults := defaults.DaemonPlacements["csi-plugin"]
csiProvisionerDefaults := defaults.DaemonPlacements["csi-provisioner"]

pluginTolerations := r.getCsiPluginTolerations()
provisionerTolerations := r.getCsiProvisionerTolerations()

opResult, err := ctrl.CreateOrUpdate(r.ctx, r.Client, rookCephOperatorConfig, func() error {

if rookCephOperatorConfig.Data == nil {
rookCephOperatorConfig.Data = make(map[string]string)
}

if pluginTolerations != nil {
tolerations := append(pluginTolerations, csiPluginDefaults.Tolerations...)
tolerationsYAML, err := yaml.Marshal(tolerations)
if err != nil {
return err
}
rookCephOperatorConfig.Data["CSI_PLUGIN_TOLERATIONS"] = string(tolerationsYAML)
initialData.Status.RookCephOperatorConfig.CsiPluginTolerationsModified = true
} else if pluginTolerations == nil && initialData.Status.RookCephOperatorConfig.CsiPluginTolerationsModified {
delete(rookCephOperatorConfig.Data, "CSI_PLUGIN_TOLERATIONS")
initialData.Status.RookCephOperatorConfig.CsiPluginTolerationsModified = false
}

if provisionerTolerations != nil {
tolerations := append(provisionerTolerations, csiProvisionerDefaults.Tolerations...)
tolerationsYAML, err := yaml.Marshal(tolerations)
if err != nil {
return err
}
rookCephOperatorConfig.Data["CSI_PROVISIONER_TOLERATIONS"] = string(tolerationsYAML)
initialData.Status.RookCephOperatorConfig.CsiProvisionerTolerationsModified = true
} else if provisionerTolerations == nil && initialData.Status.RookCephOperatorConfig.CsiProvisionerTolerationsModified {
delete(rookCephOperatorConfig.Data, "CSI_PROVISIONER_TOLERATIONS")
initialData.Status.RookCephOperatorConfig.CsiProvisionerTolerationsModified = false
}

return nil
})

if err != nil {
r.Log.Error(err, "Failed to create/update rook-ceph-operator-config configmap", "OperationResult", opResult)
return err
}

return nil
}

func (r *OCSInitializationReconciler) getCsiPluginTolerations() []corev1.Toleration {

var tolerations []corev1.Toleration

for _, sc := range r.clusters.GetStorageClusters() {
if val, ok := sc.Spec.Placement["csi-plugin"]; ok {
tolerations = append(tolerations, val.Tolerations...)
}
}

return tolerations
}

func (r *OCSInitializationReconciler) getCsiProvisionerTolerations() []corev1.Toleration {

var tolerations []corev1.Toleration

for _, sc := range r.clusters.GetStorageClusters() {
if val, ok := sc.Spec.Placement["csi-provisioner"]; ok {
tolerations = append(tolerations, val.Tolerations...)
}
}

return tolerations
}

// ensureOcsOperatorConfigExists ensures that the ocs-operator-config exists & if not create/update it with required values
// This configmap is reserved just for ocs operator use, primarily meant for passing values to rook-ceph-operator
// It is not meant to be modified by the user
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ require (
google.golang.org/grpc v1.60.0
google.golang.org/protobuf v1.31.0
gopkg.in/ini.v1 v1.67.0
gopkg.in/yaml.v2 v2.4.0
gotest.tools/v3 v3.5.0
k8s.io/api v0.28.4
k8s.io/apiextensions-apiserver v0.28.4
Expand Down Expand Up @@ -127,7 +128,6 @@ require (
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiserver v0.28.4 // indirect
k8s.io/component-base v0.28.4 // indirect
Expand Down

0 comments on commit bcdbc57

Please sign in to comment.