-
Notifications
You must be signed in to change notification settings - Fork 254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PVC Clone Populator #2709
PVC Clone Populator #2709
Changes from 1 commit
1bac742
fd84df9
3e1d894
188e448
a5ac4cb
aa2dd2f
855b8dc
55e56db
c7be492
eeb5ec9
ec33442
23935e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,6 +156,20 @@ func GetStorageClassForClaim(ctx context.Context, c client.Client, pvc *corev1.P | |
return nil, nil | ||
} | ||
|
||
// MustGetStorageClassForClaim returns the storageclass for a PVC | ||
func MustGetStorageClassForClaim(ctx context.Context, c client.Client, pvc *corev1.PersistentVolumeClaim) (*storagev1.StorageClass, error) { | ||
sc, err := GetStorageClassForClaim(ctx, c, pvc) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if sc == nil { | ||
return nil, fmt.Errorf("no storageclass for pvc") | ||
} | ||
|
||
return sc, nil | ||
} | ||
|
||
// GetCompatibleVolumeSnapshotClass returns a VolumeSNapshotClass name that works for all PVCs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor typo: Uppercase N in |
||
func GetCompatibleVolumeSnapshotClass(ctx context.Context, c client.Client, pvcs ...*corev1.PersistentVolumeClaim) (*string, error) { | ||
var storageClasses []*storagev1.StorageClass | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -188,7 +188,7 @@ func (p *Planner) watchOwned(log logr.Logger, obj client.Object) error { | |
} | ||
|
||
func (p *Planner) strategyForSourcePVC(ctx context.Context, args *ChooseStrategyArgs) (*cdiv1.CDICloneStrategy, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably just preference but I miss having the verb in several function names. For example, I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perhaps this is a bit pedantic, but I like the prefix get/set for simple operations. simply returning a value that is already set/stored somewhere for example. This is actually computing a value that is not stored anywhere. I will add 'compute' prefix |
||
if ok, err := p.validateTargetStorageClassAssignment(args); !ok || err != nil { | ||
if ok, err := p.validateTargetStorageClassAssignment(ctx, args); !ok || err != nil { | ||
return nil, err | ||
} | ||
|
||
|
@@ -239,7 +239,7 @@ func (p *Planner) strategyForSourcePVC(ctx context.Context, args *ChooseStrategy | |
} | ||
|
||
if !exists { | ||
args.Log.V(1).Info("missing storageprofile for", "name", *args.TargetClaim.Spec.StorageClassName) | ||
args.Log.V(3).Info("missing storageprofile for", "name", *args.TargetClaim.Spec.StorageClassName) | ||
} | ||
|
||
if exists && sp.Status.CloneStrategy != nil { | ||
|
@@ -273,7 +273,7 @@ func (p *Planner) strategyForSourcePVC(ctx context.Context, args *ChooseStrategy | |
return &strategy, nil | ||
} | ||
|
||
func (p *Planner) validateTargetStorageClassAssignment(args *ChooseStrategyArgs) (bool, error) { | ||
func (p *Planner) validateTargetStorageClassAssignment(ctx context.Context, args *ChooseStrategyArgs) (bool, error) { | ||
if args.TargetClaim.Spec.StorageClassName == nil { | ||
args.Log.V(3).Info("Target PVC has nil storage class, cannot compute strategy") | ||
return false, nil | ||
|
@@ -284,6 +284,11 @@ func (p *Planner) validateTargetStorageClassAssignment(args *ChooseStrategyArgs) | |
return false, fmt.Errorf("claim has emptystring storageclass, will not work") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why here you return error that the storageclass name is empty but return nil if the storage class is nil? shouldn't they both end with the same result? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, with k8s 1.26 a nil storageClassName can be updated when there is no default storageclass. So we should wait until a storageclass is assigned |
||
} | ||
|
||
_, err := MustGetStorageClassForClaim(ctx, p.Client, args.TargetClaim) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
return true, nil | ||
} | ||
|
||
|
@@ -305,15 +310,11 @@ func (p *Planner) validateAdvancedClonePVC(ctx context.Context, args *ChooseStra | |
return false, nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it make sense to emit an event here indicating why we switched to host assisted clone? In most cases we are not logging at V(3) and this piece of information gets lost. I would settle for a V(1) log honestly. |
||
} | ||
|
||
sc, err := GetStorageClassForClaim(ctx, p.Client, args.TargetClaim) | ||
sc, err := MustGetStorageClassForClaim(ctx, p.Client, args.TargetClaim) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
if sc == nil { | ||
return false, fmt.Errorf("target storageclass should exist") | ||
} | ||
|
||
srcCapacity, hasSrcCapacity := sourceClaim.Status.Capacity[corev1.ResourceStorage] | ||
targetRequest, hasTargetRequest := args.TargetClaim.Spec.Resources.Requests[corev1.ResourceStorage] | ||
allowExpansion := sc.AllowVolumeExpansion != nil && *sc.AllowVolumeExpansion | ||
|
@@ -344,13 +345,20 @@ func (p *Planner) planHostAssistedFromPVC(ctx context.Context, args *PlanArgs) ( | |
desiredClaim.Spec.Resources.Requests[corev1.ResourceStorage] = is | ||
} | ||
|
||
ct := cdiv1.DataVolumeKubeVirt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can use: cc.GetContentType(string(uploadSource.Spec.ContentType)) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is outdated code, contentType was removed |
||
if args.DataSource.Spec.ContentType != "" { | ||
ct = args.DataSource.Spec.ContentType | ||
} | ||
|
||
hcp := &HostClonePhase{ | ||
Owner: args.TargetClaim, | ||
Namespace: args.DataSource.Namespace, | ||
SourceName: args.DataSource.Spec.Source.Name, | ||
DesiredClaim: desiredClaim, | ||
ImmediateBind: true, | ||
OwnershipLabel: p.OwnershipLabel, | ||
ContentType: string(ct), | ||
Preallocation: cc.GetPreallocation(ctx, p.Client, args.DataSource.Spec.Preallocation), | ||
Client: p.Client, | ||
Log: args.Log, | ||
Recorder: p.Recorder, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this function name is a little bit awkward. I also think it doesn't make that much sense to have it since we still need to check its error return (we are only saving two checks in
planner.go
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fine