ceph_settings.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. Copyright 2021 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 installer
  14. import (
  15. "fmt"
  16. "os"
  17. "strings"
  18. cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
  19. )
  20. // TestCephSettings struct for handling panic and test suite tear down
  21. type TestCephSettings struct {
  22. DataDirHostPath string
  23. ClusterName string
  24. Namespace string
  25. OperatorNamespace string
  26. StorageClassName string
  27. UseHelm bool
  28. RetainHelmDefaultStorageCRs bool
  29. UsePVC bool
  30. Mons int
  31. UseCrashPruner bool
  32. MultipleMgrs bool
  33. SkipOSDCreation bool
  34. EnableDiscovery bool
  35. IsExternal bool
  36. SkipClusterCleanup bool
  37. SkipCleanupPolicy bool
  38. DirectMountToolbox bool
  39. ConnectionsEncrypted bool
  40. ConnectionsCompressed bool
  41. RequireMsgr2 bool
  42. EnableVolumeReplication bool
  43. TestNFSCSI bool
  44. ChangeHostName bool
  45. RookVersion string
  46. CephVersion cephv1.CephVersionSpec
  47. KubernetesVersion string
  48. }
  49. func (s *TestCephSettings) ApplyEnvVars() {
  50. // skip the cleanup by default
  51. s.SkipClusterCleanup = true
  52. if os.Getenv("SKIP_TEST_CLEANUP") == "false" {
  53. s.SkipClusterCleanup = false
  54. }
  55. s.SkipCleanupPolicy = true
  56. if os.Getenv("SKIP_CLEANUP_POLICY") == "false" {
  57. s.SkipCleanupPolicy = false
  58. }
  59. }
  60. func (s *TestCephSettings) readManifest(filename string) string {
  61. manifest := readManifest(filename)
  62. return replaceNamespaces(manifest, manifest, s.OperatorNamespace, s.Namespace)
  63. }
  64. func (s *TestCephSettings) readManifestFromGitHub(filename string) string {
  65. return s.readManifestFromGitHubWithClusterNamespace(filename, s.Namespace)
  66. }
  67. func (s *TestCephSettings) readManifestFromGitHubWithClusterNamespace(filename, clusterNamespace string) string {
  68. manifest := readManifestFromGitHub(s.RookVersion, filename)
  69. return replaceNamespaces(filename, manifest, s.OperatorNamespace, clusterNamespace)
  70. }
  71. func (s *TestCephSettings) replaceOperatorSettings(manifest string) string {
  72. manifest = strings.ReplaceAll(manifest, `ROOK_LOG_LEVEL: "INFO"`, `ROOK_LOG_LEVEL: "DEBUG"`)
  73. manifest = strings.ReplaceAll(manifest, `# CSI_LOG_LEVEL: "0"`, `CSI_LOG_LEVEL: "5"`)
  74. manifest = strings.ReplaceAll(manifest, `ROOK_ENABLE_DISCOVERY_DAEMON: "false"`, fmt.Sprintf(`ROOK_ENABLE_DISCOVERY_DAEMON: "%t"`, s.EnableDiscovery))
  75. manifest = strings.ReplaceAll(manifest, `CSI_ENABLE_VOLUME_REPLICATION: "false"`, fmt.Sprintf(`CSI_ENABLE_VOLUME_REPLICATION: "%t"`, s.EnableVolumeReplication))
  76. manifest = strings.ReplaceAll(manifest, `ROOK_CSI_ENABLE_NFS: "false"`, fmt.Sprintf(`ROOK_CSI_ENABLE_NFS: "%t"`, s.TestNFSCSI))
  77. return manifest
  78. }
  79. func replaceNamespaces(name, manifest, operatorNamespace, clusterNamespace string) string {
  80. // RBAC and related namespaces
  81. manifest = strings.ReplaceAll(manifest, "rook-ceph # namespace:operator", operatorNamespace)
  82. manifest = strings.ReplaceAll(manifest, "rook-ceph # namespace:cluster", clusterNamespace)
  83. manifest = strings.ReplaceAll(manifest, "rook-ceph-external # namespace:cluster", clusterNamespace)
  84. // Double space only needed for v1.5 upgrade test
  85. manifest = strings.ReplaceAll(manifest, "rook-ceph # namespace:operator", operatorNamespace)
  86. // SCC namespaces for operator and Ceph daemons
  87. manifest = strings.ReplaceAll(manifest, "rook-ceph:rook-ceph-system # serviceaccount:namespace:operator", operatorNamespace+":rook-ceph-system")
  88. manifest = strings.ReplaceAll(manifest, "rook-ceph:rook-ceph-mgr # serviceaccount:namespace:cluster", clusterNamespace+":rook-ceph-mgr")
  89. manifest = strings.ReplaceAll(manifest, "rook-ceph:rook-ceph-osd # serviceaccount:namespace:cluster", clusterNamespace+":rook-ceph-osd")
  90. manifest = strings.ReplaceAll(manifest, "rook-ceph:rook-ceph-rgw # serviceaccount:namespace:cluster", clusterNamespace+":rook-ceph-rgw")
  91. // SCC namespaces for CSI driver
  92. manifest = strings.ReplaceAll(manifest, "rook-ceph:rook-csi-rbd-plugin-sa # serviceaccount:namespace:operator", operatorNamespace+":rook-csi-rbd-plugin-sa")
  93. manifest = strings.ReplaceAll(manifest, "rook-ceph:rook-csi-rbd-provisioner-sa # serviceaccount:namespace:operator", operatorNamespace+":rook-csi-rbd-provisioner-sa")
  94. manifest = strings.ReplaceAll(manifest, "rook-ceph:rook-csi-cephfs-plugin-sa # serviceaccount:namespace:operator", operatorNamespace+":rook-csi-cephfs-plugin-sa")
  95. manifest = strings.ReplaceAll(manifest, "rook-ceph:rook-csi-cephfs-provisioner-sa # serviceaccount:namespace:operator", operatorNamespace+":rook-csi-cephfs-provisioner-sa")
  96. // CSI Drivers
  97. manifest = strings.ReplaceAll(manifest, "rook-ceph.cephfs.csi.ceph.com # driver:namespace:operator", operatorNamespace+".cephfs.csi.ceph.com")
  98. manifest = strings.ReplaceAll(manifest, "rook-ceph.rbd.csi.ceph.com # driver:namespace:operator", operatorNamespace+".rbd.csi.ceph.com")
  99. // Bucket storage class
  100. manifest = strings.ReplaceAll(manifest, "rook-ceph.ceph.rook.io/bucket # driver:namespace:cluster", clusterNamespace+".ceph.rook.io/bucket")
  101. if strings.Contains(manifest, "namespace:operator") || strings.Contains(manifest, "namespace:cluster") || strings.Contains(manifest, "driver:namespace:") || strings.Contains(manifest, "serviceaccount:namespace:") {
  102. logger.Infof("BAD MANIFEST:\n%s", manifest)
  103. panic(fmt.Sprintf("manifest %s still contains a namespace identifier", name))
  104. }
  105. return manifest
  106. }