rbd-mirror.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. Copyright 2020 The Rook Authors. All rights reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package clients
  14. import (
  15. "context"
  16. "github.com/rook/rook/tests/framework/installer"
  17. "github.com/rook/rook/tests/framework/utils"
  18. "github.com/stretchr/testify/assert"
  19. "k8s.io/apimachinery/pkg/api/errors"
  20. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  21. )
  22. // RBDMirrorOperation is a wrapper for k8s rook rbd mirror operations
  23. type RBDMirrorOperation struct {
  24. k8sh *utils.K8sHelper
  25. manifests installer.CephManifests
  26. }
  27. // CreateRBDMirrorOperation Constructor to create RBDMirrorOperation - client to perform ceph rbd mirror operations on k8s
  28. func CreateRBDMirrorOperation(k8sh *utils.K8sHelper, manifests installer.CephManifests) *RBDMirrorOperation {
  29. return &RBDMirrorOperation{k8sh, manifests}
  30. }
  31. // Create creates a rbd-mirror in Rook
  32. func (r *RBDMirrorOperation) Create(namespace, name string, daemonCount int) error {
  33. logger.Infof("creating the RBDMirror daemons via CRD")
  34. if err := r.k8sh.ResourceOperation("apply", r.manifests.GetRBDMirror(name, daemonCount)); err != nil {
  35. return err
  36. }
  37. logger.Infof("Make sure rook-ceph-rbd-mirror pod is running")
  38. err := r.k8sh.WaitForLabeledPodsToRun("app=rook-ceph-rbd-mirror", namespace)
  39. assert.Nil(r.k8sh.T(), err)
  40. assert.True(r.k8sh.T(), r.k8sh.CheckPodCountAndState("rook-ceph-rbd-mirror", namespace, daemonCount, "Running"),
  41. "Make sure all rbd-mirror daemon pods are in Running state")
  42. return nil
  43. }
  44. // Delete deletes a rbd-mirror in Rook
  45. func (r *RBDMirrorOperation) Delete(namespace, name string) error {
  46. ctx := context.TODO()
  47. options := &metav1.DeleteOptions{}
  48. logger.Infof("Deleting rbd-mirror %s in namespace %s", name, namespace)
  49. err := r.k8sh.RookClientset.CephV1().CephRBDMirrors(namespace).Delete(ctx, name, *options)
  50. if err != nil && !errors.IsNotFound(err) {
  51. return err
  52. }
  53. logger.Infof("Deleted rbd-mirror %s in namespace %s", name, namespace)
  54. return nil
  55. }