object.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. Copyright 2016 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. "fmt"
  16. "github.com/coreos/pkg/capnslog"
  17. "github.com/rook/rook/tests/framework/installer"
  18. "github.com/rook/rook/tests/framework/utils"
  19. )
  20. const rgwPort = 80
  21. var logger = capnslog.NewPackageLogger("github.com/rook/rook/tests", "clients")
  22. // ObjectOperation is wrapper for k8s rook object operations
  23. type ObjectOperation struct {
  24. k8sh *utils.K8sHelper
  25. manifests installer.CephManifests
  26. }
  27. // CreateObjectOperation creates new rook object client
  28. func CreateObjectOperation(k8sh *utils.K8sHelper, manifests installer.CephManifests) *ObjectOperation {
  29. return &ObjectOperation{k8sh, manifests}
  30. }
  31. // ObjectCreate Function to create a object store in rook
  32. func (o *ObjectOperation) Create(namespace, storeName string, replicaCount int32, tlsEnable bool) error {
  33. logger.Info("creating the object store via CRD")
  34. if err := o.k8sh.ResourceOperation("apply", o.manifests.GetObjectStore(storeName, int(replicaCount), rgwPort, tlsEnable)); err != nil {
  35. return err
  36. }
  37. // Starting an object store takes longer than the average operation, so add more retries
  38. err := o.k8sh.WaitForLabeledPodsToRunWithRetries(fmt.Sprintf("rook_object_store=%s", storeName), namespace, 80)
  39. if err != nil {
  40. return fmt.Errorf("rgw did not start via crd. %+v", err)
  41. }
  42. // create the external service
  43. return o.k8sh.CreateExternalRGWService(namespace, storeName)
  44. }
  45. func (o *ObjectOperation) Delete(namespace, storeName string) error {
  46. logger.Infof("Deleting the object store via CRD")
  47. if err := o.k8sh.DeleteResource("-n", namespace, "CephObjectStore", storeName); err != nil {
  48. return err
  49. }
  50. if !o.k8sh.WaitUntilPodWithLabelDeleted(fmt.Sprintf("rook_object_store=%s", storeName), namespace) {
  51. return fmt.Errorf("rgw did not stop via crd")
  52. }
  53. return nil
  54. }
  55. // Need to improve the below function for better error handling
  56. func (o *ObjectOperation) GetEndPointUrl(namespace string, storeName string) (string, error) {
  57. args := []string{"get", "svc", "-n", namespace, "-l", fmt.Sprintf("rgw=%s", storeName), "-o", "jsonpath={.items[*].spec.clusterIP}"}
  58. EndPointUrl, err := o.k8sh.Kubectl(args...)
  59. if err != nil {
  60. return "", fmt.Errorf("Unable to find rgw end point-- %s", err)
  61. }
  62. return fmt.Sprintf("%s:%d", EndPointUrl, rgwPort), nil
  63. }