Skip to content

Commit

Permalink
Merge pull request #16 from xing-yang/v1_datasource
Browse files Browse the repository at this point in the history
Switch to use TypedLocalObjectReference in core API
  • Loading branch information
k8s-ci-robot authored Oct 17, 2018
2 parents d50a9a9 + c422fbd commit e36d31f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 45 deletions.
11 changes: 1 addition & 10 deletions pkg/apis/volumesnapshot/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type VolumeSnapshotSpec struct {
// In Alpha version, only PersistentVolumeClaim is supported as the source.
// If not specified, user can create VolumeSnapshotContent and bind it with VolumeSnapshot manually.
// +optional
Source *TypedLocalObjectReference `json:"source" protobuf:"bytes,1,opt,name=source"`
Source *core_v1.TypedLocalObjectReference `json:"source" protobuf:"bytes,1,opt,name=source"`

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

// TypedLocalObjectReference contains enough information to let you locate the typed referenced object inside the same namespace.
// TODO: After TypedLocalObjectReference is merged into the in-tree core API, this will be replaced.
type TypedLocalObjectReference struct {
// Name of the referent.
Name string `json:"name,omitempty" protobuf:"bytes,1,opt,name=name"`
// Kind of the referent.
Kind string `json:"kind,omitempty" protobuf:"bytes,2,opt,name=kind"`
}

// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
20 changes: 2 additions & 18 deletions pkg/apis/volumesnapshot/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions pkg/client/clientset/versioned/fake/register.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions pkg/client/clientset/versioned/scheme/register.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/controller/framework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down
11 changes: 9 additions & 2 deletions pkg/controller/snapshot_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e36d31f

Please sign in to comment.