From 66c9ccab86bef57e761e4ea0a6bb8d01bfe50294 Mon Sep 17 00:00:00 2001 From: Rakshith R Date: Wed, 16 Jun 2021 14:37:00 +0530 Subject: [PATCH] ceph: read and validate CSI params in Go routine This commit moves SetParams and ValidateCSIParam func into go routine/lock, since it modifies/reads global CSIParam variable. Signed-off-by: Rakshith R --- pkg/operator/ceph/csi/csi.go | 13 ++++++++++++- pkg/operator/ceph/csi/spec.go | 2 +- pkg/operator/ceph/operator.go | 8 -------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/pkg/operator/ceph/csi/csi.go b/pkg/operator/ceph/csi/csi.go index e8430fe6e..a9e2f0ee2 100644 --- a/pkg/operator/ceph/csi/csi.go +++ b/pkg/operator/ceph/csi/csi.go @@ -34,6 +34,17 @@ func ValidateAndConfigureDrivers(context *clusterd.Context, namespace, rookImage v *CephCSIVersion err error ) + + if err = setParams(context.Clientset); err != nil { + logger.Errorf("failed to configure CSI parameters. %v", err) + return + } + + if err = validateCSIParam(); err != nil { + logger.Errorf("failed to validate CSI parameters. %v", err) + return + } + if !AllowUnsupported && CSIEnabled() { if v, err = validateCSIVersion(context.Clientset, namespace, rookImage, securityAccount, ownerInfo); err != nil { logger.Errorf("invalid csi version. %+v", err) @@ -57,7 +68,7 @@ func ValidateAndConfigureDrivers(context *clusterd.Context, namespace, rookImage stopDrivers(context.Clientset, namespace, serverVersion) } -func SetParams(clientset kubernetes.Interface) error { +func setParams(clientset kubernetes.Interface) error { var err error csiEnableRBD, err := k8sutil.GetOperatorSetting(clientset, controllerutil.OperatorSettingConfigMapName, "ROOK_CSI_ENABLE_RBD", "true") diff --git a/pkg/operator/ceph/csi/spec.go b/pkg/operator/ceph/csi/spec.go index a1dd3a85b..80592acb5 100644 --- a/pkg/operator/ceph/csi/spec.go +++ b/pkg/operator/ceph/csi/spec.go @@ -189,7 +189,7 @@ func CSIEnabled() bool { return EnableRBD || EnableCephFS } -func ValidateCSIParam() error { +func validateCSIParam() error { if len(CSIParam.CSIPluginImage) == 0 { return errors.New("missing csi rbd plugin image") diff --git a/pkg/operator/ceph/operator.go b/pkg/operator/ceph/operator.go index 459e8bc4e..85be89ebe 100644 --- a/pkg/operator/ceph/operator.go +++ b/pkg/operator/ceph/operator.go @@ -240,10 +240,6 @@ func (o *Operator) updateDrivers() error { return errors.Wrap(err, "error getting server version") } - if err = csi.SetParams(o.context.Clientset); err != nil { - return errors.Wrap(err, "failed to configure CSI parameters") - } - if serverVersion.Major < csi.KubeMinMajor || serverVersion.Major == csi.KubeMinMajor && serverVersion.Minor < csi.ProvDeploymentSuppVersion { logger.Infof("CSI drivers only supported in K8s 1.14 or newer. version=%s", serverVersion.String()) // disable csi control variables to disable other csi functions @@ -269,10 +265,6 @@ func (o *Operator) updateDrivers() error { return errors.Wrap(err, "failed creating csi config map") } - if err = csi.ValidateCSIParam(); err != nil { - return errors.Wrap(err, "invalid csi params") - } - go csi.ValidateAndConfigureDrivers(o.context, o.operatorNamespace, o.rookImage, o.securityAccount, serverVersion, ownerInfo) return nil }