-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
volumes.go
245 lines (213 loc) · 6.96 KB
/
volumes.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
Copyright 2020 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
import (
"fmt"
"path"
"path/filepath"
"github.com/libopenstorage/secrets"
kms "github.com/rook/rook/pkg/daemon/ceph/osd/kms"
"github.com/rook/rook/pkg/operator/ceph/config"
v1 "k8s.io/api/core/v1"
)
const (
udevPath = "/run/udev"
udevVolName = "run-udev"
osdEncryptionVolName = "osd-encryption-key"
dmPath = "/dev/mapper"
dmVolName = "dev-mapper"
)
func getPvcOSDBridgeMount(claimName string) v1.VolumeMount {
return v1.VolumeMount{
Name: fmt.Sprintf("%s-bridge", claimName),
MountPath: "/mnt",
}
}
func getPvcOSDBridgeMountActivate(mountPath, claimName string) v1.VolumeMount {
return v1.VolumeMount{
Name: fmt.Sprintf("%s-bridge", claimName),
MountPath: mountPath,
SubPath: path.Base(mountPath),
}
}
func getPvcMetadataOSDBridgeMount(claimName string) v1.VolumeMount {
return v1.VolumeMount{
Name: fmt.Sprintf("%s-bridge", claimName),
MountPath: "/srv",
}
}
func getPvcWalOSDBridgeMount(claimName string) v1.VolumeMount {
return v1.VolumeMount{
Name: fmt.Sprintf("%s-bridge", claimName),
MountPath: "/wal",
}
}
func getDeviceMapperMount() v1.VolumeMount {
return v1.VolumeMount{
MountPath: dmPath,
Name: dmVolName,
}
}
func getDeviceMapperVolume() (v1.Volume, v1.VolumeMount) {
volume := v1.Volume{
Name: dmVolName,
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{Path: dmPath},
},
}
volumeMounts := v1.VolumeMount{
Name: dmVolName,
MountPath: dmPath,
}
return volume, volumeMounts
}
func getDataBridgeVolumeSource(claimName, configDir, namespace string, inProvisioning bool) v1.VolumeSource {
var source v1.VolumeSource
if inProvisioning {
source.EmptyDir = &v1.EmptyDirVolumeSource{
Medium: "Memory",
}
} else {
// We need to use hostPath to prevent multiple OSD pods from launching the same OSD and causing corruption.
// Ceph avoids this problem by locking fsid file and block device file under the data bridge volume directory.
// These locks are released by kernel once the process is gone, so until the ceph-osd daemon alives, the other
// pods (same OSD) will not be able to acquire them and will continue to be restarted.
// If we use emptyDir, this exclusive control doesn't work because the lock files aren't shared between OSD pods.
hostPathType := v1.HostPathDirectoryOrCreate
source.HostPath = &v1.HostPathVolumeSource{
Path: filepath.Join(
configDir,
namespace,
claimName),
Type: &hostPathType,
}
}
return source
}
func getPVCOSDVolumes(osdProps *osdProperties, configDir string, namespace string, prepare bool) []v1.Volume {
volumes := []v1.Volume{
{
Name: osdProps.pvc.ClaimName,
VolumeSource: v1.VolumeSource{
PersistentVolumeClaim: &osdProps.pvc,
},
},
{
// We need a bridge mount which is basically a common volume mount between the non privileged init container
// and the privileged provision container or osd daemon container
// The reason for this is mentioned in the comment for getPVCInitContainer() method
Name: fmt.Sprintf("%s-bridge", osdProps.pvc.ClaimName),
VolumeSource: getDataBridgeVolumeSource(osdProps.pvc.ClaimName, configDir, namespace, prepare),
},
}
// If we have a metadata PVC let's add it
if osdProps.onPVCWithMetadata() {
metadataPVCVolume := []v1.Volume{
{
Name: osdProps.metadataPVC.ClaimName,
VolumeSource: v1.VolumeSource{
PersistentVolumeClaim: &osdProps.metadataPVC,
},
},
{
// We need a bridge mount which is basically a common volume mount between the non privileged init container
// and the privileged provision container or osd daemon container
// The reason for this is mentioned in the comment for getPVCInitContainer() method
Name: fmt.Sprintf("%s-bridge", osdProps.metadataPVC.ClaimName),
VolumeSource: getDataBridgeVolumeSource(osdProps.metadataPVC.ClaimName, configDir, namespace, prepare),
},
}
volumes = append(volumes, metadataPVCVolume...)
}
// If we have a wal PVC let's add it
if osdProps.onPVCWithWal() {
walPVCVolume := []v1.Volume{
{
Name: osdProps.walPVC.ClaimName,
VolumeSource: v1.VolumeSource{
PersistentVolumeClaim: &osdProps.walPVC,
},
},
{
// We need a bridge mount which is basically a common volume mount between the non privileged init container
// and the privileged provision container or osd daemon container
// The reason for this is mentioned in the comment for getPVCInitContainer() method
Name: fmt.Sprintf("%s-bridge", osdProps.walPVC.ClaimName),
VolumeSource: getDataBridgeVolumeSource(osdProps.walPVC.ClaimName, configDir, namespace, prepare),
},
}
volumes = append(volumes, walPVCVolume...)
}
logger.Debugf("volumes are %+v", volumes)
return volumes
}
func getUdevVolume() (v1.Volume, v1.VolumeMount) {
volume := v1.Volume{
Name: udevVolName,
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{Path: udevPath},
},
}
volumeMounts := v1.VolumeMount{
Name: udevVolName,
MountPath: udevPath,
}
return volume, volumeMounts
}
func (c *Cluster) getEncryptionVolume(osdProps osdProperties) (v1.Volume, v1.VolumeMount) {
// Determine whether we have a KMS configuration
var isKMS bool
if len(c.spec.Security.KeyManagementService.ConnectionDetails) != 0 {
provider := kms.GetParam(c.spec.Security.KeyManagementService.ConnectionDetails, kms.Provider)
if provider == secrets.TypeVault {
isKMS = true
}
}
// Generate volume
var m int32 = 0400
volume := v1.Volume{
Name: osdEncryptionVolName,
VolumeSource: v1.VolumeSource{
Secret: &v1.SecretVolumeSource{
SecretName: kms.GenerateOSDEncryptionSecretName(osdProps.pvc.ClaimName),
Items: []v1.KeyToPath{
{
Key: kms.OsdEncryptionSecretNameKeyName,
Path: encryptionKeyFileName,
},
},
DefaultMode: &m,
},
},
}
// On the KMS use case, we want the volume mount to be in memory since we pass write the KEK
if isKMS {
volume.VolumeSource.Secret = nil
volume.VolumeSource = v1.VolumeSource{
EmptyDir: &v1.EmptyDirVolumeSource{
Medium: v1.StorageMediumMemory,
},
}
}
// Mounts /etc/ceph/luks_key
volumeMounts := v1.VolumeMount{
Name: osdEncryptionVolName,
ReadOnly: true,
MountPath: config.EtcCephDir,
}
// With KMS we must be able to write inside the directory to write the KEK
if isKMS {
volumeMounts.ReadOnly = false
}
return volume, volumeMounts
}