From 7307575637ad4de40cde89256cfbc6780705d0df Mon Sep 17 00:00:00 2001 From: rohan47 Date: Fri, 23 Aug 2019 00:55:28 +0530 Subject: [PATCH] Added portable and failure-domain label to the OSD deployment Signed-off-by: rohan47 --- pkg/apis/rook.io/v1alpha2/types.go | 2 ++ pkg/operator/ceph/cluster/osd/deviceSet.go | 1 + pkg/operator/ceph/cluster/osd/osd.go | 5 +++++ pkg/operator/ceph/cluster/osd/spec.go | 25 ++++++++++++---------- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/pkg/apis/rook.io/v1alpha2/types.go b/pkg/apis/rook.io/v1alpha2/types.go index 294da30cf..b3ec86bc4 100644 --- a/pkg/apis/rook.io/v1alpha2/types.go +++ b/pkg/apis/rook.io/v1alpha2/types.go @@ -137,6 +137,7 @@ type StorageClassDeviceSet struct { Placement Placement `json:"placement,omitempty"` // Placement constraints for the devices Config map[string]string `json:"config,omitempty"` // Provider-specific device configuration VolumeClaimTemplates []v1.PersistentVolumeClaim `json:"volumeClaimTemplates,omitempty"` // List of PVC templates for the underlying storage devices + Portable bool `json:"portable,omitempty"` // OSD portablity across the hosts } type VolumeSource struct { @@ -145,4 +146,5 @@ type VolumeSource struct { Resources v1.ResourceRequirements `json:"resources,omitempty"` Placement Placement `json:"placement,omitempty"` Config map[string]string `json:"config,omitempty"` + Portable bool `json:"portable,omitempty"` // OSD portablity across the hosts } diff --git a/pkg/operator/ceph/cluster/osd/deviceSet.go b/pkg/operator/ceph/cluster/osd/deviceSet.go index 0f5a432e1..b7fab38a5 100644 --- a/pkg/operator/ceph/cluster/osd/deviceSet.go +++ b/pkg/operator/ceph/cluster/osd/deviceSet.go @@ -49,6 +49,7 @@ func (c *Cluster) prepareStorageClassDeviceSets(config *provisionConfig) []rooka ClaimName: pvc.GetName(), ReadOnly: false, }, + Portable: storageClassDeviceSet.Portable, }) logger.Infof("successfully provisioned osd for storageClassDeviceSet %s of set %v", storageClassDeviceSet.Name, i) } diff --git a/pkg/operator/ceph/cluster/osd/osd.go b/pkg/operator/ceph/cluster/osd/osd.go index 2157adf6f..7d061c770 100644 --- a/pkg/operator/ceph/cluster/osd/osd.go +++ b/pkg/operator/ceph/cluster/osd/osd.go @@ -57,6 +57,8 @@ const ( clusterAvailableSpaceReserve = 0.05 serviceAccountName = "rook-ceph-osd" unknownID = -1 + portableKey = "portable" + failureDomainKey = "failure-domain" cephOsdPodMinimumMemory uint64 = 4096 // minimum amount of memory in MB to run the pod ) @@ -143,6 +145,7 @@ type osdProperties struct { placement rookalpha.Placement metadataDevice string location string + portable bool } // Start the osd management @@ -233,6 +236,7 @@ func (c *Cluster) startProvisioningOverPVCs(config *provisionConfig) { pvc: volume.PersistentVolumeClaimSource, resources: volume.Resources, placement: volume.Placement, + portable: volume.Portable, } // update the orchestration status of this pvc to the starting state @@ -719,6 +723,7 @@ func (c *Cluster) getOSDPropsForPVC(pvcName string) (osdProperties, error) { pvc: volumeSource.PersistentVolumeClaimSource, resources: volumeSource.Resources, placement: volumeSource.Placement, + portable: volumeSource.Portable, }, nil } } diff --git a/pkg/operator/ceph/cluster/osd/spec.go b/pkg/operator/ceph/cluster/osd/spec.go index 51d2abf67..79e651a5d 100644 --- a/pkg/operator/ceph/cluster/osd/spec.go +++ b/pkg/operator/ceph/cluster/osd/spec.go @@ -103,6 +103,7 @@ func (c *Cluster) makeDeployment(osdProps osdProperties, osd OSDInfo) (*apps.Dep volumeMounts := opspec.CephVolumeMounts() configVolumeMounts := opspec.RookVolumeMounts() volumes := opspec.PodVolumes(c.dataDirHostPath, c.Namespace) + failureDomainValue := osdProps.crushHostname var dataDir string if osd.IsDirectory { @@ -286,11 +287,7 @@ func (c *Cluster) makeDeployment(osdProps osdProperties, osd OSDInfo) (*apps.Dep ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf(osdAppNameFmt, osd.ID), Namespace: c.Namespace, - Labels: map[string]string{ - k8sutil.AppAttr: appName, - k8sutil.ClusterAttr: c.Namespace, - osdLabelKey: fmt.Sprintf("%d", osd.ID), - }, + Labels: c.getOSDLabels(osd.ID, failureDomainValue, osdProps.portable), }, Spec: apps.DeploymentSpec{ Selector: &metav1.LabelSelector{ @@ -305,12 +302,8 @@ func (c *Cluster) makeDeployment(osdProps osdProperties, osd OSDInfo) (*apps.Dep }, Template: v1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ - Name: appName, - Labels: map[string]string{ - k8sutil.AppAttr: appName, - k8sutil.ClusterAttr: c.Namespace, - osdLabelKey: fmt.Sprintf("%d", osd.ID), - }, + Name: appName, + Labels: c.getOSDLabels(osd.ID, failureDomainValue, osdProps.portable), }, Spec: v1.PodSpec{ RestartPolicy: v1.RestartPolicyAlways, @@ -758,3 +751,13 @@ func makeStorageClassDeviceSetPVCLabel(storageClassDeviceSetName, pvcStorageClas CephDeviceSetPVCIDLabelKey: pvcStorageClassDeviceSetPVCId, } } + +func (c *Cluster) getOSDLabels(osdID int, failureDomainValue string, portable bool) map[string]string { + return map[string]string{ + k8sutil.AppAttr: appName, + k8sutil.ClusterAttr: c.Namespace, + osdLabelKey: fmt.Sprintf("%d", osdID), + failureDomainKey: failureDomainValue, + portableKey: strconv.FormatBool(portable), + } +}