Skip to content

Commit

Permalink
Add VolumeSnapshotClass selection logs
Browse files Browse the repository at this point in the history
Signed-off-by: Arnon Gilboa <agilboa@redhat.com>
  • Loading branch information
arnongilboa committed Sep 19, 2023
1 parent ea331f8 commit 312a0b8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/clone/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func getCommonSnapshotClass(ctx context.Context, c client.Client, pvcs ...*corev
}

// GetCompatibleVolumeSnapshotClass returns a VolumeSnapshotClass name that works for all PVCs
func GetCompatibleVolumeSnapshotClass(ctx context.Context, c client.Client, pvcs ...*corev1.PersistentVolumeClaim) (*string, error) {
func GetCompatibleVolumeSnapshotClass(ctx context.Context, c client.Client, log logr.Logger, pvcs ...*corev1.PersistentVolumeClaim) (*string, error) {
driver, err := GetCommonDriver(ctx, c, pvcs...)
if err != nil {
return nil, err
Expand All @@ -261,7 +261,7 @@ func GetCompatibleVolumeSnapshotClass(ctx context.Context, c client.Client, pvcs
return nil, err
}

return cc.GetVolumeSnapshotClass(context.TODO(), c, *driver, snapshotClassName)
return cc.GetVolumeSnapshotClass(context.TODO(), c, *driver, snapshotClassName, log)
}

// SameVolumeMode returns true if all pvcs have the same volume mode
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/clone/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func (p *Planner) computeStrategyForSourcePVC(ctx context.Context, args *ChooseS
}

if strategy == cdiv1.CloneStrategySnapshot {
n, err := GetCompatibleVolumeSnapshotClass(ctx, p.Client, sourceClaim, args.TargetClaim)
n, err := GetCompatibleVolumeSnapshotClass(ctx, p.Client, args.Log, sourceClaim, args.TargetClaim)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -660,7 +660,7 @@ func (p *Planner) planSnapshotFromPVC(ctx context.Context, args *PlanArgs) ([]Ph
return nil, fmt.Errorf("source claim does not exist")
}

vsc, err := GetCompatibleVolumeSnapshotClass(ctx, p.Client, sourceClaim, args.TargetClaim)
vsc, err := GetCompatibleVolumeSnapshotClass(ctx, p.Client, args.Log, args.TargetClaim)
if err != nil {
return nil, err
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/controller/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,7 @@ func GetSnapshotClassForSmartClone(dvName string, targetPvcStorageClassName, sna
return "", nil
}

vscName, err := GetVolumeSnapshotClass(context.TODO(), client, targetStorageClass.Provisioner, snapshotClassName)
vscName, err := GetVolumeSnapshotClass(context.TODO(), client, targetStorageClass.Provisioner, snapshotClassName, logger)
if err != nil {
return "", err
}
Expand All @@ -1838,13 +1838,15 @@ func GetSnapshotClassForSmartClone(dvName string, targetPvcStorageClassName, sna
}

// GetVolumeSnapshotClass looks up the snapshot class based on the driver and an optional specific name
func GetVolumeSnapshotClass(ctx context.Context, c client.Client, driver string, snapshotClassName *string) (*string, error) {
func GetVolumeSnapshotClass(ctx context.Context, c client.Client, driver string, snapshotClassName *string, log logr.Logger) (*string, error) {
logger := log.WithName("GetVolumeSnapshotClass").V(3)
if snapshotClassName != nil {
vsc := &snapshotv1.VolumeSnapshotClass{}
if err := c.Get(context.TODO(), types.NamespacedName{Name: *snapshotClassName}, vsc); err != nil {
return nil, err
}
if vsc.Driver == driver {
logger.Info("VolumeSnapshotClass selected according to StorageProfile", "name", vsc.Name)
return &vsc.Name, nil
}
return nil, nil
Expand All @@ -1862,6 +1864,7 @@ func GetVolumeSnapshotClass(ctx context.Context, c client.Client, driver string,
for _, vsc := range vscList.Items {
if vsc.Driver == driver {
if vsc.Annotations[AnnDefaultSnapshotClass] == "true" {
logger.Info("Default VolumeSnapshotClass selected", "name", vsc.Name)
return &vsc.Name, nil
}
candidates = append(candidates, vsc.Name)
Expand All @@ -1870,6 +1873,7 @@ func GetVolumeSnapshotClass(ctx context.Context, c client.Client, driver string,

if len(candidates) > 0 {
sort.Strings(candidates)
logger.Info("First VolumeSnapshotClass selected", "name", candidates[0], "candidates", len(candidates))
return &candidates[0], nil
}

Expand Down

0 comments on commit 312a0b8

Please sign in to comment.