diff --git a/Documentation/ceph-pool-crd.md b/Documentation/ceph-pool-crd.md index f310830f9..b5068db73 100644 --- a/Documentation/ceph-pool-crd.md +++ b/Documentation/ceph-pool-crd.md @@ -70,8 +70,6 @@ When creating an erasure-coded pool, it is highly recommended to create the pool * `replicated`: Settings for a replicated pool. If specified, `erasureCoded` settings must not be specified. * `size`: The desired number of copies to make of the data in the pool. - * `targetSizeRatio:` gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity of a given pool, for more info see the [ceph documentation](https://docs.ceph.com/docs/master/rados/operations/placement-groups/#specifying-expected-pool-size) - * `requireSafeReplicaSize`: set to false if you want to create a pool with size 1, setting pool size 1 could lead to data loss without recovery. Make sure you are *ABSOLUTELY CERTAIN* that is what you want. * `erasureCoded`: Settings for an erasure-coded pool. If specified, `replicated` settings must not be specified. See below for more details on [erasure coding](#erasure-coding). * `dataChunks`: Number of chunks to divide the original object into * `codingChunks`: Number of coding chunks to generate @@ -83,7 +81,29 @@ When creating an erasure-coded pool, it is highly recommended to create the pool > **NOTE**: Neither Rook, nor Ceph, prevent the creation of a cluster where the replicated data (or Erasure Coded chunks) can be written safely. By design, Ceph will delay checking for suitable OSDs until a write request is made and this write can hang if there are not sufficient OSDs to satisfy the request. * `deviceClass`: Sets up the CRUSH rule for the pool to distribute data only on the specified device class. If left empty or unspecified, the pool will use the cluster's default CRUSH root, which usually distributes data over all OSDs, regardless of their class. * `crushRoot`: The root in the crush map to be used by the pool. If left empty or unspecified, the default root will be used. Creating a crush hierarchy for the OSDs currently requires the Rook toolbox to run the Ceph tools described [here](http://docs.ceph.com/docs/master/rados/operations/crush-map/#modifying-the-crush-map). -* `compressionMode`: Sets up the pool for inline compression when using a Bluestore OSD. If left unspecified does not setup any compression mode for the pool. Values supported are the same as Bluestore inline compression [modes](https://docs.ceph.com/docs/master/rados/configuration/bluestore-config-ref/#inline-compression), such as `none`, `passive`, `aggressive`, and `force`. + +* `parameters`: Sets any [parameters](https://docs.ceph.com/docs/master/rados/operations/pools/#set-pool-values) listed to the given pool + * `target_size_ratio:` gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity of a given pool, for more info see the [ceph documentation](https://docs.ceph.com/docs/master/rados/operations/placement-groups/#specifying-expected-pool-size) + * `requireSafeReplicaSize`: set to false if you want to create a pool with size 1, setting pool size 1 could lead to data loss without recovery. Make sure you are *ABSOLUTELY CERTAIN* that is what you want. + * `compression_mode`: Sets up the pool for inline compression when using a Bluestore OSD. If left unspecified does not setup any compression mode for the pool. Values supported are the same as Bluestore inline compression [modes](https://docs.ceph.com/docs/master/rados/configuration/bluestore-config-ref/#inline-compression), such as `none`, `passive`, `aggressive`, and `force`. + +### Add specific pool properties + +With `poolProperties` you can set any pool property: + +```yaml +spec: + parameters: + : +``` + +For instance: + +```yaml +spec: + parameters: + min_size: 1 +``` ### Erasure Coding diff --git a/PendingReleaseNotes.md b/PendingReleaseNotes.md index 449d14f6b..d4d9e17a1 100644 --- a/PendingReleaseNotes.md +++ b/PendingReleaseNotes.md @@ -9,6 +9,7 @@ - Added a [toolbox job](Documentation/ceph-toolbox.md#toolbox-job) for running a script with Ceph commands, similar to running commands in the Rook toolbox. - Ceph RBD Mirror daemon has been extracted to its own CRD, it has been removed from the `CephCluster` CRD, see the [rbd-mirror crd](Documentation/ceph-rbd-mirror-crd.html). - CephCluster CRD has been converted to use the controller-runtime framework. +- CephBlockPool CRD has a new field called `parameters` which allows to set any property on a given [pool](Documentation/ceph-pool-crd.html#add-specific-pool-properties) ### EdgeFS diff --git a/cluster/charts/rook-ceph/templates/resources.yaml b/cluster/charts/rook-ceph/templates/resources.yaml index 4ae24fbe0..76af0b1a3 100644 --- a/cluster/charts/rook-ceph/templates/resources.yaml +++ b/cluster/charts/rook-ceph/templates/resources.yaml @@ -528,6 +528,8 @@ spec: - passive - aggressive - force + parameters: + type: object subresources: status: {} --- diff --git a/cluster/examples/kubernetes/ceph/common.yaml b/cluster/examples/kubernetes/ceph/common.yaml index a9b7fc281..211a94c46 100644 --- a/cluster/examples/kubernetes/ceph/common.yaml +++ b/cluster/examples/kubernetes/ceph/common.yaml @@ -612,6 +612,8 @@ spec: - passive - aggressive - force + parameters: + type: object subresources: status: {} # OLM: END CEPH BLOCK POOL CRD diff --git a/cluster/examples/kubernetes/ceph/filesystem.yaml b/cluster/examples/kubernetes/ceph/filesystem.yaml index aeec7c140..12b4a81de 100644 --- a/cluster/examples/kubernetes/ceph/filesystem.yaml +++ b/cluster/examples/kubernetes/ceph/filesystem.yaml @@ -15,6 +15,13 @@ spec: replicated: size: 3 requireSafeReplicaSize: true + parameters: + # Inline compression mode for the data pool + # Further reference: https://docs.ceph.com/docs/nautilus/rados/configuration/bluestore-config-ref/#inline-compression + compression_mode: none + # gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity of a given pool + # for more info: https://docs.ceph.com/docs/master/rados/operations/placement-groups/#specifying-expected-pool-size + #target_size_ratio: .5 # The list of data pool specs. Can use replication or erasure coding. dataPools: - failureDomain: host @@ -26,9 +33,13 @@ spec: # gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity of a given pool # for more info: https://docs.ceph.com/docs/master/rados/operations/placement-groups/#specifying-expected-pool-size #targetSizeRatio: .5 - # Inline compression mode for the data pool - # Further reference: https://docs.ceph.com/docs/nautilus/rados/configuration/bluestore-config-ref/#inline-compression - compressionMode: none + parameters: + # Inline compression mode for the data pool + # Further reference: https://docs.ceph.com/docs/nautilus/rados/configuration/bluestore-config-ref/#inline-compression + compression_mode: none + # gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity of a given pool + # for more info: https://docs.ceph.com/docs/master/rados/operations/placement-groups/#specifying-expected-pool-size + #target_size_ratio: .5 # Whether to preserve metadata and data pools on filesystem deletion preservePoolsOnDelete: true # The metadata service (mds) configuration diff --git a/cluster/examples/kubernetes/ceph/object.yaml b/cluster/examples/kubernetes/ceph/object.yaml index a3ef991f2..53a9a840c 100644 --- a/cluster/examples/kubernetes/ceph/object.yaml +++ b/cluster/examples/kubernetes/ceph/object.yaml @@ -18,9 +18,13 @@ spec: # Disallow setting pool with replica 1, this could lead to data loss without recovery. # Make sure you're *ABSOLUTELY CERTAIN* that is what you want requireSafeReplicaSize: true + parameters: + # Inline compression mode for the data pool + # Further reference: https://docs.ceph.com/docs/nautilus/rados/configuration/bluestore-config-ref/#inline-compression + compression_mode: none # gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity of a given pool # for more info: https://docs.ceph.com/docs/master/rados/operations/placement-groups/#specifying-expected-pool-size - #targetSizeRatio: .5 + #target_size_ratio: .5 # The pool spec used to create the data pool. Can use replication or erasure coding. dataPool: failureDomain: host @@ -29,12 +33,13 @@ spec: # Disallow setting pool with replica 1, this could lead to data loss without recovery. # Make sure you're *ABSOLUTELY CERTAIN* that is what you want requireSafeReplicaSize: true + parameters: + # Inline compression mode for the data pool + # Further reference: https://docs.ceph.com/docs/nautilus/rados/configuration/bluestore-config-ref/#inline-compression + compression_mode: none # gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity of a given pool # for more info: https://docs.ceph.com/docs/master/rados/operations/placement-groups/#specifying-expected-pool-size - #targetSizeRatio: .5 - # Inline compression mode for the data pool - # Further reference: https://docs.ceph.com/docs/nautilus/rados/configuration/bluestore-config-ref/#inline-compression - compressionMode: none + #target_size_ratio: .5 # Whether to preserve metadata and data pools on object store deletion preservePoolsOnDelete: false # The gateway service configuration diff --git a/cluster/examples/kubernetes/ceph/pool-ec.yaml b/cluster/examples/kubernetes/ceph/pool-ec.yaml index 64d1e8d1f..d6b363b81 100644 --- a/cluster/examples/kubernetes/ceph/pool-ec.yaml +++ b/cluster/examples/kubernetes/ceph/pool-ec.yaml @@ -16,8 +16,11 @@ spec: erasureCoded: dataChunks: 2 codingChunks: 1 - # Inline compression mode for the data pool - compressionMode: none + # Set any property on a given pool + # see https://docs.ceph.com/docs/master/rados/operations/pools/#set-pool-values + parameters: + # Inline compression mode for the data pool + compression_mode: none # A key/value list of annotations annotations: # key: value diff --git a/cluster/examples/kubernetes/ceph/pool.yaml b/cluster/examples/kubernetes/ceph/pool.yaml index 44325388d..84b232c96 100644 --- a/cluster/examples/kubernetes/ceph/pool.yaml +++ b/cluster/examples/kubernetes/ceph/pool.yaml @@ -18,18 +18,21 @@ spec: # Disallow setting pool with replica 1, this could lead to data loss without recovery. # Make sure you're *ABSOLUTELY CERTAIN* that is what you want requireSafeReplicaSize: true - # gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity of a given pool - # for more info: https://docs.ceph.com/docs/master/rados/operations/placement-groups/#specifying-expected-pool-size - #targetSizeRatio: .5 # Ceph CRUSH root location of the rule # For reference: https://docs.ceph.com/docs/nautilus/rados/operations/crush-map/#types-and-buckets #crushRoot: my-root # The Ceph CRUSH device class associated with the CRUSH replicated rule # For reference: https://docs.ceph.com/docs/nautilus/rados/operations/crush-map/#device-classes #deviceClass: my-class - # Inline compression mode for the data pool - # Further reference: https://docs.ceph.com/docs/nautilus/rados/configuration/bluestore-config-ref/#inline-compression - compressionMode: none + # Set any property on a given pool + # see https://docs.ceph.com/docs/master/rados/operations/pools/#set-pool-values + parameters: + # Inline compression mode for the data pool + # Further reference: https://docs.ceph.com/docs/nautilus/rados/configuration/bluestore-config-ref/#inline-compression + compression_mode: none + # gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity of a given pool + # for more info: https://docs.ceph.com/docs/master/rados/operations/placement-groups/#specifying-expected-pool-size + #target_size_ratio: .5 # A key/value list of annotations annotations: # key: value diff --git a/pkg/apis/ceph.rook.io/v1/blockpool.go b/pkg/apis/ceph.rook.io/v1/blockpool.go index fd29c595b..3d50cef40 100644 --- a/pkg/apis/ceph.rook.io/v1/blockpool.go +++ b/pkg/apis/ceph.rook.io/v1/blockpool.go @@ -23,3 +23,11 @@ func (p *PoolSpec) IsReplicated() bool { func (p *PoolSpec) IsErasureCoded() bool { return p.ErasureCoded.CodingChunks > 0 || p.ErasureCoded.DataChunks > 0 } + +func (p *PoolSpec) IsCompressionEnabled() bool { + return p.CompressionMode != "" +} + +func (p *ReplicatedSpec) IsTargetRatioEnabled() bool { + return p.TargetSizeRatio != 0 +} diff --git a/pkg/apis/ceph.rook.io/v1/types.go b/pkg/apis/ceph.rook.io/v1/types.go index fabcf0331..54cf89fdd 100755 --- a/pkg/apis/ceph.rook.io/v1/types.go +++ b/pkg/apis/ceph.rook.io/v1/types.go @@ -269,6 +269,9 @@ type PoolSpec struct { // The erasure code settings ErasureCoded ErasureCodedSpec `json:"erasureCoded"` + + // Parameters is a list of properties to enable on a given pool + Parameters map[string]string `json:"parameters,omitempty"` } type Status struct { diff --git a/pkg/apis/ceph.rook.io/v1/zz_generated.deepcopy.go b/pkg/apis/ceph.rook.io/v1/zz_generated.deepcopy.go index 04e5de5cb..59c0484aa 100644 --- a/pkg/apis/ceph.rook.io/v1/zz_generated.deepcopy.go +++ b/pkg/apis/ceph.rook.io/v1/zz_generated.deepcopy.go @@ -31,7 +31,7 @@ func (in *CephBlockPool) DeepCopyInto(out *CephBlockPool) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec + in.Spec.DeepCopyInto(&out.Spec) if in.Status != nil { in, out := &in.Status, &out.Status *out = new(Status) @@ -1041,11 +1041,13 @@ func (in *ExternalSpec) DeepCopy() *ExternalSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *FilesystemSpec) DeepCopyInto(out *FilesystemSpec) { *out = *in - out.MetadataPool = in.MetadataPool + in.MetadataPool.DeepCopyInto(&out.MetadataPool) if in.DataPools != nil { in, out := &in.DataPools, &out.DataPools *out = make([]PoolSpec, len(*in)) - copy(*out, *in) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } in.MetadataServer.DeepCopyInto(&out.MetadataServer) return @@ -1280,8 +1282,8 @@ func (in *ObjectRealmSpec) DeepCopy() *ObjectRealmSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ObjectStoreSpec) DeepCopyInto(out *ObjectStoreSpec) { *out = *in - out.MetadataPool = in.MetadataPool - out.DataPool = in.DataPool + in.MetadataPool.DeepCopyInto(&out.MetadataPool) + in.DataPool.DeepCopyInto(&out.DataPool) in.Gateway.DeepCopyInto(&out.Gateway) out.Zone = in.Zone return @@ -1350,6 +1352,13 @@ func (in *PoolSpec) DeepCopyInto(out *PoolSpec) { *out = *in out.Replicated = in.Replicated out.ErasureCoded = in.ErasureCoded + if in.Parameters != nil { + in, out := &in.Parameters, &out.Parameters + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } return } diff --git a/pkg/daemon/ceph/client/pool.go b/pkg/daemon/ceph/client/pool.go index 2e8c83278..bd62ea787 100644 --- a/pkg/daemon/ceph/client/pool.go +++ b/pkg/daemon/ceph/client/pool.go @@ -28,8 +28,12 @@ import ( ) const ( - confirmFlag = "--yes-i-really-mean-it" - reallyConfirmFlag = "--yes-i-really-really-mean-it" + confirmFlag = "--yes-i-really-mean-it" + reallyConfirmFlag = "--yes-i-really-really-mean-it" + targetSizeRatioProperty = "target_size_ratio" + compressionModeProperty = "compression_mode" + PgAutoscaleModeProperty = "pg_autoscale_mode" + PgAutoscaleModeOn = "on" ) type CephStoragePoolSummary struct { @@ -232,11 +236,23 @@ func givePoolAppTag(context *clusterd.Context, namespace string, poolName string } func setCommonPoolProperties(context *clusterd.Context, pool cephv1.PoolSpec, namespace, poolName, appName string) error { - compressionModeProperty := "compression_mode" - if pool.CompressionMode != "" { - err := SetPoolProperty(context, namespace, poolName, compressionModeProperty, pool.CompressionMode) + if len(pool.Parameters) == 0 { + pool.Parameters = make(map[string]string) + } + + if pool.Replicated.IsTargetRatioEnabled() { + pool.Parameters[targetSizeRatioProperty] = strconv.FormatFloat(pool.Replicated.TargetSizeRatio, 'f', -1, 32) + } + + if pool.IsCompressionEnabled() { + pool.Parameters[compressionModeProperty] = pool.CompressionMode + } + + // Apply properties + for propName, propValue := range pool.Parameters { + err := SetPoolProperty(context, namespace, poolName, propName, propValue) if err != nil { - return errors.Wrapf(err, "failed to set property %q on pool %q to %q", compressionModeProperty, poolName, pool.CompressionMode) + logger.Errorf("failed to set property %q to pool %q to %q. %v", propName, poolName, propValue, err) } } @@ -289,18 +305,10 @@ func CreateReplicatedPoolForApp(context *clusterd.Context, namespace, poolName s } // the pool is type replicated, set the size for the pool now that it's been created - if err = SetPoolReplicatedSizeProperty(context, namespace, poolName, strconv.FormatUint(uint64(pool.Replicated.Size), 10)); err != nil { + if err := SetPoolReplicatedSizeProperty(context, namespace, poolName, strconv.FormatUint(uint64(pool.Replicated.Size), 10)); err != nil { return errors.Wrapf(err, "failed to set size property to replicated pool %q to %d", poolName, pool.Replicated.Size) } - targetSizeRatioProperty := "target_size_ratio" - if pool.Replicated.TargetSizeRatio != 0 { - err = SetPoolProperty(context, namespace, poolName, targetSizeRatioProperty, strconv.FormatFloat(pool.Replicated.TargetSizeRatio, 'f', -1, 32)) - if err != nil { - return errors.Wrapf(err, "failed to set property %q to replicated pool %q to %.2f", targetSizeRatioProperty, poolName, pool.Replicated.TargetSizeRatio) - } - } - if err = setCommonPoolProperties(context, pool, namespace, poolName, appName); err != nil { return err } @@ -339,9 +347,10 @@ func createReplicationCrushRule(context *clusterd.Context, namespace, ruleName s // SetPoolProperty sets a property to a given pool func SetPoolProperty(context *clusterd.Context, namespace, name, propName, propVal string) error { args := []string{"osd", "pool", "set", name, propName, propVal} + logger.Infof("setting pool property %q to %q on pool %q", propName, propVal, name) _, err := NewCephCommand(context, namespace, args).Run() if err != nil { - return errors.Wrapf(err, "failed to set pool property %s on pool %s", propName, name) + return errors.Wrapf(err, "failed to set pool property %q on pool %q", propName, name) } return nil } diff --git a/pkg/operator/ceph/cluster/crash/reconcile.go b/pkg/operator/ceph/cluster/crash/reconcile.go index e68d2e03c..236e67032 100644 --- a/pkg/operator/ceph/cluster/crash/reconcile.go +++ b/pkg/operator/ceph/cluster/crash/reconcile.go @@ -26,10 +26,8 @@ import ( appsv1 "k8s.io/api/apps/v1" kerrors "k8s.io/apimachinery/pkg/api/errors" - "github.com/rook/rook/pkg/operator/ceph/controller" "github.com/rook/rook/pkg/operator/ceph/file/mds" "github.com/rook/rook/pkg/operator/ceph/object" - "github.com/rook/rook/pkg/operator/ceph/version" "github.com/coreos/pkg/capnslog" @@ -41,6 +39,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" + opcontroller "github.com/rook/rook/pkg/operator/ceph/controller" "github.com/rook/rook/pkg/operator/ceph/disruption/controllerconfig" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -163,7 +162,7 @@ func (r *ReconcileNode) reconcile(request reconcile.Request) (reconcile.Result, } clusterImage := cephCluster.Spec.CephVersion.Image - cephVersion, err := getImageVersion(cephCluster) + cephVersion, err := opcontroller.GetImageVersion(cephCluster) if err != nil { logger.Errorf("ceph version not found for image %q used by cluster %q. %v", clusterImage, cephCluster.Name, err) return reconcile.Result{}, nil @@ -212,18 +211,6 @@ func (r *ReconcileNode) cephPodList() ([]corev1.Pod, error) { return cephPods, nil } -// getImageVersion returns the CephVersion registered for a specified image (if any) and whether any image was found. -func getImageVersion(cephCluster cephv1.CephCluster) (*version.CephVersion, error) { - // If the Ceph cluster has not yet recorded the image and version for the current image in its spec, then the Crash - // controller should wait for the version to be detected. - if cephCluster.Status.CephVersion != nil && cephCluster.Spec.CephVersion.Image == cephCluster.Status.CephVersion.Image { - logger.Debugf("ceph version found %q", cephCluster.Status.CephVersion.Version) - return controller.ExtractCephVersionFromLabel(cephCluster.Status.CephVersion.Version) - } - - return nil, errors.New("attempt to determine ceph version for the current cluster image timed out") -} - func (r *ReconcileNode) deleteCrashCollector(deployment appsv1.Deployment) error { deploymentName := deployment.ObjectMeta.Name namespace := deployment.ObjectMeta.Namespace diff --git a/pkg/operator/ceph/cluster/mgr/mgr.go b/pkg/operator/ceph/cluster/mgr/mgr.go index dd9e9ee4b..cbdc3ba6f 100644 --- a/pkg/operator/ceph/cluster/mgr/mgr.go +++ b/pkg/operator/ceph/cluster/mgr/mgr.go @@ -52,7 +52,7 @@ const ( serviceAccountName = "rook-ceph-mgr" prometheusModuleName = "prometheus" crashModuleName = "crash" - pgautoscalerModuleName = "pg_autoscaler" + PgautoscalerModuleName = "pg_autoscaler" balancerModuleName = "balancer" balancerModuleMode = "upmap" metricsPort = 9283 @@ -322,7 +322,7 @@ func (c *Cluster) configureMgrModules() error { } // Configure special settings for individual modules that are enabled - if module.Name == pgautoscalerModuleName { + if module.Name == PgautoscalerModuleName { monStore := config.GetMonStore(c.context, c.Namespace) // Ceph Octopus will have that option enabled err := monStore.Set("global", "osd_pool_default_pg_autoscale_mode", "on") @@ -406,3 +406,14 @@ func (c *Cluster) deployPrometheusRule(name, namespace string) error { } return nil } + +// IsModuleInSpec returns whether a module is present in the CephCluster manager spec +func IsModuleInSpec(modules []cephv1.Module, moduleName string) bool { + for _, v := range modules { + if v.Name == moduleName { + return true + } + } + + return false +} diff --git a/pkg/operator/ceph/cluster/rbd/controller.go b/pkg/operator/ceph/cluster/rbd/controller.go index 02eecbf10..aa1014ab6 100644 --- a/pkg/operator/ceph/cluster/rbd/controller.go +++ b/pkg/operator/ceph/cluster/rbd/controller.go @@ -155,12 +155,12 @@ func (r *ReconcileCephRBDMirror) reconcile(request reconcile.Request) (reconcile } // Make sure a CephCluster is present otherwise do nothing - cephClusterSpec, isReadyToReconcile, _, reconcileResponse := opcontroller.IsReadyToReconcile(r.client, r.context, request.NamespacedName, controllerName) + cephCluster, isReadyToReconcile, _, reconcileResponse := opcontroller.IsReadyToReconcile(r.client, r.context, request.NamespacedName, controllerName) if !isReadyToReconcile { logger.Debugf("CephCluster resource not ready in namespace %q, retrying in %q.", request.NamespacedName.Namespace, reconcileResponse.RequeueAfter.String()) return reconcileResponse, nil } - r.cephClusterSpec = &cephClusterSpec + r.cephClusterSpec = &cephCluster.Spec // Populate clusterInfo // Always populate it during each reconcile diff --git a/pkg/operator/ceph/controller/controller_utils.go b/pkg/operator/ceph/controller/controller_utils.go index 3dfd58d07..e36ea2dd3 100644 --- a/pkg/operator/ceph/controller/controller_utils.go +++ b/pkg/operator/ceph/controller/controller_utils.go @@ -46,7 +46,7 @@ var ( ) // IsReadyToReconcile determines if a controller is ready to reconcile or not -func IsReadyToReconcile(c client.Client, clustercontext *clusterd.Context, namespacedName types.NamespacedName, controllerName string) (cephv1.ClusterSpec, bool, bool, reconcile.Result) { +func IsReadyToReconcile(c client.Client, clustercontext *clusterd.Context, namespacedName types.NamespacedName, controllerName string) (cephv1.CephCluster, bool, bool, reconcile.Result) { cephClusterExists := false // Running ceph commands won't work and the controller will keep re-queuing so I believe it's fine not to check @@ -56,11 +56,11 @@ func IsReadyToReconcile(c client.Client, clustercontext *clusterd.Context, names err := c.List(context.TODO(), clusterList, client.InNamespace(namespacedName.Namespace)) if err != nil { logger.Errorf("%q:failed to fetch CephCluster %v", controllerName, err) - return cephv1.ClusterSpec{}, false, cephClusterExists, ImmediateRetryResult + return cephCluster, false, cephClusterExists, ImmediateRetryResult } if len(clusterList.Items) == 0 { logger.Errorf("%q: no CephCluster resource found in namespace %q", controllerName, namespacedName.Namespace) - return cephv1.ClusterSpec{}, false, cephClusterExists, WaitForRequeueIfCephClusterNotReady + return cephCluster, false, cephClusterExists, WaitForRequeueIfCephClusterNotReady } cephClusterExists = true cephCluster = clusterList.Items[0] @@ -74,21 +74,21 @@ func IsReadyToReconcile(c client.Client, clustercontext *clusterd.Context, names if err != nil { if strings.Contains(err.Error(), "error calling conf_read_file") { logger.Infof("%q: operator is not ready to run ceph command, cannot reconcile yet.", controllerName) - return cephCluster.Spec, false, cephClusterExists, WaitForRequeueIfCephClusterNotReady + return cephCluster, false, cephClusterExists, WaitForRequeueIfCephClusterNotReady } // We should not arrive there logger.Errorf("%q: ceph command error %v", controllerName, err) - return cephCluster.Spec, false, cephClusterExists, ImmediateRetryResult + return cephCluster, false, cephClusterExists, ImmediateRetryResult } // If Ceph status is ok we can reconcile if status.Health.Status == "HEALTH_OK" || status.Health.Status == "HEALTH_WARN" { logger.Debugf("%q: ceph status is %q, operator is ready to run ceph command, reconciling", controllerName, status.Health.Status) - return cephCluster.Spec, true, cephClusterExists, reconcile.Result{} + return cephCluster, true, cephClusterExists, reconcile.Result{} } logger.Infof("%s: CephCluster %q found but skipping reconcile since Ceph health is %q", controllerName, cephCluster.Name, status.Health.Status) - return cephCluster.Spec, false, cephClusterExists, WaitForRequeueIfCephClusterNotReady + return cephCluster, false, cephClusterExists, WaitForRequeueIfCephClusterNotReady } // ClusterOwnerRef represents the owner reference of the CephCluster CR diff --git a/pkg/operator/ceph/controller/version.go b/pkg/operator/ceph/controller/version.go index 6be6e3ebd..125c2eb7c 100644 --- a/pkg/operator/ceph/controller/version.go +++ b/pkg/operator/ceph/controller/version.go @@ -18,6 +18,7 @@ package controller import ( "github.com/pkg/errors" + cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" "github.com/rook/rook/pkg/clusterd" "github.com/rook/rook/pkg/daemon/ceph/client" cephver "github.com/rook/rook/pkg/operator/ceph/version" @@ -34,3 +35,15 @@ func ValidateCephVersionsBetweenLocalAndExternalClusters(context *clusterd.Conte return *externalVersion, cephver.ValidateCephVersionsBetweenLocalAndExternalClusters(localVersion, *externalVersion) } + +// GetImageVersion returns the CephVersion registered for a specified image (if any) and whether any image was found. +func GetImageVersion(cephCluster cephv1.CephCluster) (*cephver.CephVersion, error) { + // If the Ceph cluster has not yet recorded the image and version for the current image in its spec, then the Crash + // controller should wait for the version to be detected. + if cephCluster.Status.CephVersion != nil && cephCluster.Spec.CephVersion.Image == cephCluster.Status.CephVersion.Image { + logger.Debugf("ceph version found %q", cephCluster.Status.CephVersion.Version) + return ExtractCephVersionFromLabel(cephCluster.Status.CephVersion.Version) + } + + return nil, errors.New("attempt to determine ceph version for the current cluster image timed out") +} diff --git a/pkg/operator/ceph/file/controller.go b/pkg/operator/ceph/file/controller.go index 6293c5520..68fa5a8e5 100644 --- a/pkg/operator/ceph/file/controller.go +++ b/pkg/operator/ceph/file/controller.go @@ -156,7 +156,7 @@ func (r *ReconcileCephFilesystem) reconcile(request reconcile.Request) (reconcil } // Make sure a CephCluster is present otherwise do nothing - cephClusterSpec, isReadyToReconcile, cephClusterExists, reconcileResponse := opcontroller.IsReadyToReconcile(r.client, r.context, request.NamespacedName, controllerName) + cephCluster, isReadyToReconcile, cephClusterExists, reconcileResponse := opcontroller.IsReadyToReconcile(r.client, r.context, request.NamespacedName, controllerName) if !isReadyToReconcile { // This handles the case where the Ceph Cluster is gone and we want to delete that CR // We skip the deleteFilesystem() function since everything is gone already @@ -176,7 +176,7 @@ func (r *ReconcileCephFilesystem) reconcile(request reconcile.Request) (reconcil } return reconcileResponse, nil } - r.cephClusterSpec = &cephClusterSpec + r.cephClusterSpec = &cephCluster.Spec // Populate clusterInfo // Always populate it during each reconcile diff --git a/pkg/operator/ceph/nfs/controller.go b/pkg/operator/ceph/nfs/controller.go index 84c7d7a29..b114f53ec 100644 --- a/pkg/operator/ceph/nfs/controller.go +++ b/pkg/operator/ceph/nfs/controller.go @@ -155,7 +155,7 @@ func (r *ReconcileCephNFS) reconcile(request reconcile.Request) (reconcile.Resul } // Make sure a CephCluster is present otherwise do nothing - cephClusterSpec, isReadyToReconcile, cephClusterExists, reconcileResponse := opcontroller.IsReadyToReconcile(r.client, r.context, request.NamespacedName, controllerName) + cephCluster, isReadyToReconcile, cephClusterExists, reconcileResponse := opcontroller.IsReadyToReconcile(r.client, r.context, request.NamespacedName, controllerName) if !isReadyToReconcile { // This handles the case where the Ceph Cluster is gone and we want to delete that CR // We skip the deleteStore() function since everything is gone already @@ -175,7 +175,7 @@ func (r *ReconcileCephNFS) reconcile(request reconcile.Request) (reconcile.Resul } return reconcileResponse, nil } - r.cephClusterSpec = &cephClusterSpec + r.cephClusterSpec = &cephCluster.Spec // Populate clusterInfo // Always populate it during each reconcile diff --git a/pkg/operator/ceph/object/controller.go b/pkg/operator/ceph/object/controller.go index 9e0748cc1..f061507e2 100644 --- a/pkg/operator/ceph/object/controller.go +++ b/pkg/operator/ceph/object/controller.go @@ -165,7 +165,7 @@ func (r *ReconcileCephObjectStore) reconcile(request reconcile.Request) (reconci } // Make sure a CephCluster is present otherwise do nothing - cephClusterSpec, isReadyToReconcile, cephClusterExists, reconcileResponse := opcontroller.IsReadyToReconcile(r.client, r.context, request.NamespacedName, controllerName) + cephCluster, isReadyToReconcile, cephClusterExists, reconcileResponse := opcontroller.IsReadyToReconcile(r.client, r.context, request.NamespacedName, controllerName) if !isReadyToReconcile { // This handles the case where the Ceph Cluster is gone and we want to delete that CR // We skip the deleteStore() function since everything is gone already @@ -186,7 +186,7 @@ func (r *ReconcileCephObjectStore) reconcile(request reconcile.Request) (reconci return reconcileResponse, nil } - r.cephClusterSpec = &cephClusterSpec + r.cephClusterSpec = &cephCluster.Spec // Populate clusterInfo // Always populate it during each reconcile diff --git a/pkg/operator/ceph/pool/controller.go b/pkg/operator/ceph/pool/controller.go index e1630a409..292e7b17c 100644 --- a/pkg/operator/ceph/pool/controller.go +++ b/pkg/operator/ceph/pool/controller.go @@ -28,6 +28,7 @@ import ( "github.com/pkg/errors" cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" "github.com/rook/rook/pkg/clusterd" + "github.com/rook/rook/pkg/operator/ceph/cluster/mgr" opcontroller "github.com/rook/rook/pkg/operator/ceph/controller" "github.com/rook/rook/pkg/operator/k8sutil" kerrors "k8s.io/apimachinery/pkg/api/errors" @@ -137,7 +138,7 @@ func (r *ReconcileCephBlockPool) reconcile(request reconcile.Request) (reconcile } // Make sure a CephCluster is present otherwise do nothing - _, isReadyToReconcile, cephClusterExists, reconcileResponse := opcontroller.IsReadyToReconcile(r.client, r.context, request.NamespacedName, controllerName) + cephCluster, isReadyToReconcile, cephClusterExists, reconcileResponse := opcontroller.IsReadyToReconcile(r.client, r.context, request.NamespacedName, controllerName) if !isReadyToReconcile { // This handles the case where the Ceph Cluster is gone and we want to delete that CR // We skip the deletePool() function since everything is gone already @@ -189,6 +190,24 @@ func (r *ReconcileCephBlockPool) reconcile(request reconcile.Request) (reconcile updateStatus(r.client, request.NamespacedName, k8sutil.ReconcilingStatus) + // Get CephCluster version + cephVersion, err := opcontroller.GetImageVersion(cephCluster) + if err != nil { + return reconcile.Result{}, errors.Wrapf(err, "failed to fetch ceph version from cephcluster %q", cephCluster.Name) + } + + // If the CephCluster has enabled the "pg_autoscaler" module and is running Nautilus + // we force the pg_autoscale_mode to "on" + _, propertyExists := cephBlockPool.Spec.Parameters[cephclient.PgAutoscaleModeProperty] + if mgr.IsModuleInSpec(cephCluster.Spec.Mgr.Modules, mgr.PgautoscalerModuleName) && + !cephVersion.IsAtLeastOctopus() && + !propertyExists { + if len(cephBlockPool.Spec.Parameters) == 0 { + cephBlockPool.Spec.Parameters = make(map[string]string) + } + cephBlockPool.Spec.Parameters[cephclient.PgAutoscaleModeProperty] = cephclient.PgAutoscaleModeOn + } + // CREATE/UPDATE reconcileResponse, err = r.reconcileCreatePool(cephBlockPool) if err != nil { diff --git a/pkg/operator/ceph/pool/controller_test.go b/pkg/operator/ceph/pool/controller_test.go index 928d0e442..2cfe7bf5f 100644 --- a/pkg/operator/ceph/pool/controller_test.go +++ b/pkg/operator/ceph/pool/controller_test.go @@ -320,6 +320,9 @@ func TestCephBlockPoolController(t *testing.T) { }, Status: cephv1.ClusterStatus{ Phase: "", + CephVersion: &cephv1.ClusterVersion{ + Version: "14.2.9-0", + }, }, } diff --git a/tests/framework/installer/ceph_manifests_v1.2.go b/tests/framework/installer/ceph_manifests_v1.2.go index 818677063..30d8e60da 100644 --- a/tests/framework/installer/ceph_manifests_v1.2.go +++ b/tests/framework/installer/ceph_manifests_v1.2.go @@ -1747,7 +1747,9 @@ spec: size: ` + replicaSize + ` targetSizeRatio: .5 requireSafeReplicaSize: false - compressionMode: aggressive` + compressionMode: aggressive + poolProperties: + pg_autoscale_mode: on` } func (m *CephManifestsV1_2) GetBlockStorageClassDef(csi bool, poolName, storageClassName, reclaimPolicy, namespace, systemNamespace string) string {