Skip to content

Commit e36d31f

Browse files
authored
Merge pull request #16 from xing-yang/v1_datasource
Switch to use TypedLocalObjectReference in core API
2 parents d50a9a9 + c422fbd commit e36d31f

File tree

6 files changed

+31
-45
lines changed

6 files changed

+31
-45
lines changed

pkg/apis/volumesnapshot/v1alpha1/types.go

+1-10
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ type VolumeSnapshotSpec struct {
7171
// In Alpha version, only PersistentVolumeClaim is supported as the source.
7272
// If not specified, user can create VolumeSnapshotContent and bind it with VolumeSnapshot manually.
7373
// +optional
74-
Source *TypedLocalObjectReference `json:"source" protobuf:"bytes,1,opt,name=source"`
74+
Source *core_v1.TypedLocalObjectReference `json:"source" protobuf:"bytes,1,opt,name=source"`
7575

7676
// SnapshotContentName binds the VolumeSnapshot object with the VolumeSnapshotContent
7777
// +optional
@@ -110,15 +110,6 @@ type VolumeSnapshotStatus struct {
110110
Error *storage.VolumeError `json:"error,omitempty" protobuf:"bytes,4,opt,name=error,casttype=VolumeError"`
111111
}
112112

113-
// TypedLocalObjectReference contains enough information to let you locate the typed referenced object inside the same namespace.
114-
// TODO: After TypedLocalObjectReference is merged into the in-tree core API, this will be replaced.
115-
type TypedLocalObjectReference struct {
116-
// Name of the referent.
117-
Name string `json:"name,omitempty" protobuf:"bytes,1,opt,name=name"`
118-
// Kind of the referent.
119-
Kind string `json:"kind,omitempty" protobuf:"bytes,2,opt,name=kind"`
120-
}
121-
122113
// +genclient
123114
// +genclient:nonNamespaced
124115
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

pkg/apis/volumesnapshot/v1alpha1/zz_generated.deepcopy.go

+2-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/client/clientset/versioned/fake/register.go

+9-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/client/clientset/versioned/scheme/register.go

+9-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controller/framework_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ func newSnapshot(name, className, boundToContent, snapshotUID, claimName string,
806806
SelfLink: "/apis/snapshot.storage.k8s.io/v1alpha1/namespaces/" + testNamespace + "/volumesnapshots/" + name,
807807
},
808808
Spec: crdv1.VolumeSnapshotSpec{
809-
Source: &crdv1.TypedLocalObjectReference{
809+
Source: &v1.TypedLocalObjectReference{
810810
Name: claimName,
811811
Kind: "PersistentVolumeClaim",
812812
},

pkg/controller/snapshot_controller.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import (
7777
// In the future version, a retry policy will be added.
7878

7979
const pvcKind = "PersistentVolumeClaim"
80+
const apiGroup = ""
8081
const controllerUpdateFailMsg = "snapshot controller failed to update"
8182

8283
const IsDefaultSnapshotClassAnnotation = "snapshot.storage.kubernetes.io/is-default-class"
@@ -824,13 +825,19 @@ func (ctrl *csiSnapshotController) SetDefaultSnapshotClass(snapshot *crdv1.Volum
824825

825826
// getClaimFromVolumeSnapshot is a helper function to get PVC from VolumeSnapshot.
826827
func (ctrl *csiSnapshotController) getClaimFromVolumeSnapshot(snapshot *crdv1.VolumeSnapshot) (*v1.PersistentVolumeClaim, error) {
827-
if snapshot.Spec.Source == nil || snapshot.Spec.Source.Kind != pvcKind {
828-
return nil, fmt.Errorf("The snapshot source is not the right type. Expected %s, Got %v", pvcKind, snapshot.Spec.Source)
828+
if snapshot.Spec.Source == nil {
829+
return nil, fmt.Errorf("the snapshot source is not specified.")
830+
}
831+
if snapshot.Spec.Source.Kind != pvcKind {
832+
return nil, fmt.Errorf("the snapshot source is not the right type. Expected %s, Got %v", pvcKind, snapshot.Spec.Source.Kind)
829833
}
830834
pvcName := snapshot.Spec.Source.Name
831835
if pvcName == "" {
832836
return nil, fmt.Errorf("the PVC name is not specified in snapshot %s", snapshotKey(snapshot))
833837
}
838+
if snapshot.Spec.Source.APIGroup != nil && *(snapshot.Spec.Source.APIGroup) != apiGroup {
839+
return nil, fmt.Errorf("the snapshot source does not have the right APIGroup. Expected empty string, Got %s", *(snapshot.Spec.Source.APIGroup))
840+
}
834841

835842
pvc, err := ctrl.client.CoreV1().PersistentVolumeClaims(snapshot.Namespace).Get(pvcName, metav1.GetOptions{})
836843
if err != nil {

0 commit comments

Comments
 (0)