resources.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. Copyright 2018 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 v1
  14. import (
  15. v1 "k8s.io/api/core/v1"
  16. )
  17. const (
  18. // ResourcesKeyMon represents the name of resource in the CR for a mon
  19. ResourcesKeyMon = "mon"
  20. // ResourcesKeyMgr represents the name of resource in the CR for a mgr
  21. ResourcesKeyMgr = "mgr"
  22. // ResourcesKeyMgrSidecar represents the name of resource in the CR for a mgr
  23. ResourcesKeyMgrSidecar = "mgr-sidecar"
  24. // ResourcesKeyOSD represents the name of a resource in the CR for all OSDs
  25. ResourcesKeyOSD = "osd"
  26. // ResourcesKeyPrepareOSD represents the name of resource in the CR for the osd prepare job
  27. ResourcesKeyPrepareOSD = "prepareosd"
  28. // ResourcesKeyMDS represents the name of resource in the CR for the mds
  29. ResourcesKeyMDS = "mds"
  30. // ResourcesKeyCrashCollector represents the name of resource in the CR for the crash
  31. ResourcesKeyCrashCollector = "crashcollector"
  32. // ResourcesKeyLogCollector represents the name of resource in the CR for the log
  33. ResourcesKeyLogCollector = "logcollector"
  34. // ResourcesKeyRBDMirror represents the name of resource in the CR for the rbd mirror
  35. ResourcesKeyRBDMirror = "rbdmirror"
  36. // ResourcesKeyFilesystemMirror represents the name of resource in the CR for the filesystem mirror
  37. ResourcesKeyFilesystemMirror = "fsmirror"
  38. // ResourcesKeyCleanup represents the name of resource in the CR for the cleanup
  39. ResourcesKeyCleanup = "cleanup"
  40. // ResourcesKeyCleanup represents the name of resource in the CR for ceph-exporter
  41. ResourcesKeyCephExporter = "exporter"
  42. )
  43. // GetMgrResources returns the placement for the MGR service
  44. func GetMgrResources(p ResourceSpec) v1.ResourceRequirements {
  45. return p[ResourcesKeyMgr]
  46. }
  47. // GetMgrSidecarResources returns the placement for the MGR sidecar container
  48. func GetMgrSidecarResources(p ResourceSpec) v1.ResourceRequirements {
  49. return p[ResourcesKeyMgrSidecar]
  50. }
  51. // GetMonResources returns the placement for the monitors
  52. func GetMonResources(p ResourceSpec) v1.ResourceRequirements {
  53. return p[ResourcesKeyMon]
  54. }
  55. // GetOSDResources returns the placement for all OSDs or for OSDs of specified device class (hdd, nvme, ssd)
  56. func GetOSDResources(p ResourceSpec, deviceClass string) v1.ResourceRequirements {
  57. if deviceClass == "" {
  58. return p[ResourcesKeyOSD]
  59. }
  60. // if device class specified, but not set in requirements return common osd requirements if present
  61. r, ok := p[getOSDResourceKeyForDeviceClass(deviceClass)]
  62. if ok {
  63. return r
  64. }
  65. return p[ResourcesKeyOSD]
  66. }
  67. // getOSDResourceKeyForDeviceClass returns key name for device class in resources spec
  68. func getOSDResourceKeyForDeviceClass(deviceClass string) string {
  69. return ResourcesKeyOSD + "-" + deviceClass
  70. }
  71. // GetPrepareOSDResources returns the placement for the OSDs prepare job
  72. func GetPrepareOSDResources(p ResourceSpec) v1.ResourceRequirements {
  73. return p[ResourcesKeyPrepareOSD]
  74. }
  75. // GetCrashCollectorResources returns the placement for the crash daemon
  76. func GetCrashCollectorResources(p ResourceSpec) v1.ResourceRequirements {
  77. return p[ResourcesKeyCrashCollector]
  78. }
  79. // GetLogCollectorResources returns the placement for the crash daemon
  80. func GetLogCollectorResources(p ResourceSpec) v1.ResourceRequirements {
  81. return p[ResourcesKeyLogCollector]
  82. }
  83. // GetCleanupResources returns the placement for the cleanup job
  84. func GetCleanupResources(p ResourceSpec) v1.ResourceRequirements {
  85. return p[ResourcesKeyCleanup]
  86. }
  87. // GetCleanupResources returns the placement for the cleanup job
  88. func GetCephExporterResources(p ResourceSpec) v1.ResourceRequirements {
  89. return p[ResourcesKeyCephExporter]
  90. }