ceph_manifests.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  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 installer
  14. import (
  15. "fmt"
  16. "regexp"
  17. "strconv"
  18. "strings"
  19. "github.com/rook/rook/pkg/operator/ceph/object/cosi"
  20. "github.com/rook/rook/tests/framework/utils"
  21. )
  22. type CephManifests interface {
  23. Settings() *TestCephSettings
  24. GetCRDs(k8shelper *utils.K8sHelper) string
  25. GetCSINFSRBAC() string
  26. GetOperator() string
  27. GetCommon() string
  28. GetCommonExternal() string
  29. GetCephCluster() string
  30. GetExternalCephCluster() string
  31. GetToolbox() string
  32. GetBlockPool(poolName, replicaSize string) string
  33. GetBlockStorageClass(poolName, storageClassName, reclaimPolicy string) string
  34. GetFileStorageClass(fsName, storageClassName string) string
  35. GetNFSStorageClass(fsName, nfsClusterName, server, storageClassName string) string
  36. GetNFSSnapshotClass(fsName, snapshotClassName string) string
  37. GetBlockSnapshotClass(snapshotClassName, reclaimPolicy string) string
  38. GetFileStorageSnapshotClass(snapshotClassName, reclaimPolicy string) string
  39. GetFilesystem(name string, activeCount int) string
  40. GetNFS(name string, daemonCount int) string
  41. GetNFSPool() string
  42. GetRBDMirror(name string, daemonCount int) string
  43. GetObjectStore(name string, replicaCount, port int, tlsEnable bool) string
  44. GetObjectStoreUser(name, displayName, store, usercaps, maxsize string, maxbuckets, maxobjects int) string
  45. GetBucketStorageClass(storeName, storageClassName, reclaimPolicy string) string
  46. GetOBC(obcName, storageClassName, bucketName string, maxObject string, createBucket bool) string
  47. GetOBCNotification(obcName, storageClassName, bucketName string, notificationName string, createBucket bool) string
  48. GetBucketNotification(notificationName string, topicName string) string
  49. GetBucketTopic(topicName string, storeName string, httpEndpointService string) string
  50. GetClient(name string, caps map[string]string) string
  51. GetFilesystemSubvolumeGroup(fsName, groupName string) string
  52. GetCOSIDriver() string
  53. GetBucketClass(name, objectstoreUserName, deletionPolicy string) string
  54. GetBucketClaim(claimName, className string) string
  55. }
  56. // CephManifestsMaster wraps rook yaml definitions
  57. type CephManifestsMaster struct {
  58. settings *TestCephSettings
  59. }
  60. // NewCephManifests gets the manifest type depending on the Rook version desired
  61. func NewCephManifests(settings *TestCephSettings) CephManifests {
  62. switch settings.RookVersion {
  63. case LocalBuildTag:
  64. return &CephManifestsMaster{settings}
  65. case Version1_12:
  66. return &CephManifestsPreviousVersion{settings, &CephManifestsMaster{settings}}
  67. }
  68. panic(fmt.Errorf("unrecognized ceph manifest version: %s", settings.RookVersion))
  69. }
  70. func (m *CephManifestsMaster) Settings() *TestCephSettings {
  71. return m.settings
  72. }
  73. func (m *CephManifestsMaster) GetCRDs(k8shelper *utils.K8sHelper) string {
  74. return m.settings.readManifest("crds.yaml")
  75. }
  76. func (m *CephManifestsMaster) GetCSINFSRBAC() string {
  77. return m.settings.readManifest("/csi/nfs/rbac.yaml")
  78. }
  79. func (m *CephManifestsMaster) GetOperator() string {
  80. var manifest string
  81. if utils.IsPlatformOpenShift() {
  82. manifest = m.settings.readManifest("operator-openshift.yaml")
  83. } else {
  84. manifest = m.settings.readManifest("operator.yaml")
  85. }
  86. return m.settings.replaceOperatorSettings(manifest)
  87. }
  88. func (m *CephManifestsMaster) GetCommonExternal() string {
  89. return m.settings.readManifest("common-external.yaml")
  90. }
  91. func (m *CephManifestsMaster) GetCommon() string {
  92. return m.settings.readManifest("common.yaml")
  93. }
  94. func (m *CephManifestsMaster) GetToolbox() string {
  95. if m.settings.DirectMountToolbox {
  96. manifest := strings.ReplaceAll(m.settings.readManifest("direct-mount.yaml"), "name: rook-direct-mount", "name: rook-ceph-tools")
  97. manifest = strings.ReplaceAll(manifest, "name: rook-direct-mount", "name: rook-ceph-tools")
  98. return strings.ReplaceAll(manifest, "app: rook-direct-mount", "app: rook-ceph-tools")
  99. }
  100. manifest := m.settings.readManifest("toolbox.yaml")
  101. if m.settings.CephVersion.Image != "" {
  102. // The toolbox uses the ceph image, so replace the version that is being tested
  103. // The regex allows for any character in the tag ("\S" --> non-whitespace character)
  104. versionRegex := regexp.MustCompile(`image: quay.io/ceph/ceph:\S+`)
  105. manifest = versionRegex.ReplaceAllString(manifest, "image: "+m.settings.CephVersion.Image)
  106. }
  107. return manifest
  108. }
  109. //**********************************************************************************
  110. //**********************************************************************************
  111. // After a release, copy the methods below this separator into the versioned file
  112. // such as ceph_manifests_previous.go. Methods above this separator do not need to be
  113. // copied since the versioned implementation will load them directly from github.
  114. //**********************************************************************************
  115. //**********************************************************************************
  116. func (m *CephManifestsMaster) GetCephCluster() string {
  117. crushRoot := "# crushRoot not specified; Rook will use `default`"
  118. if m.settings.Mons == 1 {
  119. crushRoot = `crushRoot: "custom-root"`
  120. }
  121. pruner := "# daysToRetain not specified;"
  122. if m.settings.UseCrashPruner {
  123. pruner = "daysToRetain: 5"
  124. }
  125. mgrCount := 1
  126. if m.settings.MultipleMgrs {
  127. mgrCount = 2
  128. }
  129. clusterSpec := `apiVersion: ceph.rook.io/v1
  130. kind: CephCluster
  131. metadata:
  132. # set the name to something different from the namespace
  133. name: ` + m.settings.ClusterName + `
  134. namespace: ` + m.settings.Namespace + `
  135. spec:
  136. resources: null
  137. dataDirHostPath: ` + m.settings.DataDirHostPath + `
  138. cephVersion:
  139. image: ` + m.settings.CephVersion.Image + `
  140. allowUnsupported: ` + strconv.FormatBool(m.settings.CephVersion.AllowUnsupported) + `
  141. skipUpgradeChecks: true
  142. continueUpgradeAfterChecksEvenIfNotHealthy: false
  143. mgr:
  144. count: ` + strconv.Itoa(mgrCount) + `
  145. allowMultiplePerNode: true
  146. modules:
  147. - name: pg_autoscaler
  148. enabled: true
  149. dashboard:
  150. enabled: true
  151. network:
  152. hostNetwork: false
  153. connections:
  154. requireMsgr2: ` + strconv.FormatBool(m.settings.RequireMsgr2) + `
  155. encryption:
  156. enabled: ` + strconv.FormatBool(m.settings.ConnectionsEncrypted) + `
  157. compression:
  158. enabled: ` + strconv.FormatBool(m.settings.ConnectionsCompressed) + `
  159. crashCollector:
  160. disable: false
  161. ` + pruner + `
  162. logCollector:
  163. enabled: true
  164. periodicity: daily
  165. maxLogSize: 500M
  166. disruptionManagement:
  167. managePodBudgets: true
  168. osdMaintenanceTimeout: 30
  169. pgHealthCheckTimeout: 0
  170. healthCheck:
  171. daemonHealth:
  172. mon:
  173. interval: 10s
  174. timeout: 15s
  175. osd:
  176. interval: 10s
  177. status:
  178. interval: 5s`
  179. if m.settings.UsePVC {
  180. clusterSpec += `
  181. mon:
  182. count: ` + strconv.Itoa(m.settings.Mons) + `
  183. allowMultiplePerNode: true
  184. volumeClaimTemplate:
  185. spec:
  186. storageClassName: ` + m.settings.StorageClassName + `
  187. resources:
  188. requests:
  189. storage: 5Gi
  190. storage:
  191. config:
  192. ` + crushRoot + `
  193. storageClassDeviceSets:
  194. - name: set1
  195. count: 1
  196. portable: false
  197. tuneDeviceClass: true
  198. encrypted: false
  199. volumeClaimTemplates:
  200. - metadata:
  201. name: data
  202. spec:
  203. resources:
  204. requests:
  205. storage: 10Gi
  206. storageClassName: ` + m.settings.StorageClassName + `
  207. volumeMode: Block
  208. accessModes:
  209. - ReadWriteOnce
  210. `
  211. } else {
  212. clusterSpec += `
  213. mon:
  214. count: ` + strconv.Itoa(m.settings.Mons) + `
  215. allowMultiplePerNode: true
  216. storage:
  217. useAllNodes: ` + strconv.FormatBool(!m.settings.SkipOSDCreation) + `
  218. useAllDevices: ` + strconv.FormatBool(!m.settings.SkipOSDCreation) + `
  219. deviceFilter: ` + getDeviceFilter() + `
  220. config:
  221. databaseSizeMB: "1024"
  222. `
  223. }
  224. return clusterSpec + `
  225. priorityClassNames:
  226. mon: system-node-critical
  227. osd: system-node-critical
  228. mgr: system-cluster-critical
  229. `
  230. }
  231. func (m *CephManifestsMaster) GetBlockSnapshotClass(snapshotClassName, reclaimPolicy string) string {
  232. // Create a CSI driver snapshotclass
  233. return `
  234. apiVersion: snapshot.storage.k8s.io/v1
  235. kind: VolumeSnapshotClass
  236. metadata:
  237. name: ` + snapshotClassName + `
  238. driver: ` + m.settings.OperatorNamespace + `.rbd.csi.ceph.com
  239. deletionPolicy: ` + reclaimPolicy + `
  240. parameters:
  241. clusterID: ` + m.settings.Namespace + `
  242. csi.storage.k8s.io/snapshotter-secret-name: rook-csi-rbd-provisioner
  243. csi.storage.k8s.io/snapshotter-secret-namespace: ` + m.settings.Namespace + `
  244. `
  245. }
  246. func (m *CephManifestsMaster) GetFileStorageSnapshotClass(snapshotClassName, reclaimPolicy string) string {
  247. // Create a CSI driver snapshotclass
  248. return `
  249. apiVersion: snapshot.storage.k8s.io/v1
  250. kind: VolumeSnapshotClass
  251. metadata:
  252. name: ` + snapshotClassName + `
  253. driver: ` + m.settings.OperatorNamespace + `.cephfs.csi.ceph.com
  254. deletionPolicy: ` + reclaimPolicy + `
  255. parameters:
  256. clusterID: ` + m.settings.Namespace + `
  257. csi.storage.k8s.io/snapshotter-secret-name: rook-csi-cephfs-provisioner
  258. csi.storage.k8s.io/snapshotter-secret-namespace: ` + m.settings.Namespace + `
  259. `
  260. }
  261. func (m *CephManifestsMaster) GetBlockPool(poolName string, replicaSize string) string {
  262. return `apiVersion: ceph.rook.io/v1
  263. kind: CephBlockPool
  264. metadata:
  265. name: ` + poolName + `
  266. namespace: ` + m.settings.Namespace + `
  267. spec:
  268. replicated:
  269. size: ` + replicaSize + `
  270. targetSizeRatio: .5
  271. requireSafeReplicaSize: false
  272. parameters:
  273. compression_mode: aggressive
  274. mirroring:
  275. enabled: true
  276. mode: image
  277. quotas:
  278. maxSize: 10Gi
  279. maxObjects: 1000000
  280. statusCheck:
  281. mirror:
  282. disabled: false
  283. interval: 10s`
  284. }
  285. func (m *CephManifestsMaster) GetBlockStorageClass(poolName, storageClassName, reclaimPolicy string) string {
  286. // Create a CSI driver storage class
  287. sc := `
  288. apiVersion: storage.k8s.io/v1
  289. kind: StorageClass
  290. metadata:
  291. name: ` + storageClassName + `
  292. provisioner: ` + m.settings.OperatorNamespace + `.rbd.csi.ceph.com
  293. reclaimPolicy: ` + reclaimPolicy + `
  294. parameters:
  295. pool: ` + poolName + `
  296. clusterID: ` + m.settings.Namespace + `
  297. csi.storage.k8s.io/provisioner-secret-name: rook-csi-rbd-provisioner
  298. csi.storage.k8s.io/provisioner-secret-namespace: ` + m.settings.Namespace + `
  299. csi.storage.k8s.io/node-stage-secret-name: rook-csi-rbd-node
  300. csi.storage.k8s.io/node-stage-secret-namespace: ` + m.settings.Namespace + `
  301. imageFeatures: layering
  302. csi.storage.k8s.io/fstype: ext4
  303. `
  304. return sc
  305. }
  306. func (m *CephManifestsMaster) GetFileStorageClass(fsName, storageClassName string) string {
  307. // Create a CSI driver storage class
  308. csiCephFSNodeSecret := "rook-csi-cephfs-node" //nolint:gosec // We safely suppress gosec in tests file
  309. csiCephFSProvisionerSecret := "rook-csi-cephfs-provisioner" //nolint:gosec // We safely suppress gosec in tests file
  310. sc := `
  311. apiVersion: storage.k8s.io/v1
  312. kind: StorageClass
  313. metadata:
  314. name: ` + storageClassName + `
  315. provisioner: ` + m.settings.OperatorNamespace + `.cephfs.csi.ceph.com
  316. parameters:
  317. clusterID: ` + m.settings.Namespace + `
  318. fsName: ` + fsName + `
  319. pool: ` + fsName + `-data0
  320. csi.storage.k8s.io/provisioner-secret-name: ` + csiCephFSProvisionerSecret + `
  321. csi.storage.k8s.io/provisioner-secret-namespace: ` + m.settings.Namespace + `
  322. csi.storage.k8s.io/node-stage-secret-name: ` + csiCephFSNodeSecret + `
  323. csi.storage.k8s.io/node-stage-secret-namespace: ` + m.settings.Namespace + `
  324. `
  325. if m.settings.ConnectionsEncrypted {
  326. // encryption requires either the 5.11 kernel or the fuse mounter. Until the newer
  327. // kernel is available in minikube, we need to test with fuse.
  328. sc += " mounter: fuse"
  329. }
  330. return sc
  331. }
  332. func (m *CephManifestsMaster) GetNFSStorageClass(fsName, nfsClusterName, server, storageClassName string) string {
  333. // Create a CSI driver storage class
  334. csiCephFSNodeSecret := "rook-csi-cephfs-node" //nolint:gosec // We safely suppress gosec in tests file
  335. csiCephFSProvisionerSecret := "rook-csi-cephfs-provisioner" //nolint:gosec // We safely suppress gosec in tests file
  336. sc := `
  337. apiVersion: storage.k8s.io/v1
  338. kind: StorageClass
  339. metadata:
  340. name: ` + storageClassName + `
  341. provisioner: ` + m.settings.OperatorNamespace + `.nfs.csi.ceph.com
  342. parameters:
  343. clusterID: ` + m.settings.Namespace + `
  344. fsName: ` + fsName + `
  345. nfsCluster: ` + nfsClusterName + `
  346. server: ` + server + `
  347. pool: ` + fsName + `-data0
  348. csi.storage.k8s.io/provisioner-secret-name: ` + csiCephFSProvisionerSecret + `
  349. csi.storage.k8s.io/provisioner-secret-namespace: ` + m.settings.Namespace + `
  350. csi.storage.k8s.io/node-stage-secret-name: ` + csiCephFSNodeSecret + `
  351. csi.storage.k8s.io/node-stage-secret-namespace: ` + m.settings.Namespace + `
  352. mountOptions:
  353. - "nolock"
  354. `
  355. // "nolock" mountOptions has been added to prevent the following error in ci environment:
  356. // rpc error: code = Internal desc = mount failed: exit status 32
  357. // Mounting command: mount
  358. // Mounting arguments: -t nfs <src> <dest>
  359. // Output: mount.nfs: rpc.statd is not running but is required for remote locking.
  360. // mount.nfs: Either use '-o nolock' to keep locks local, or start statd.
  361. return sc
  362. }
  363. func (m *CephManifestsMaster) GetNFSSnapshotClass(snapshotClassName, reclaimPolicy string) string {
  364. // return NFS CSI snapshotclass object.
  365. return `
  366. apiVersion: snapshot.storage.k8s.io/v1
  367. kind: VolumeSnapshotClass
  368. metadata:
  369. name: ` + snapshotClassName + `
  370. driver: ` + m.settings.OperatorNamespace + `.nfs.csi.ceph.com
  371. deletionPolicy: ` + reclaimPolicy + `
  372. parameters:
  373. clusterID: ` + m.settings.Namespace + `
  374. csi.storage.k8s.io/snapshotter-secret-name: rook-csi-cephfs-provisioner
  375. csi.storage.k8s.io/snapshotter-secret-namespace: ` + m.settings.Namespace + `
  376. `
  377. }
  378. // GetFilesystem returns the manifest to create a Rook filesystem resource with the given config.
  379. func (m *CephManifestsMaster) GetFilesystem(name string, activeCount int) string {
  380. return `apiVersion: ceph.rook.io/v1
  381. kind: CephFilesystem
  382. metadata:
  383. name: ` + name + `
  384. namespace: ` + m.settings.Namespace + `
  385. spec:
  386. metadataPool:
  387. replicated:
  388. size: 1
  389. requireSafeReplicaSize: false
  390. dataPools:
  391. - replicated:
  392. size: 1
  393. requireSafeReplicaSize: false
  394. compressionMode: none
  395. metadataServer:
  396. resources: null
  397. activeCount: ` + strconv.Itoa(activeCount) + `
  398. activeStandby: true`
  399. }
  400. // GetFilesystem returns the manifest to create a Rook Ceph NFS resource with the given config.
  401. func (m *CephManifestsMaster) GetNFS(name string, count int) string {
  402. return `apiVersion: ceph.rook.io/v1
  403. kind: CephNFS
  404. metadata:
  405. name: ` + name + `
  406. namespace: ` + m.settings.Namespace + `
  407. spec:
  408. rados:
  409. pool: .nfs
  410. namespace: nfs-ns
  411. server:
  412. active: ` + strconv.Itoa(count)
  413. }
  414. // GetFilesystem returns the manifest to create a Rook Ceph NFS resource with the given config.
  415. func (m *CephManifestsMaster) GetNFSPool() string {
  416. return `apiVersion: ceph.rook.io/v1
  417. kind: CephBlockPool
  418. metadata:
  419. name: dot-nfs
  420. namespace: ` + m.settings.Namespace + `
  421. spec:
  422. name: .nfs
  423. replicated:
  424. size: 1
  425. requireSafeReplicaSize: false`
  426. }
  427. func (m *CephManifestsMaster) GetObjectStore(name string, replicaCount, port int, tlsEnable bool) string {
  428. if tlsEnable {
  429. return `apiVersion: ceph.rook.io/v1
  430. kind: CephObjectStore
  431. metadata:
  432. name: ` + name + `
  433. namespace: ` + m.settings.Namespace + `
  434. spec:
  435. metadataPool:
  436. replicated:
  437. size: 1
  438. requireSafeReplicaSize: false
  439. compressionMode: passive
  440. dataPool:
  441. replicated:
  442. size: 1
  443. requireSafeReplicaSize: false
  444. gateway:
  445. resources: null
  446. securePort: ` + strconv.Itoa(port) + `
  447. instances: ` + strconv.Itoa(replicaCount) + `
  448. sslCertificateRef: ` + name + `
  449. `
  450. }
  451. return `apiVersion: ceph.rook.io/v1
  452. kind: CephObjectStore
  453. metadata:
  454. name: ` + name + `
  455. namespace: ` + m.settings.Namespace + `
  456. spec:
  457. metadataPool:
  458. replicated:
  459. size: 1
  460. requireSafeReplicaSize: false
  461. compressionMode: passive
  462. dataPool:
  463. replicated:
  464. size: 1
  465. requireSafeReplicaSize: false
  466. gateway:
  467. resources: null
  468. port: ` + strconv.Itoa(port) + `
  469. instances: ` + strconv.Itoa(replicaCount) + `
  470. `
  471. }
  472. func (m *CephManifestsMaster) GetObjectStoreUser(name, displayName, store, usercaps, maxsize string, maxbuckets, maxobjects int) string {
  473. return `apiVersion: ceph.rook.io/v1
  474. kind: CephObjectStoreUser
  475. metadata:
  476. name: ` + name + `
  477. namespace: ` + m.settings.Namespace + `
  478. spec:
  479. displayName: ` + displayName + `
  480. store: ` + store + `
  481. quotas:
  482. maxBuckets: ` + strconv.Itoa(maxbuckets) + `
  483. maxObjects: ` + strconv.Itoa(maxobjects) + `
  484. maxSize: ` + maxsize + `
  485. capabilities:
  486. user: "` + usercaps + `"
  487. bucket: "` + usercaps + `"
  488. `
  489. }
  490. // GetBucketStorageClass returns the manifest to create object bucket
  491. func (m *CephManifestsMaster) GetBucketStorageClass(storeName, storageClassName, reclaimPolicy string) string {
  492. return `apiVersion: storage.k8s.io/v1
  493. kind: StorageClass
  494. metadata:
  495. name: ` + storageClassName + `
  496. provisioner: ` + m.settings.Namespace + `.ceph.rook.io/bucket
  497. reclaimPolicy: ` + reclaimPolicy + `
  498. parameters:
  499. objectStoreName: ` + storeName + `
  500. objectStoreNamespace: ` + m.settings.Namespace
  501. }
  502. // GetOBC returns the manifest to create object bucket claim
  503. func (m *CephManifestsMaster) GetOBC(claimName string, storageClassName string, objectBucketName string, maxObject string, varBucketName bool) string {
  504. bucketParameter := "generateBucketName"
  505. if varBucketName {
  506. bucketParameter = "bucketName"
  507. }
  508. return `apiVersion: objectbucket.io/v1alpha1
  509. kind: ObjectBucketClaim
  510. metadata:
  511. name: ` + claimName + `
  512. spec:
  513. ` + bucketParameter + `: ` + objectBucketName + `
  514. storageClassName: ` + storageClassName + `
  515. additionalConfig:
  516. maxObjects: "` + maxObject + `"`
  517. }
  518. // GetOBCNotification returns the manifest to create object bucket claim
  519. func (m *CephManifestsMaster) GetOBCNotification(claimName string, storageClassName string, objectBucketName string, notificationName string, varBucketName bool) string {
  520. bucketParameter := "generateBucketName"
  521. if varBucketName {
  522. bucketParameter = "bucketName"
  523. }
  524. return `apiVersion: objectbucket.io/v1alpha1
  525. kind: ObjectBucketClaim
  526. metadata:
  527. name: ` + claimName + `
  528. labels:
  529. bucket-notification-` + notificationName + `: ` + notificationName + `
  530. spec:
  531. ` + bucketParameter + `: ` + objectBucketName + `
  532. storageClassName: ` + storageClassName
  533. }
  534. // GetBucketNotification returns the manifest to create ceph bucket notification
  535. func (m *CephManifestsMaster) GetBucketNotification(notificationName string, topicName string) string {
  536. return `apiVersion: ceph.rook.io/v1
  537. kind: CephBucketNotification
  538. metadata:
  539. name: ` + notificationName + `
  540. spec:
  541. topic: ` + topicName + `
  542. events:
  543. - s3:ObjectCreated:Put
  544. - s3:ObjectRemoved:Delete
  545. `
  546. }
  547. // GetBucketTopic returns the manifest to create ceph bucket topic
  548. func (m *CephManifestsMaster) GetBucketTopic(topicName string, storeName string, httpEndpointService string) string {
  549. return `apiVersion: ceph.rook.io/v1
  550. kind: CephBucketTopic
  551. metadata:
  552. name: ` + topicName + `
  553. spec:
  554. endpoint:
  555. http:
  556. uri: ` + httpEndpointService + `
  557. sendCloudEvents: false
  558. objectStoreName: ` + storeName + `
  559. objectStoreNamespace: ` + m.settings.Namespace
  560. }
  561. func (m *CephManifestsMaster) GetClient(claimName string, caps map[string]string) string {
  562. clientCaps := []string{}
  563. for name, cap := range caps {
  564. str := name + ": " + cap
  565. clientCaps = append(clientCaps, str)
  566. }
  567. return `apiVersion: ceph.rook.io/v1
  568. kind: CephClient
  569. metadata:
  570. name: ` + claimName + `
  571. namespace: ` + m.settings.Namespace + `
  572. spec:
  573. caps:
  574. ` + strings.Join(clientCaps, "\n ")
  575. }
  576. func (m *CephManifestsMaster) GetExternalCephCluster() string {
  577. return `apiVersion: ceph.rook.io/v1
  578. kind: CephCluster
  579. metadata:
  580. name: ` + m.settings.ClusterName + `
  581. namespace: ` + m.settings.Namespace + `
  582. spec:
  583. external:
  584. enable: true
  585. dataDirHostPath: ` + m.settings.DataDirHostPath + `
  586. healthCheck:
  587. daemonHealth:
  588. status:
  589. interval: 5s`
  590. }
  591. // GetRBDMirror returns the manifest to create a Rook Ceph RBD Mirror resource with the given config.
  592. func (m *CephManifestsMaster) GetRBDMirror(name string, count int) string {
  593. return `apiVersion: ceph.rook.io/v1
  594. kind: CephRBDMirror
  595. metadata:
  596. name: ` + name + `
  597. namespace: ` + m.settings.Namespace + `
  598. spec:
  599. count: ` + strconv.Itoa(count)
  600. }
  601. func (m *CephManifestsMaster) GetFilesystemSubvolumeGroup(fsName, groupName string) string {
  602. return `apiVersion: ceph.rook.io/v1
  603. kind: CephFilesystemSubVolumeGroup
  604. metadata:
  605. name: ` + groupName + `
  606. namespace: ` + m.settings.Namespace + `
  607. spec:
  608. filesystemName: ` + fsName
  609. }
  610. func (m *CephManifestsMaster) GetCOSIDriver() string {
  611. // TODO: use the official image once it is available
  612. return `apiVersion: ceph.rook.io/v1
  613. kind: CephCOSIDriver
  614. metadata:
  615. name: ` + cosi.CephCOSIDriverName + `
  616. namespace: ` + m.settings.OperatorNamespace + `
  617. spec:
  618. deploymentStrategy: Auto `
  619. }
  620. func (m *CephManifestsMaster) GetBucketClass(name, objectStoreUserSecretName, deletionPolicy string) string {
  621. return `apiVersion: objectstorage.k8s.io/v1alpha1
  622. kind: BucketClass
  623. metadata:
  624. name: ` + name + `
  625. namespace: ` + m.settings.OperatorNamespace + `
  626. driverName: ceph.objectstorage.k8s.io
  627. deletionPolicy: ` + deletionPolicy + `
  628. parameters:
  629. objectStoreUserSecretName: ` + objectStoreUserSecretName + `
  630. objectStoreUserSecretNamespace: ` + m.settings.Namespace
  631. }
  632. func (m *CephManifestsMaster) GetBucketClaim(name, bucketClassName string) string {
  633. return `apiVersion: objectstorage.k8s.io/v1alpha1
  634. kind: BucketClaim
  635. metadata:
  636. name: ` + name + `
  637. namespace: ` + m.settings.OperatorNamespace + `
  638. spec:
  639. bucketClassName: ` + bucketClassName + `
  640. protocols:
  641. - s3 `
  642. }