/
storage.go
141 lines (117 loc) · 3.95 KB
/
storage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
Copyright 2016 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package osd for the Ceph OSDs.
package v1alpha1
const bluestore = "bluestore"
// AnyUseAllDevices gets whether to use all devices
func (s *StorageSpec) AnyUseAllDevices() bool {
if s.Selection.GetUseAllDevices() {
return true
}
for _, n := range s.Nodes {
if n.Selection.GetUseAllDevices() {
return true
}
}
return false
}
// ClearUseAllDevices clears all devices
func (s *StorageSpec) ClearUseAllDevices() {
clear := false
s.Selection.UseAllDevices = &clear
for i := range s.Nodes {
s.Nodes[i].Selection.UseAllDevices = &clear
}
}
// Fully resolves the config of the given node name, taking into account cluster level and node level specified config.
// In general, the more fine grained the configuration is specified, the more precedence it takes. Fully resolved
// configuration for the node has the following order of precedence.
// 1) Node (config defined on the node itself)
// 2) Cluster (config defined on the cluster)
// 3) Default values (if no config exists for the node or cluster)
func (s *StorageSpec) ResolveNode(nodeName string) *Node {
// find the requested storage node first, if it exists
var node *Node
for i := range s.Nodes {
if s.Nodes[i].Name == nodeName {
node = &(s.Nodes[i])
break
}
}
if node == nil {
// a node with the given name was not found
return nil
}
// now resolve all properties that haven't already been set on the node
s.resolveNodeSelection(node)
s.resolveNodeConfig(node)
return node
}
func (s *StorageSpec) resolveNodeSelection(node *Node) {
resolveString(&(node.Selection.DeviceFilter), s.Selection.DeviceFilter, "")
resolveString(&(node.Selection.MetadataDevice), s.Selection.MetadataDevice, "")
if node.Selection.UseAllDevices == nil {
if s.Selection.UseAllDevices != nil {
// the node does not have a value specified for use all devices, but the cluster does. Use the cluster's.
node.Selection.UseAllDevices = s.Selection.UseAllDevices
} else {
// neither node nor cluster have a value set for use all devices, use the default value.
node.Selection.UseAllDevices = newBool(false)
}
}
if len(node.Selection.Directories) == 0 {
node.Selection.Directories = s.Directories
}
}
func (s *StorageSpec) resolveNodeConfig(node *Node) {
resolveString(&(node.Config.StoreConfig.StoreType), s.Config.StoreConfig.StoreType, bluestore)
resolveInt(&(node.Config.StoreConfig.DatabaseSizeMB), s.Config.StoreConfig.DatabaseSizeMB, 0)
resolveInt(&(node.Config.StoreConfig.WalSizeMB), s.Config.StoreConfig.WalSizeMB, 0)
resolveInt(&(node.Config.StoreConfig.JournalSizeMB), s.Config.StoreConfig.JournalSizeMB, 0)
resolveString(&(node.Config.Location), s.Config.Location, "")
}
func (s *Selection) GetUseAllDevices() bool {
return s.UseAllDevices != nil && *(s.UseAllDevices)
}
func resolveString(setting *string, parent, defaultVal string) {
if *setting == "" {
if parent != "" {
*setting = parent
} else {
*setting = defaultVal
}
}
}
func resolveInt(setting *int, parent, defaultVal int) {
if *setting == 0 {
if parent != 0 {
*setting = parent
} else {
*setting = defaultVal
}
}
}
func newBool(val bool) *bool {
return &val
}
// NodesByName implements an interface to sort nodes by name
type NodesByName []Node
func (s NodesByName) Len() int {
return len(s)
}
func (s NodesByName) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s NodesByName) Less(i, j int) bool {
return s[i].Name < s[j].Name
}