Skip to content

Commit

Permalink
csi: enable csi-omap when set in sidecar config
Browse files Browse the repository at this point in the history
Signed-off-by: Rewant Soni <[email protected]>
  • Loading branch information
rewantsoni committed Mar 18, 2024
1 parent c55248d commit be0de20
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 7 deletions.
41 changes: 38 additions & 3 deletions controllers/clusterversion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package controllers
import (
"bytes"
"context"
"strconv"
"strings"

// The embed package is required for the prometheus rule files
Expand Down Expand Up @@ -51,7 +52,9 @@ import (
var pvcPrometheusRules string

const (
operatorConfigMapName = "ocs-client-operator-config"
operatorConfigMapName = "ocs-client-operator-config"
csiSidecarConfigMapName = "ceph-csi-sidecar-config"
csiOMAPGeneratorKey = "CSI_ENABLE_OMAP_GENERATOR"
// ClusterVersionName is the name of the ClusterVersion object in the
// openshift cluster.
clusterVersionName = "version"
Expand Down Expand Up @@ -86,7 +89,7 @@ func (c *ClusterVersionReconciler) SetupWithManager(mgr ctrl.Manager) error {
func(client client.Object) bool {
namespace := client.GetNamespace()
name := client.GetName()
return ((namespace == c.OperatorNamespace) && (name == operatorConfigMapName))
return namespace == c.OperatorNamespace && (name == operatorConfigMapName || name == csiSidecarConfigMapName)
},
),
)
Expand Down Expand Up @@ -203,6 +206,25 @@ func (c *ClusterVersionReconciler) Reconcile(ctx context.Context, req ctrl.Reque
return ctrl.Result{}, err
}

sideCarConfig := &corev1.ConfigMap{}
sideCarConfig.Name = csiSidecarConfigMapName
sideCarConfig.Namespace = c.OperatorNamespace

err = c.get(sideCarConfig)
if err != nil && !k8serrors.IsNotFound(err) {
c.log.Error(err, "failed to get csi side car configmap", "name", sideCarConfig)
return ctrl.Result{}, err
}

enableOMAPGenerator := false
if value, ok := sideCarConfig.Data[csiOMAPGeneratorKey]; ok {
enableOMAPGenerator, err = strconv.ParseBool(value)
if err != nil {
c.log.Error(err, "failed to parse configmap entry", "ConfigMap", sideCarConfig, csiOMAPGeneratorKey, value)
return ctrl.Result{}, err
}
}

c.cephFSDeployment = &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: csi.CephFSDeploymentName,
Expand Down Expand Up @@ -249,7 +271,7 @@ func (c *ClusterVersionReconciler) Reconcile(ctx context.Context, req ctrl.Reque
if err := c.own(c.rbdDeployment); err != nil {
return err
}
csi.SetRBDDeploymentDesiredState(c.rbdDeployment)
csi.SetRBDDeploymentDesiredState(c.rbdDeployment, enableOMAPGenerator)
return nil
})
if err != nil {
Expand Down Expand Up @@ -337,6 +359,10 @@ func (c *ClusterVersionReconciler) create(obj client.Object) error {
return c.Client.Create(c.ctx, obj)
}

func (c *ClusterVersionReconciler) get(obj client.Object) error {
return c.Client.Get(c.ctx, client.ObjectKeyFromObject(obj), obj)
}

// applyLabels adds labels to object meta, overwriting keys that are already defined.
func applyLabels(label string, t *metav1.ObjectMeta) {
// Create a map to store the configuration
Expand Down Expand Up @@ -366,6 +392,15 @@ func (c *ClusterVersionReconciler) getOperatorConfig() (*corev1.ConfigMap, error
return cm, nil
}

func (c *ClusterVersionReconciler) getSideCarConfig() (*corev1.ConfigMap, error) {

Check failure on line 395 in controllers/clusterversion_controller.go

View workflow job for this annotation

GitHub Actions / golangci-lint

func `(*ClusterVersionReconciler).getSideCarConfig` is unused (unused)
cm := &corev1.ConfigMap{}
err := c.Client.Get(c.ctx, types.NamespacedName{Name: csiSidecarConfigMapName, Namespace: c.OperatorNamespace}, cm)
if err != nil && !k8serrors.IsNotFound(err) {
return nil, err
}
return cm, nil
}

func (c *ClusterVersionReconciler) ensureConsolePlugin() error {
c.consoleDeployment = &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Expand Down
18 changes: 18 additions & 0 deletions controllers/storageclassclaim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,24 @@ func (r *StorageClassClaimReconciler) reconcilePhases() (reconcile.Result, error
return reconcile.Result{}, fmt.Errorf("failed to extract monitor data: %v", err)
}
csiClusterConfigEntry.Monitors = append(csiClusterConfigEntry.Monitors, monitorIps...)
} else if eResource.Kind == "ConfigMap" && eResource.Name == csiSidecarConfigMapName {
csiSideCarConfig := &corev1.ConfigMap{}
csiSideCarConfig.Name = eResource.Name
csiSideCarConfig.Namespace = r.OperatorNamespace

data := map[string]string{}
err = json.Unmarshal(eResource.Data, &data)
if err != nil {
return reconcile.Result{}, fmt.Errorf("failed to unmarshal csi-sidecar-config configuration response: %v", err)
}

_, err := controllerutil.CreateOrUpdate(r.ctx, r.Client, csiSideCarConfig, func() error {
csiSideCarConfig.Data = data
return nil
})
if err != nil {
return reconcile.Result{}, fmt.Errorf("failed to create or update configMap %v: %s", csiSideCarConfig, err)
}
}
}
// Go over the received objects and operate on them accordingly.
Expand Down
17 changes: 14 additions & 3 deletions pkg/csi/rbddeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ var rbdDeploymentSpec = appsv1.DeploymentSpec{
},
{
Name: "ceph-csi-configs",
MountPath: "/etc/ceph-csi-config",
MountPath: templates.DefaultCephCSIConfigPath,
},
{
Name: "keys-tmp-dir",
MountPath: "/tmp/csi/keys",
MountPath: templates.DefaultTmpDir,
},
{
Name: "ceph-csi-kms-config",
Expand Down Expand Up @@ -214,7 +214,7 @@ var rbdDeploymentSpec = appsv1.DeploymentSpec{
},
}

func SetRBDDeploymentDesiredState(deploy *appsv1.Deployment) {
func SetRBDDeploymentDesiredState(deploy *appsv1.Deployment, enableOMAPGenerator bool) {
// Copy required labels
for key := range rbdDaemonsetLabels {
deploy.Labels[key] = cephfsDaemonsetLabels[key]
Expand All @@ -223,6 +223,12 @@ func SetRBDDeploymentDesiredState(deploy *appsv1.Deployment) {
// Update the deployment set with desired spec
rbdDeploymentSpec.DeepCopyInto(&deploy.Spec)

if enableOMAPGenerator {
deploy.Spec.Template.Spec.Containers = append(
deploy.Spec.Template.Spec.Containers,
corev1.Container{Name: templates.OMAPGeneratorContainer.Name})
}

// Find and Update placeholder containers with desired state
leaderElectionArg := fmt.Sprintf("--leader-election-namespace=%s", deploy.Namespace)

Expand Down Expand Up @@ -255,6 +261,11 @@ func SetRBDDeploymentDesiredState(deploy *appsv1.Deployment) {
c.Image = sidecarImages.ContainerImages.CSIADDONSImageURL
c.Args = append(c.Args, leaderElectionArg)

case templates.OMAPGeneratorContainer.Name:
templates.OMAPGeneratorContainer.DeepCopyInto(c)
c.Image = sidecarImages.ContainerImages.CephCSIImageURL
c.Args = append(c.Args, fmt.Sprintf("--drivername=%s", GetRBDDriverName()))

case rbdDeploymentContainerName:
c.Image = sidecarImages.ContainerImages.CephCSIImageURL
}
Expand Down
30 changes: 30 additions & 0 deletions pkg/templates/csisidecars.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,36 @@ var CSIAddonsContainer = corev1.Container{
ImagePullPolicy: corev1.PullIfNotPresent,
}

var OMAPGeneratorContainer = corev1.Container{
Name: "csi-omap-generator",
ImagePullPolicy: corev1.PullIfNotPresent,
Args: []string{
"--type=controller",
"--drivernamespace=$(DRIVER_NAMESPACE)",
"--v=5",
},
Env: []corev1.EnvVar{
{
Name: "DRIVER_NAMESPACE",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "metadata.namespace",
},
},
},
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "ceph-csi-configs",
MountPath: DefaultCephCSIConfigPath,
},
{
Name: "keys-tmp-dir",
MountPath: DefaultTmpDir,
},
},
}

var DriverRegistrar = corev1.Container{
Name: "csi-driver-registrar",
ImagePullPolicy: corev1.PullIfNotPresent,
Expand Down
3 changes: 2 additions & 1 deletion pkg/templates/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const (
DefaultCSIAddonsSocketPath = "unix:///csi/csi-addons.sock"
DefaultSocketDir = "/csi"
DefaultStagingPath = "/var/lib/kubelet/plugins/kubernetes.io/csi/"

DefaultCephCSIConfigPath = "/etc/ceph-csi-config"
DefaultTmpDir = "/tmp/csi/keys"
// configmap names
MonConfigMapName = "ceph-csi-configs"
EncryptionConfigMapName = "ceph-csi-kms-config"
Expand Down

0 comments on commit be0de20

Please sign in to comment.