Switch to use TypedLocalObjectReference in core API
This commit is contained in:
@@ -806,7 +806,7 @@ func newSnapshot(name, className, boundToContent, snapshotUID, claimName string,
|
||||
SelfLink: "/apis/snapshot.storage.k8s.io/v1alpha1/namespaces/" + testNamespace + "/volumesnapshots/" + name,
|
||||
},
|
||||
Spec: crdv1.VolumeSnapshotSpec{
|
||||
Source: &crdv1.TypedLocalObjectReference{
|
||||
Source: &v1.TypedLocalObjectReference{
|
||||
Name: claimName,
|
||||
Kind: "PersistentVolumeClaim",
|
||||
},
|
||||
|
@@ -77,6 +77,7 @@ import (
|
||||
// In the future version, a retry policy will be added.
|
||||
|
||||
const pvcKind = "PersistentVolumeClaim"
|
||||
const apiGroup = ""
|
||||
const controllerUpdateFailMsg = "snapshot controller failed to update"
|
||||
|
||||
const IsDefaultSnapshotClassAnnotation = "snapshot.storage.kubernetes.io/is-default-class"
|
||||
@@ -824,13 +825,19 @@ func (ctrl *csiSnapshotController) SetDefaultSnapshotClass(snapshot *crdv1.Volum
|
||||
|
||||
// getClaimFromVolumeSnapshot is a helper function to get PVC from VolumeSnapshot.
|
||||
func (ctrl *csiSnapshotController) getClaimFromVolumeSnapshot(snapshot *crdv1.VolumeSnapshot) (*v1.PersistentVolumeClaim, error) {
|
||||
if snapshot.Spec.Source == nil || snapshot.Spec.Source.Kind != pvcKind {
|
||||
return nil, fmt.Errorf("The snapshot source is not the right type. Expected %s, Got %v", pvcKind, snapshot.Spec.Source)
|
||||
if snapshot.Spec.Source == nil {
|
||||
return nil, fmt.Errorf("the snapshot source is not specified.")
|
||||
}
|
||||
if snapshot.Spec.Source.Kind != pvcKind {
|
||||
return nil, fmt.Errorf("the snapshot source is not the right type. Expected %s, Got %v", pvcKind, snapshot.Spec.Source.Kind)
|
||||
}
|
||||
pvcName := snapshot.Spec.Source.Name
|
||||
if pvcName == "" {
|
||||
return nil, fmt.Errorf("the PVC name is not specified in snapshot %s", snapshotKey(snapshot))
|
||||
}
|
||||
if snapshot.Spec.Source.APIGroup != nil && *(snapshot.Spec.Source.APIGroup) != apiGroup {
|
||||
return nil, fmt.Errorf("the snapshot source does not have the right APIGroup. Expected empty string, Got %s", *(snapshot.Spec.Source.APIGroup))
|
||||
}
|
||||
|
||||
pvc, err := ctrl.client.CoreV1().PersistentVolumeClaims(snapshot.Namespace).Get(pvcName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user