cephfs: set cluster Name as metadata on the subvolume

This change helps read the cluster name from the cmdline args,
the provisioner will set the same on the subvolume.

Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
This commit is contained in:
Prasanna Kumar Kalever
2022-06-14 18:53:29 +05:30
committed by mergify[bot]
parent 25ce21f496
commit 21d811096b
8 changed files with 72 additions and 37 deletions

View File

@ -34,6 +34,7 @@ func fmtBackingSnapshotReftrackerName(backingSnapID string) string {
func AddSnapshotBackedVolumeRef(
ctx context.Context,
volOptions *VolumeOptions,
clusterName string,
) error {
ioctx, err := volOptions.conn.GetIoctx(volOptions.MetadataPool)
if err != nil {
@ -95,7 +96,7 @@ func AddSnapshotBackedVolumeRef(
// There may have been a race between adding a ref to the reftracker and
// deleting the backing snapshot. Make sure the snapshot still exists by
// trying to retrieve it again.
_, _, _, err = NewSnapshotOptionsFromID(ctx, volOptions.BackingSnapshotID, volOptions.conn.Creds)
_, _, _, err = NewSnapshotOptionsFromID(ctx, volOptions.BackingSnapshotID, volOptions.conn.Creds, clusterName)
if err != nil {
log.ErrorLog(ctx, "failed to get backing snapshot %s: %v", volOptions.BackingSnapshotID, err)
}

View File

@ -78,6 +78,7 @@ func CheckVolExists(ctx context.Context,
pvID *VolumeIdentifier,
sID *SnapshotIdentifier,
cr *util.Credentials,
clusterName string,
) (*VolumeIdentifier, error) {
var vid VolumeIdentifier
// Connect to cephfs' default radosNamespace (csi)
@ -99,7 +100,7 @@ func CheckVolExists(ctx context.Context,
vid.FsSubvolName = imageData.ImageAttributes.ImageName
volOptions.VolID = vid.FsSubvolName
vol := core.NewSubVolume(volOptions.conn, &volOptions.SubVolume, volOptions.ClusterID)
vol := core.NewSubVolume(volOptions.conn, &volOptions.SubVolume, volOptions.ClusterID, clusterName)
if (sID != nil || pvID != nil) && imageData.ImageAttributes.BackingSnapshotID == "" {
cloneState, cloneStateErr := vol.GetCloneState(ctx)
if cloneStateErr != nil {

View File

@ -196,7 +196,7 @@ func fmtBackingSnapshotOptionMismatch(optName, expected, actual string) error {
// NewVolumeOptions generates a new instance of volumeOptions from the provided
// CSI request parameters.
func NewVolumeOptions(ctx context.Context, requestName string, req *csi.CreateVolumeRequest,
func NewVolumeOptions(ctx context.Context, requestName, clusterName string, req *csi.CreateVolumeRequest,
cr *util.Credentials,
) (*VolumeOptions, error) {
var (
@ -289,7 +289,7 @@ func NewVolumeOptions(ctx context.Context, requestName string, req *csi.CreateVo
opts.BackingSnapshotID = req.GetVolumeContentSource().GetSnapshot().GetSnapshotId()
err = opts.populateVolumeOptionsFromBackingSnapshot(ctx, cr)
err = opts.populateVolumeOptionsFromBackingSnapshot(ctx, cr, clusterName)
if err != nil {
return nil, err
}
@ -304,6 +304,7 @@ func NewVolumeOptionsFromVolID(
ctx context.Context,
volID string,
volOpt, secrets map[string]string,
clusterName string,
) (*VolumeOptions, *VolumeIdentifier, error) {
var (
vi util.CSIIdentifier
@ -407,16 +408,16 @@ func NewVolumeOptionsFromVolID(
volOptions.SubVolume.VolID = vid.FsSubvolName
if volOptions.BackingSnapshot {
err = volOptions.populateVolumeOptionsFromBackingSnapshot(ctx, cr)
err = volOptions.populateVolumeOptionsFromBackingSnapshot(ctx, cr, clusterName)
} else {
err = volOptions.populateVolumeOptionsFromSubvolume(ctx)
err = volOptions.populateVolumeOptionsFromSubvolume(ctx, clusterName)
}
return &volOptions, &vid, err
}
func (vo *VolumeOptions) populateVolumeOptionsFromSubvolume(ctx context.Context) error {
vol := core.NewSubVolume(vo.conn, &vo.SubVolume, vo.ClusterID)
func (vo *VolumeOptions) populateVolumeOptionsFromSubvolume(ctx context.Context, clusterName string) error {
vol := core.NewSubVolume(vo.conn, &vo.SubVolume, vo.ClusterID, clusterName)
var info *core.Subvolume
info, err := vol.GetSubVolumeInfo(ctx)
@ -436,6 +437,7 @@ func (vo *VolumeOptions) populateVolumeOptionsFromSubvolume(ctx context.Context)
func (vo *VolumeOptions) populateVolumeOptionsFromBackingSnapshot(
ctx context.Context,
cr *util.Credentials,
clusterName string,
) error {
// As of CephFS snapshot v2 API, snapshots may be found in two locations:
//
@ -457,7 +459,7 @@ func (vo *VolumeOptions) populateVolumeOptionsFromBackingSnapshot(
return nil
}
parentBackingSnapVolOpts, _, snapID, err := NewSnapshotOptionsFromID(ctx, vo.BackingSnapshotID, cr)
parentBackingSnapVolOpts, _, snapID, err := NewSnapshotOptionsFromID(ctx, vo.BackingSnapshotID, cr, clusterName)
if err != nil {
return fmt.Errorf("failed to retrieve backing snapshot %s: %w", vo.BackingSnapshotID, err)
}
@ -652,6 +654,7 @@ func NewSnapshotOptionsFromID(
ctx context.Context,
snapID string,
cr *util.Credentials,
clusterName string,
) (*VolumeOptions, *core.SnapshotInfo, *SnapshotIdentifier, error) {
var (
vi util.CSIIdentifier
@ -723,7 +726,7 @@ func NewSnapshotOptionsFromID(
sid.FsSubvolName = imageAttributes.SourceName
volOptions.SubVolume.VolID = sid.FsSubvolName
vol := core.NewSubVolume(volOptions.conn, &volOptions.SubVolume, volOptions.ClusterID)
vol := core.NewSubVolume(volOptions.conn, &volOptions.SubVolume, volOptions.ClusterID, clusterName)
subvolInfo, err := vol.GetSubVolumeInfo(ctx)
if err != nil {