Files
my-rook-config/pkg/operator/ceph/pool/validate.go
T
Sébastien Han 451622a955 ceph: add rbd-mirror configuration
Rook is now capable of configuring mirroring between sites. The
implementation works at different levels:

* CephBlockPool: which introduces a new `mirroring` configuration as well
as `statusCheck`. When turned on, Rook will enable mirroring on the
pool. It will also create a bootstrap peer token and store it in a
Kubernetes Secret. The name of that Secret can be found in the Status
field of the CephBlockPool CRD. This token can be fetched and used by
other clusters to configure the site as a peer. Mirroring can be
configured either at the pool or the image level.

* CephRBDMirror: which introduces a new `peers` configuration allowing
Rook to connect to peers by passing a Secret name. The administrator will
create a Kubernetes Secret with 2 keys: 'token' for the bootstrap peer
token and 'pool' for the name of pool. Once detected the rbd-mirror
controller will go ahead and import the peer configuration.

Pool mirroring status example:

```
status:
  info:
    rbdMirrorBootstrapPeerSecretName: pool-peer-token-test
  mirroringInfo:
    lastChanged: "2020-09-17T14:47:27Z"
    lastChecked: "2020-09-17T14:48:27Z"
    summary:
      summary:
        mode: image
        peers:
        - client_name: client.rbd-mirror-peer
          direction: rx-tx
          mirror_uuid: ""
          site_name: rhcs
          uuid: c50522a4-28a4-4bd3-ba68-e11780308882
        site_name: 91eae0dd-06b1-4d2c-91f3-1311c9df382b-rook-ceph
  mirroringStatus:
    lastChecked: "2020-09-17T14:48:27Z"
    summary:
      summary:
        daemon_health: OK
        health: OK
        image_health: OK
        states:
          replaying: 1
```

Signed-off-by: Sébastien Han <seb@redhat.com>
2020-09-17 19:05:04 +02:00

113 lines
3.1 KiB
Go

/*
Copyright 2020 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package pool to manage a rook pool.
package pool
import (
"github.com/rook/rook/pkg/daemon/ceph/client"
cephclient "github.com/rook/rook/pkg/daemon/ceph/client"
"github.com/pkg/errors"
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
"github.com/rook/rook/pkg/clusterd"
)
// ValidatePool Validate the pool arguments
func ValidatePool(context *clusterd.Context, clusterInfo *cephclient.ClusterInfo, p *cephv1.CephBlockPool) error {
if p.Name == "" {
return errors.New("missing name")
}
if p.Namespace == "" {
return errors.New("missing namespace")
}
if err := ValidatePoolSpec(context, clusterInfo, &p.Spec); err != nil {
return err
}
return nil
}
// ValidatePoolSpec validates the Ceph block pool spec CR
func ValidatePoolSpec(context *clusterd.Context, clusterInfo *client.ClusterInfo, p *cephv1.PoolSpec) error {
if p.IsReplicated() && p.IsErasureCoded() {
return errors.New("both replication and erasure code settings cannot be specified")
}
var crush cephclient.CrushMap
var err error
if p.FailureDomain != "" || p.CrushRoot != "" {
crush, err = cephclient.GetCrushMap(context, clusterInfo)
if err != nil {
return errors.Wrap(err, "failed to get crush map")
}
}
// validate the failure domain if specified
if p.FailureDomain != "" {
found := false
for _, t := range crush.Types {
if t.Name == p.FailureDomain {
found = true
break
}
}
if !found {
return errors.Errorf("unrecognized failure domain %s", p.FailureDomain)
}
}
// validate the crush root if specified
if p.CrushRoot != "" {
found := false
for _, t := range crush.Buckets {
if t.Name == p.CrushRoot {
found = true
break
}
}
if !found {
return errors.Errorf("unrecognized crush root %s", p.CrushRoot)
}
}
// validate pool replica size
if p.Replicated.Size == 1 && p.Replicated.RequireSafeReplicaSize {
return errors.Errorf("error pool size is %d and requireSafeReplicaSize is %t, must be false", p.Replicated.Size, p.Replicated.RequireSafeReplicaSize)
}
// validate pool compression mode if specified
if p.CompressionMode != "" {
switch p.CompressionMode {
case "none", "passive", "aggressive", "force":
break
default:
return errors.Errorf("unrecognized compression mode %q", p.CompressionMode)
}
}
// Validate mirroring settings
if p.Mirroring.Enabled {
switch p.Mirroring.Mode {
case "image", "pool":
break
default:
return errors.Errorf("unrecognized mirroring mode %q. only 'image and 'pool' are supported", p.Mirroring.Mode)
}
}
return nil
}