Files
my-rook-config/tests/framework/clients/rbd-mirror.go
T
Sébastien Han c1b8a7aa9e ceph: extract rbd-mirror to its own crd
Previously, the rbd-mirror daemon was integrated into the `CephCluster`
CRD. This wasn't really practical since we would have to wait for the
whole orchestration to be done to actually set it up. The same goes for
any CR update. Let's say you want to change the number of daemons, Rook
would go through mons, mgrs and osds until it get to rbd-mirror.
This triggers an undesired full orchestration.

With its own CRD this component just gains a lot more flexibility.

Closes: https://github.com/rook/rook/issues/5084
Signed-off-by: Sébastien Han <seb@redhat.com>
2020-04-15 09:12:56 +02:00

68 lines
2.4 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 clients
import (
"github.com/rook/rook/tests/framework/installer"
"github.com/rook/rook/tests/framework/utils"
"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// RBDMirrorOperation is a wrapper for k8s rook rbd mirror operations
type RBDMirrorOperation struct {
k8sh *utils.K8sHelper
manifests installer.CephManifests
}
// CreateRBDMirrorOperation Constructor to create RBDMirrorOperation - client to perform ceph rbd mirror operations on k8s
func CreateRBDMirrorOperation(k8sh *utils.K8sHelper, manifests installer.CephManifests) *RBDMirrorOperation {
return &RBDMirrorOperation{k8sh, manifests}
}
// Create creates a rbd-mirror in Rook
func (r *RBDMirrorOperation) Create(namespace, name string, daemonCount int) error {
logger.Infof("creating the RBDMirror daemons via CRD")
if err := r.k8sh.ResourceOperation("apply", r.manifests.GetRBDMirror(namespace, name, daemonCount)); err != nil {
return err
}
logger.Infof("Make sure rook-ceph-rbd-mirror pod is running")
err := r.k8sh.WaitForLabeledPodsToRun("app=rook-ceph-rbd-mirror", namespace)
assert.Nil(r.k8sh.T(), err)
assert.True(r.k8sh.T(), r.k8sh.CheckPodCountAndState("rook-ceph-rbd-mirror", namespace, daemonCount, "Running"),
"Make sure all rbd-mirror daemon pods are in Running state")
return nil
}
// Delete deletes a rbd-mirror in Rook
func (r *RBDMirrorOperation) Delete(namespace, name string) error {
options := &metav1.DeleteOptions{}
logger.Infof("Deleting rbd-mirror %s in namespace %s", name, namespace)
err := r.k8sh.RookClientset.CephV1().CephRBDMirrors(namespace).Delete(name, options)
if err != nil && !errors.IsNotFound(err) {
return err
}
logger.Infof("Deleted rbd-mirror %s in namespace %s", name, namespace)
return nil
}