osd: refactor code
Simplify osd management code.
Signed-off-by: Satoru Takeuchi <satoru.takeuchi@gmail.com>
(cherry picked from commit 00b3d0f323)
This commit is contained in:
1 parent
24f6fdf67d
commit
33e52648c2
4 files changed
+122
-139
No files matched your search
@@ -432,9 +432,8 @@ func getAvailableDevices(context *clusterd.Context, agent *OsdAgent) (*DeviceOsd
|
||||
if !isAvailable {
|
||||
logger.Infof("skipping device %q: %s.", device.Name, rejectedReason)
|
||||
continue
|
||||
} else {
|
||||
logger.Infof("device %q is available.", device.Name)
|
||||
}
|
||||
logger.Infof("device %q is available.", device.Name)
|
||||
|
||||
var deviceInfo *DeviceOsdIDEntry
|
||||
if agent.metadataDevice != "" && agent.metadataDevice == device.Name {
|
||||
@@ -497,23 +496,22 @@ func getAvailableDevices(context *clusterd.Context, agent *OsdAgent) (*DeviceOsd
|
||||
continue
|
||||
}
|
||||
}
|
||||
matchedDevice = desiredDevice
|
||||
|
||||
if matchedDevice.DeviceClass == "" {
|
||||
classNotSet := true
|
||||
if agent.pvcBacked {
|
||||
crushDeviceClass := os.Getenv(oposd.CrushDeviceClassVarName)
|
||||
if crushDeviceClass != "" {
|
||||
matchedDevice.DeviceClass = crushDeviceClass
|
||||
classNotSet = false
|
||||
}
|
||||
}
|
||||
if classNotSet {
|
||||
matchedDevice.DeviceClass = sys.GetDiskDeviceClass(device)
|
||||
}
|
||||
}
|
||||
|
||||
if matched {
|
||||
matchedDevice = desiredDevice
|
||||
if matchedDevice.DeviceClass == "" {
|
||||
classNotSet := true
|
||||
if agent.pvcBacked {
|
||||
crushDeviceClass := os.Getenv(oposd.CrushDeviceClassVarName)
|
||||
if crushDeviceClass != "" {
|
||||
matchedDevice.DeviceClass = crushDeviceClass
|
||||
classNotSet = false
|
||||
}
|
||||
}
|
||||
if classNotSet {
|
||||
matchedDevice.DeviceClass = sys.GetDiskDeviceClass(device)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,10 +205,6 @@ func (a *OsdAgent) configureCVDevices(context *clusterd.Context, devices *Device
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// If running on OSD on PVC
|
||||
if a.pvcBacked {
|
||||
if block, metadataBlock, walBlock, err = a.initializeBlockPVC(context, devices, lvBackedPV); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to initialize devices on PVC")
|
||||
}
|
||||
|
||||
@@ -38,9 +38,7 @@ func (c *Cluster) makeJob(osdProps osdProperties, provisionConfig *provisionConf
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !osdProps.onPVC() {
|
||||
podSpec.Spec.NodeSelector = map[string]string{v1.LabelHostname: osdProps.crushHostname}
|
||||
} else {
|
||||
if osdProps.onPVC() {
|
||||
// This is not needed in raw mode and 14.2.8 brings it
|
||||
// but we still want to do this not to lose backward compatibility with lvm based OSDs...
|
||||
podSpec.Spec.InitContainers = append(podSpec.Spec.InitContainers, c.getPVCInitContainer(osdProps))
|
||||
@@ -50,6 +48,8 @@ func (c *Cluster) makeJob(osdProps osdProperties, provisionConfig *provisionConf
|
||||
if osdProps.onPVCWithWal() {
|
||||
podSpec.Spec.InitContainers = append(podSpec.Spec.InitContainers, c.getPVCWalInitContainer("/wal", osdProps))
|
||||
}
|
||||
} else {
|
||||
podSpec.Spec.NodeSelector = map[string]string{v1.LabelHostname: osdProps.crushHostname}
|
||||
}
|
||||
|
||||
job := &batch.Job{
|
||||
@@ -108,12 +108,6 @@ func (c *Cluster) provisionPodTemplateSpec(osdProps osdProperties, restart v1.Re
|
||||
udevVolume := v1.Volume{Name: "udev", VolumeSource: v1.VolumeSource{HostPath: &v1.HostPathVolumeSource{Path: "/run/udev"}}}
|
||||
volumes = append(volumes, udevVolume)
|
||||
|
||||
// If not running on PVC we mount the rootfs of the host to validate the presence of the LVM package
|
||||
if !osdProps.onPVC() {
|
||||
rootFSVolume := v1.Volume{Name: "rootfs", VolumeSource: v1.VolumeSource{HostPath: &v1.HostPathVolumeSource{Path: "/"}}}
|
||||
volumes = append(volumes, rootFSVolume)
|
||||
}
|
||||
|
||||
if osdProps.onPVC() {
|
||||
// Create volume config for PVCs
|
||||
volumes = append(volumes, getPVCOSDVolumes(&osdProps, c.spec.DataDirHostPath, c.clusterInfo.Namespace, true)...)
|
||||
@@ -126,6 +120,10 @@ func (c *Cluster) provisionPodTemplateSpec(osdProps osdProperties, restart v1.Re
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If not running on PVC we mount the rootfs of the host to validate the presence of the LVM package
|
||||
rootFSVolume := v1.Volume{Name: "rootfs", VolumeSource: v1.VolumeSource{HostPath: &v1.HostPathVolumeSource{Path: "/"}}}
|
||||
volumes = append(volumes, rootFSVolume)
|
||||
}
|
||||
|
||||
if len(volumes) == 0 {
|
||||
@@ -235,11 +233,6 @@ func (c *Cluster) provisionOSDContainer(osdProps osdProperties, copyBinariesMoun
|
||||
copyBinariesMount,
|
||||
}...)
|
||||
|
||||
// If not running on PVC we mount the rootfs of the host to validate the presence of the LVM package
|
||||
if !osdProps.onPVC() {
|
||||
volumeMounts = append(volumeMounts, v1.VolumeMount{Name: "rootfs", MountPath: "/rootfs", ReadOnly: true})
|
||||
}
|
||||
|
||||
// If the OSD runs on PVC
|
||||
if osdProps.onPVC() {
|
||||
volumeMounts = append(volumeMounts, getPvcOSDBridgeMount(osdProps.pvc.ClaimName))
|
||||
@@ -287,6 +280,9 @@ func (c *Cluster) provisionOSDContainer(osdProps osdProperties, copyBinariesMoun
|
||||
envVars = append(envVars, cephVolumeRawEncryptedEnvVarFromSecret(osdProps))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If not running on PVC we mount the rootfs of the host to validate the presence of the LVM package
|
||||
volumeMounts = append(volumeMounts, v1.VolumeMount{Name: "rootfs", MountPath: "/rootfs", ReadOnly: true})
|
||||
}
|
||||
|
||||
// run privileged always since we always mount /dev
|
||||
|
||||
@@ -358,32 +358,35 @@ func (c *Cluster) makeDeployment(osdProps osdProperties, osd OSDInfo, provisionC
|
||||
var command []string
|
||||
var args []string
|
||||
// If the OSD was prepared with ceph-volume and running on PVC and using the LVM mode
|
||||
if osdProps.onPVC() && osd.CVMode == "lvm" {
|
||||
// if the osd was provisioned by ceph-volume, we need to launch it with rook as the parent process
|
||||
command = []string{path.Join(rookBinariesMountPath, "rook")}
|
||||
args = []string{
|
||||
"ceph", "osd", "start",
|
||||
"--",
|
||||
"--foreground",
|
||||
"--id", osdID,
|
||||
"--fsid", c.clusterInfo.FSID,
|
||||
"--cluster", "ceph",
|
||||
"--setuser", "ceph",
|
||||
"--setgroup", "ceph",
|
||||
fmt.Sprintf("--crush-location=%s", osd.Location),
|
||||
}
|
||||
osd.LVBackedPV = true
|
||||
} else if osdProps.onPVC() && osd.CVMode == "raw" {
|
||||
doBinaryCopyInit = false
|
||||
doConfigInit = false
|
||||
command = []string{"ceph-osd"}
|
||||
args = []string{
|
||||
"--foreground",
|
||||
"--id", osdID,
|
||||
"--fsid", c.clusterInfo.FSID,
|
||||
"--setuser", "ceph",
|
||||
"--setgroup", "ceph",
|
||||
fmt.Sprintf("--crush-location=%s", osd.Location),
|
||||
if osdProps.onPVC() {
|
||||
if osd.CVMode == "lvm" {
|
||||
// if the osd was provisioned by ceph-volume, we need to launch it with rook as the parent process
|
||||
command = []string{path.Join(rookBinariesMountPath, "rook")}
|
||||
args = []string{
|
||||
"ceph", "osd", "start",
|
||||
"--",
|
||||
"--foreground",
|
||||
"--id", osdID,
|
||||
"--fsid", c.clusterInfo.FSID,
|
||||
"--cluster", "ceph",
|
||||
"--setuser", "ceph",
|
||||
"--setgroup", "ceph",
|
||||
fmt.Sprintf("--crush-location=%s", osd.Location),
|
||||
}
|
||||
osd.LVBackedPV = true
|
||||
} else {
|
||||
// raw mode
|
||||
doBinaryCopyInit = false
|
||||
doConfigInit = false
|
||||
command = []string{"ceph-osd"}
|
||||
args = []string{
|
||||
"--foreground",
|
||||
"--id", osdID,
|
||||
"--fsid", c.clusterInfo.FSID,
|
||||
"--setuser", "ceph",
|
||||
"--setgroup", "ceph",
|
||||
fmt.Sprintf("--crush-location=%s", osd.Location),
|
||||
}
|
||||
}
|
||||
} else {
|
||||
doBinaryCopyInit = false
|
||||
@@ -440,31 +443,21 @@ func (c *Cluster) makeDeployment(osdProps osdProperties, osd OSDInfo, provisionC
|
||||
volumeMounts = append(volumeMounts, copyBinariesContainer.VolumeMounts[0])
|
||||
}
|
||||
|
||||
// Add the volume to the spec and the mount to the daemon container
|
||||
// so that it can pick the already mounted/activated osd metadata path
|
||||
// This container will activate the OSD and place the activated filesinto an empty dir
|
||||
// The empty dir will be shared by the "activate-osd" pod and the "osd" main pod
|
||||
activateOSDVolume, activateOSDContainer := c.getActivateOSDInitContainer(c.spec.DataDirHostPath, c.clusterInfo.Namespace, osdID, osd, osdProps)
|
||||
if !osdProps.onPVC() {
|
||||
volumes = append(volumes, activateOSDVolume...)
|
||||
volumeMounts = append(volumeMounts, activateOSDContainer.VolumeMounts[0])
|
||||
}
|
||||
|
||||
args = append(args, opconfig.LoggingFlags()...)
|
||||
args = append(args, osdOnSDNFlag(c.spec.Network)...)
|
||||
args = append(args, controller.NetworkBindingFlags(c.clusterInfo, &c.spec)...)
|
||||
|
||||
osdDataDirPath := activateOSDMountPath + osdID
|
||||
if osdProps.onPVC() && osd.CVMode == "lvm" {
|
||||
// Let's use the old bridge for these lvm based pvc osds
|
||||
volumeMounts = append(volumeMounts, getPvcOSDBridgeMount(osdProps.pvc.ClaimName))
|
||||
envVars = append(envVars, pvcBackedOSDEnvVar("true"))
|
||||
envVars = append(envVars, lvBackedPVEnvVar(strconv.FormatBool(osd.LVBackedPV)))
|
||||
}
|
||||
|
||||
if osdProps.onPVC() && osd.CVMode == "raw" {
|
||||
volumeMounts = append(volumeMounts, getPvcOSDBridgeMountActivate(osdDataDirPath, osdProps.pvc.ClaimName))
|
||||
if osdProps.onPVC() {
|
||||
envVars = append(envVars, pvcBackedOSDEnvVar("true"))
|
||||
if osd.CVMode == "lvm" {
|
||||
// Let's use the old bridge for these lvm based pvc osds
|
||||
volumeMounts = append(volumeMounts, getPvcOSDBridgeMount(osdProps.pvc.ClaimName))
|
||||
envVars = append(envVars, lvBackedPVEnvVar(strconv.FormatBool(osd.LVBackedPV)))
|
||||
} else {
|
||||
// raw mode
|
||||
volumeMounts = append(volumeMounts, getPvcOSDBridgeMountActivate(osdDataDirPath, osdProps.pvc.ClaimName))
|
||||
}
|
||||
}
|
||||
|
||||
// We cannot go un-privileged until we have a bindmount for logs and crash
|
||||
@@ -500,35 +493,6 @@ func (c *Cluster) makeDeployment(osdProps osdProperties, osd OSDInfo, provisionC
|
||||
initContainers = append(initContainers, *copyBinariesContainer)
|
||||
}
|
||||
|
||||
if osdProps.onPVC() && osd.CVMode == "lvm" {
|
||||
initContainers = append(initContainers, c.getPVCInitContainer(osdProps))
|
||||
} else if osdProps.onPVC() && osd.CVMode == "raw" {
|
||||
// Copy main block device to an empty dir
|
||||
initContainers = append(initContainers, c.getPVCInitContainerActivate(osdDataDirPath, osdProps))
|
||||
// Copy main block.db device to an empty dir
|
||||
if osdProps.onPVCWithMetadata() {
|
||||
initContainers = append(initContainers, c.getPVCMetadataInitContainerActivate(osdDataDirPath, osdProps))
|
||||
}
|
||||
// Copy main block.wal device to an empty dir
|
||||
if osdProps.onPVCWithWal() {
|
||||
initContainers = append(initContainers, c.getPVCWalInitContainerActivate(osdDataDirPath, osdProps))
|
||||
}
|
||||
if osdProps.encrypted {
|
||||
// Open the encrypted disk
|
||||
initContainers = append(initContainers, c.getPVCEncryptionOpenInitContainerActivate(osdDataDirPath, osdProps)...)
|
||||
// Copy the encrypted block to the osd data location, e,g: /var/lib/ceph/osd/ceph-0/block
|
||||
initContainers = append(initContainers, c.getPVCEncryptionInitContainerActivate(osdDataDirPath, osdProps)...)
|
||||
// Print the encrypted block status
|
||||
initContainers = append(initContainers, c.getEncryptedStatusPVCInitContainer(osdDataDirPath, osdProps))
|
||||
// Resize the encrypted device if necessary, this must be done after the encrypted block is opened
|
||||
initContainers = append(initContainers, c.getExpandEncryptedPVCInitContainer(osdDataDirPath, osdProps))
|
||||
}
|
||||
initContainers = append(initContainers, c.getActivatePVCInitContainer(osdProps, osdID))
|
||||
initContainers = append(initContainers, c.getExpandPVCInitContainer(osdProps, osdID))
|
||||
} else {
|
||||
initContainers = append(initContainers, *activateOSDContainer)
|
||||
}
|
||||
|
||||
// For OSD on PVC with LVM the directory does not exist yet
|
||||
// It gets created by the 'ceph-volume lvm activate' command
|
||||
//
|
||||
@@ -536,9 +500,45 @@ func (c *Cluster) makeDeployment(osdProps osdProperties, osd OSDInfo, provisionC
|
||||
// So we don't need to chown it again
|
||||
dataPath := ""
|
||||
|
||||
// Raw mode on PVC needs this path so that OSD's metadata files can be chown after 'ceph-bluestore-tool' ran
|
||||
if osd.CVMode == "raw" && osdProps.onPVC() {
|
||||
dataPath = activateOSDMountPath + osdID
|
||||
if osdProps.onPVC() {
|
||||
if osd.CVMode == "lvm" {
|
||||
initContainers = append(initContainers, c.getPVCInitContainer(osdProps))
|
||||
} else {
|
||||
// Raw mode on PVC needs this path so that OSD's metadata files can be chown after 'ceph-bluestore-tool' ran
|
||||
dataPath = activateOSDMountPath + osdID
|
||||
|
||||
// Copy main block device to an empty dir
|
||||
initContainers = append(initContainers, c.getPVCInitContainerActivate(osdDataDirPath, osdProps))
|
||||
// Copy main block.db device to an empty dir
|
||||
if osdProps.onPVCWithMetadata() {
|
||||
initContainers = append(initContainers, c.getPVCMetadataInitContainerActivate(osdDataDirPath, osdProps))
|
||||
}
|
||||
// Copy main block.wal device to an empty dir
|
||||
if osdProps.onPVCWithWal() {
|
||||
initContainers = append(initContainers, c.getPVCWalInitContainerActivate(osdDataDirPath, osdProps))
|
||||
}
|
||||
if osdProps.encrypted {
|
||||
// Open the encrypted disk
|
||||
initContainers = append(initContainers, c.getPVCEncryptionOpenInitContainerActivate(osdDataDirPath, osdProps)...)
|
||||
// Copy the encrypted block to the osd data location, e,g: /var/lib/ceph/osd/ceph-0/block
|
||||
initContainers = append(initContainers, c.getPVCEncryptionInitContainerActivate(osdDataDirPath, osdProps)...)
|
||||
// Print the encrypted block status
|
||||
initContainers = append(initContainers, c.getEncryptedStatusPVCInitContainer(osdDataDirPath, osdProps))
|
||||
// Resize the encrypted device if necessary, this must be done after the encrypted block is opened
|
||||
initContainers = append(initContainers, c.getExpandEncryptedPVCInitContainer(osdDataDirPath, osdProps))
|
||||
}
|
||||
initContainers = append(initContainers, c.getActivatePVCInitContainer(osdProps, osdID))
|
||||
initContainers = append(initContainers, c.getExpandPVCInitContainer(osdProps, osdID))
|
||||
}
|
||||
} else {
|
||||
// Add the volume to the spec and the mount to the daemon container
|
||||
// so that it can pick the already mounted/activated osd metadata path
|
||||
// This container will activate the OSD and place the activated filesinto an empty dir
|
||||
// The empty dir will be shared by the "activate-osd" pod and the "osd" main pod
|
||||
activateOSDVolume, activateOSDContainer := c.getActivateOSDInitContainer(c.spec.DataDirHostPath, c.clusterInfo.Namespace, osdID, osd, osdProps)
|
||||
volumes = append(volumes, activateOSDVolume...)
|
||||
volumeMounts = append(volumeMounts, activateOSDContainer.VolumeMounts[0])
|
||||
initContainers = append(initContainers, *activateOSDContainer)
|
||||
}
|
||||
|
||||
// Doing a chown in a post start lifecycle hook does not reliably complete before the OSD
|
||||
@@ -638,15 +638,26 @@ func (c *Cluster) makeDeployment(osdProps osdProperties, osd OSDInfo, provisionC
|
||||
k8sutil.AddLabelToDeployment(CephDeviceSetLabelKey, osdProps.deviceSetName, deployment)
|
||||
k8sutil.AddLabelToPod(OSDOverPVCLabelKey, osdProps.pvc.ClaimName, &deployment.Spec.Template)
|
||||
k8sutil.AddLabelToPod(CephDeviceSetLabelKey, osdProps.deviceSetName, &deployment.Spec.Template)
|
||||
// Replace default unreachable node toleration if the osd pod is portable and based in PVC
|
||||
if osdProps.portable {
|
||||
k8sutil.AddUnreachableNodeToleration(&deployment.Spec.Template.Spec)
|
||||
}
|
||||
c.applyAllPlacementIfNeeded(&deployment.Spec.Template.Spec)
|
||||
// apply storageClassDeviceSets.Placement
|
||||
osdProps.placement.ApplyToPodSpec(&deployment.Spec.Template.Spec)
|
||||
} else {
|
||||
c.applyAllPlacementIfNeeded(&deployment.Spec.Template.Spec)
|
||||
// apply c.spec.Placement.osd
|
||||
c.spec.Placement[cephv1.KeyOSD].ApplyToPodSpec(&deployment.Spec.Template.Spec)
|
||||
}
|
||||
if !osdProps.portable {
|
||||
if osdProps.portable {
|
||||
// portable OSDs must have affinity to the topology where the osd prepare job was executed
|
||||
if err := applyTopologyAffinity(&deployment.Spec.Template.Spec, osd); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
deployment.Spec.Template.Spec.NodeSelector = map[string]string{v1.LabelHostname: osdProps.crushHostname}
|
||||
}
|
||||
// Replace default unreachable node toleration if the osd pod is portable and based in PVC
|
||||
if osdProps.onPVC() && osdProps.portable {
|
||||
k8sutil.AddUnreachableNodeToleration(&deployment.Spec.Template.Spec)
|
||||
}
|
||||
|
||||
k8sutil.AddRookVersionLabelToDeployment(deployment)
|
||||
cephv1.GetOSDAnnotations(c.spec.Annotations).ApplyToObjectMeta(&deployment.ObjectMeta)
|
||||
cephv1.GetOSDAnnotations(c.spec.Annotations).ApplyToObjectMeta(&deployment.Spec.Template.ObjectMeta)
|
||||
@@ -659,23 +670,6 @@ func (c *Cluster) makeDeployment(osdProps osdProperties, osd OSDInfo, provisionC
|
||||
return nil, errors.Wrapf(err, "failed to set owner reference to osd deployment %q", deployment.Name)
|
||||
}
|
||||
|
||||
if osdProps.onPVC() {
|
||||
c.applyAllPlacementIfNeeded(&deployment.Spec.Template.Spec)
|
||||
// apply storageClassDeviceSets.Placement
|
||||
osdProps.placement.ApplyToPodSpec(&deployment.Spec.Template.Spec)
|
||||
} else {
|
||||
c.applyAllPlacementIfNeeded(&deployment.Spec.Template.Spec)
|
||||
// apply c.spec.Placement.osd
|
||||
c.spec.Placement[cephv1.KeyOSD].ApplyToPodSpec(&deployment.Spec.Template.Spec)
|
||||
}
|
||||
|
||||
// portable OSDs must have affinity to the topology where the osd prepare job was executed
|
||||
if osdProps.portable {
|
||||
if err := applyTopologyAffinity(&deployment.Spec.Template.Spec, osd); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Change TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES if the OSD has been annotated with a value
|
||||
osdAnnotations := cephv1.GetOSDAnnotations(c.spec.Annotations)
|
||||
tcmallocMaxTotalThreadCacheBytes, ok := osdAnnotations[tcmallocMaxTotalThreadCacheBytesEnv]
|
||||
@@ -758,9 +752,6 @@ func (c *Cluster) getActivateOSDInitContainer(configDir, namespace, osdID string
|
||||
},
|
||||
}
|
||||
|
||||
adminKeyringVol, adminKeyringVolMount := cephkey.Volume().Admin(), cephkey.VolumeMount().Admin()
|
||||
volume = append(volume, adminKeyringVol)
|
||||
|
||||
envVars := append(
|
||||
osdActivateEnvVar(),
|
||||
blockPathEnvVariable(osdInfo.BlockPath),
|
||||
@@ -773,12 +764,14 @@ func (c *Cluster) getActivateOSDInitContainer(configDir, namespace, osdID string
|
||||
// Build empty dir osd path to something like "/var/lib/ceph/osd/ceph-0"
|
||||
activateOSDMountPathID := activateOSDMountPath + osdID
|
||||
|
||||
adminKeyringVol, adminKeyringVolMount := cephkey.Volume().Admin(), cephkey.VolumeMount().Admin()
|
||||
volume = append(volume, adminKeyringVol)
|
||||
volMounts := []v1.VolumeMount{
|
||||
{Name: activateOSDVolumeName, MountPath: activateOSDMountPathID},
|
||||
{Name: "devices", MountPath: "/dev"},
|
||||
{Name: k8sutil.ConfigOverrideName, ReadOnly: true, MountPath: tempEtcCephDir},
|
||||
adminKeyringVolMount,
|
||||
}
|
||||
volMounts = append(volMounts, adminKeyringVolMount)
|
||||
|
||||
if osdProps.onPVC() {
|
||||
volMounts = append(volMounts, getPvcOSDBridgeMount(osdProps.pvc.ClaimName))
|
||||
|
||||
Reference in new issue
Block a user