Skip to content
Permalink
Browse files

Update snapshot CRD to v1beta

  • Loading branch information
xing-yang committed Aug 30, 2019
1 parent 4160887 commit 65ce20f81bef6002cf21143be07fbf28a0abd338
Showing with 7,295 additions and 786 deletions.
  1. +1 −1 cmd/csi-provisioner/csi-provisioner.go
  2. +1 −1 go.mod
  3. +4 −0 go.sum
  4. +13 −18 pkg/controller/controller.go
  5. +24 −28 pkg/controller/controller_test.go
  6. +0 −201 vendor/github.com/kubernetes-csi/external-snapshotter/LICENSE
  7. +0 −256 vendor/github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1alpha1/types.go
  8. +2 −1 ...ithub.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/{v1alpha1 → v1beta1}/doc.go
  9. +2 −2 ....com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/{v1alpha1 → v1beta1}/register.go
  10. +377 −0 vendor/github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1beta1/types.go
  11. +126 −77 ...es-csi/external-snapshotter/pkg/apis/volumesnapshot/{v1alpha1 → v1beta1}/zz_generated.deepcopy.go
  12. +10 −18 vendor/github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned/clientset.go
  13. +1 −1 vendor/github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned/doc.go
  14. +6 −11 ...om/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned/fake/clientset_generated.go
  15. +1 −1 vendor/github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned/fake/doc.go
  16. +3 −3 ...or/github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned/fake/register.go
  17. +1 −1 vendor/github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned/scheme/doc.go
  18. +3 −3 .../github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned/scheme/register.go
  19. +2 −2 ...ernal-snapshotter/pkg/client/clientset/versioned/typed/volumesnapshot/{v1alpha1 → v1beta1}/doc.go
  20. +1 −1 ...-snapshotter/pkg/client/clientset/versioned/typed/volumesnapshot/{v1alpha1 → v1beta1}/fake/doc.go
  21. +26 −26 .../client/clientset/versioned/typed/volumesnapshot/{v1alpha1 → v1beta1}/fake/fake_volumesnapshot.go
  22. +7 −7 .../clientset/versioned/typed/volumesnapshot/{v1alpha1 → v1beta1}/fake/fake_volumesnapshot_client.go
  23. +23 −23 ...nt/clientset/versioned/typed/volumesnapshot/{v1alpha1 → v1beta1}/fake/fake_volumesnapshotclass.go
  24. +34 −23 .../clientset/versioned/typed/volumesnapshot/{v1alpha1 → v1beta1}/fake/fake_volumesnapshotcontent.go
  25. +2 −2 ...r/pkg/client/clientset/versioned/typed/volumesnapshot/{v1alpha1 → v1beta1}/generated_expansion.go
  26. +22 −22 ...hotter/pkg/client/clientset/versioned/typed/volumesnapshot/{v1alpha1 → v1beta1}/volumesnapshot.go
  27. +19 −19 ...pkg/client/clientset/versioned/typed/volumesnapshot/{v1alpha1 → v1beta1}/volumesnapshot_client.go
  28. +19 −19 ...r/pkg/client/clientset/versioned/typed/volumesnapshot/{v1alpha1 → v1beta1}/volumesnapshotclass.go
  29. +35 −19 ...pkg/client/clientset/versioned/typed/volumesnapshot/{v1alpha1 → v1beta1}/volumesnapshotcontent.go
  30. +180 −0 ...r/github.com/kubernetes-csi/external-snapshotter/pkg/client/informers/externalversions/factory.go
  31. +66 −0 ...r/github.com/kubernetes-csi/external-snapshotter/pkg/client/informers/externalversions/generic.go
  32. +40 −0 ...ternal-snapshotter/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go
  33. +46 −0 ...rnetes-csi/external-snapshotter/pkg/client/informers/externalversions/volumesnapshot/interface.go
  34. +59 −0 ...si/external-snapshotter/pkg/client/informers/externalversions/volumesnapshot/v1beta1/interface.go
  35. +89 −0 ...ternal-snapshotter/pkg/client/informers/externalversions/volumesnapshot/v1beta1/volumesnapshot.go
  36. +88 −0 ...l-snapshotter/pkg/client/informers/externalversions/volumesnapshot/v1beta1/volumesnapshotclass.go
  37. +88 −0 ...snapshotter/pkg/client/informers/externalversions/volumesnapshot/v1beta1/volumesnapshotcontent.go
  38. +35 −0 ...ernetes-csi/external-snapshotter/pkg/client/listers/volumesnapshot/v1beta1/expansion_generated.go
  39. +94 −0 ...m/kubernetes-csi/external-snapshotter/pkg/client/listers/volumesnapshot/v1beta1/volumesnapshot.go
  40. +65 −0 ...ernetes-csi/external-snapshotter/pkg/client/listers/volumesnapshot/v1beta1/volumesnapshotclass.go
  41. +65 −0 ...netes-csi/external-snapshotter/pkg/client/listers/volumesnapshot/v1beta1/volumesnapshotcontent.go
  42. +112 −0 vendor/github.com/kubernetes-csi/external-snapshotter/pkg/controller/csi_handler.go
  43. +1,455 −0 vendor/github.com/kubernetes-csi/external-snapshotter/pkg/controller/framework_test.go
  44. +1,226 −0 vendor/github.com/kubernetes-csi/external-snapshotter/pkg/controller/snapshot_controller.go
  45. +477 −0 vendor/github.com/kubernetes-csi/external-snapshotter/pkg/controller/snapshot_controller_base.go
  46. +93 −0 vendor/github.com/kubernetes-csi/external-snapshotter/pkg/controller/snapshot_controller_test.go
  47. +336 −0 vendor/github.com/kubernetes-csi/external-snapshotter/pkg/controller/snapshot_create_test.go
  48. +320 −0 vendor/github.com/kubernetes-csi/external-snapshotter/pkg/controller/snapshot_delete_test.go
  49. +67 −0 vendor/github.com/kubernetes-csi/external-snapshotter/pkg/controller/snapshot_finalizer_test.go
  50. +267 −0 vendor/github.com/kubernetes-csi/external-snapshotter/pkg/controller/snapshot_ready_test.go
  51. +381 −0 vendor/github.com/kubernetes-csi/external-snapshotter/pkg/controller/util.go
  52. +196 −0 vendor/github.com/kubernetes-csi/external-snapshotter/pkg/controller/util_test.go
  53. +148 −0 vendor/github.com/kubernetes-csi/external-snapshotter/pkg/snapshotter/snapshotter.go
  54. +537 −0 vendor/github.com/kubernetes-csi/external-snapshotter/pkg/snapshotter/snapshotter_test.go
@@ -121,7 +121,7 @@ func main() {
if err != nil {
klog.Fatalf("Failed to create client: %v", err)
}
// snapclientset.NewForConfig creates a new Clientset for VolumesnapshotV1alpha1Client
// snapclientset.NewForConfig creates a new Clientset for VolumesnapshotV1beta1Client
snapClient, err := snapclientset.NewForConfig(config)
if err != nil {
klog.Fatalf("Failed to create snapshot client: %v", err)
2 go.mod
@@ -11,7 +11,7 @@ require (
github.com/imdario/mergo v0.3.7 // indirect
github.com/kubernetes-csi/csi-lib-utils v0.6.1
github.com/kubernetes-csi/csi-test v2.0.0+incompatible
github.com/kubernetes-csi/external-snapshotter v0.0.0-20190401205233-54a21f108e31
github.com/kubernetes-csi/external-snapshotter v2.0.0-rc1.0.20191024235139-bc6e42db5bc6+incompatible
github.com/miekg/dns v1.1.8 // indirect
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 // indirect
github.com/prometheus/common v0.2.0 // indirect
4 go.sum
@@ -93,6 +93,10 @@ github.com/kubernetes-csi/csi-test v2.0.0+incompatible h1:ia04uVFUM/J9n/v3LEMn3r
github.com/kubernetes-csi/csi-test v2.0.0+incompatible/go.mod h1:YxJ4UiuPWIhMBkxUKY5c267DyA0uDZ/MtAimhx/2TA0=
github.com/kubernetes-csi/external-snapshotter v0.0.0-20190401205233-54a21f108e31 h1:k5JUmEU48jVYjA2G6G0Vm09vK7QGm24KQm9XTWAF+KE=
github.com/kubernetes-csi/external-snapshotter v0.0.0-20190401205233-54a21f108e31/go.mod h1:oYfxnsuh48V1UDYORl77YQxQbbdokNy7D73phuFpksY=
github.com/kubernetes-csi/external-snapshotter v1.2.2 h1:OPXoJydNqkWjhLwJ20dSqOhkmUYcpm+CCO0pYm+C8Q8=
github.com/kubernetes-csi/external-snapshotter v1.2.2/go.mod h1:oYfxnsuh48V1UDYORl77YQxQbbdokNy7D73phuFpksY=
github.com/kubernetes-csi/external-snapshotter v2.0.0-rc1.0.20191024235139-bc6e42db5bc6+incompatible h1:luZoAqNkFePdBVZlKNL3+GPRN9djXt8sxhDJjumGlD8=
github.com/kubernetes-csi/external-snapshotter v2.0.0-rc1.0.20191024235139-bc6e42db5bc6+incompatible/go.mod h1:oYfxnsuh48V1UDYORl77YQxQbbdokNy7D73phuFpksY=
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
@@ -30,7 +30,7 @@ import (

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/kubernetes-csi/csi-lib-utils/connection"
snapapi "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1alpha1"
snapapi "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1beta1"
snapclientset "github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned"
"sigs.k8s.io/sig-storage-lib-external-provisioner/controller"
"sigs.k8s.io/sig-storage-lib-external-provisioner/util"
@@ -795,11 +795,11 @@ func (p *csiProvisioner) getPVCSource(options controller.ProvisionOptions) (*csi
// getSnapshotSource verifies DataSource.Kind of type VolumeSnapshot, making sure that the requested Snapshot is available/ready
// returns the VolumeContentSource for the requested snapshot
func (p *csiProvisioner) getSnapshotSource(options controller.ProvisionOptions) (*csi.VolumeContentSource, error) {
snapshotObj, err := p.snapshotClient.VolumesnapshotV1alpha1().VolumeSnapshots(options.PVC.Namespace).Get(options.PVC.Spec.DataSource.Name, metav1.GetOptions{})
snapshotObj, err := p.snapshotClient.SnapshotV1beta1().VolumeSnapshots(options.PVC.Namespace).Get(options.PVC.Spec.DataSource.Name, metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("error getting snapshot %s from api server: %v", options.PVC.Spec.DataSource.Name, err)
}
if snapshotObj.Status.ReadyToUse == false {
if snapshotObj.Status.ReadyToUse == nil || *snapshotObj.Status.ReadyToUse == false {
return nil, fmt.Errorf("snapshot %s is not Ready", options.PVC.Spec.DataSource.Name)
}

@@ -808,36 +808,31 @@ func (p *csiProvisioner) getSnapshotSource(options controller.ProvisionOptions)
}
klog.V(5).Infof("VolumeSnapshot %+v", snapshotObj)

snapContentObj, err := p.snapshotClient.VolumesnapshotV1alpha1().VolumeSnapshotContents().Get(snapshotObj.Spec.SnapshotContentName, metav1.GetOptions{})
if err != nil {
klog.Warningf("error getting snapshotcontent %s for snapshot %s/%s from api server: %s", snapshotObj.Spec.SnapshotContentName, snapshotObj.Namespace, snapshotObj.Name, err)
return nil, fmt.Errorf("snapshot in dataSource not bound or invalid")
if snapshotObj.Status.BoundVolumeSnapshotContentName == nil {
return nil, fmt.Errorf("snapshot %s does not have a content", options.PVC.Spec.DataSource.Name)
}

if snapContentObj.Spec.VolumeSnapshotRef == nil {
klog.Warningf("snapshotcontent %s for snapshot %s/%s is not bound", snapshotObj.Spec.SnapshotContentName, snapshotObj.Namespace, snapshotObj.Name)
return nil, fmt.Errorf("snapshot in dataSource not bound or invalid")
}
snapContentObj, err := p.snapshotClient.SnapshotV1beta1().VolumeSnapshotContents().Get(*snapshotObj.Status.BoundVolumeSnapshotContentName, metav1.GetOptions{})

if snapContentObj.Spec.VolumeSnapshotRef.UID != snapshotObj.UID || snapContentObj.Spec.VolumeSnapshotRef.Namespace != snapshotObj.Namespace || snapContentObj.Spec.VolumeSnapshotRef.Name != snapshotObj.Name {
klog.Warningf("snapshotcontent %s for snapshot %s/%s is bound to a different snapshot", snapshotObj.Spec.SnapshotContentName, snapshotObj.Namespace, snapshotObj.Name)
if err != nil {
klog.Warningf("error getting snapshotcontent %s for snapshot %s/%s from api server: %s", *snapshotObj.Status.BoundVolumeSnapshotContentName, snapshotObj.Namespace, snapshotObj.Name, err)
return nil, fmt.Errorf("snapshot in dataSource not bound or invalid")
}

if snapContentObj.Spec.VolumeSnapshotSource.CSI == nil {
klog.Warningf("error getting snapshot source from snapshotcontent %s for snapshot %s/%s", snapshotObj.Spec.SnapshotContentName, snapshotObj.Namespace, snapshotObj.Name)
if snapContentObj.Spec.VolumeSnapshotRef.UID != snapshotObj.UID || snapContentObj.Spec.VolumeSnapshotRef.Namespace != snapshotObj.Namespace || snapContentObj.Spec.VolumeSnapshotRef.Name != snapshotObj.Name {
klog.Warningf("snapshotcontent %s for snapshot %s/%s is bound to a different snapshot", *snapshotObj.Status.BoundVolumeSnapshotContentName, snapshotObj.Namespace, snapshotObj.Name)
return nil, fmt.Errorf("snapshot in dataSource not bound or invalid")
}

if snapContentObj.Spec.VolumeSnapshotSource.CSI.Driver != options.StorageClass.Provisioner {
klog.Warningf("snapshotcontent %s for snapshot %s/%s is handled by a different CSI driver than requested by StorageClass %s", snapshotObj.Spec.SnapshotContentName, snapshotObj.Namespace, snapshotObj.Name, options.StorageClass.Name)
if snapContentObj.Spec.Driver != options.StorageClass.Provisioner {
klog.Warningf("snapshotcontent %s for snapshot %s/%s is handled by a different CSI driver than requested by StorageClass %s", *snapshotObj.Status.BoundVolumeSnapshotContentName, snapshotObj.Namespace, snapshotObj.Name, options.StorageClass.Name)
return nil, fmt.Errorf("snapshot in dataSource not bound or invalid")
}

klog.V(5).Infof("VolumeSnapshotContent %+v", snapContentObj)
snapshotSource := csi.VolumeContentSource_Snapshot{
Snapshot: &csi.VolumeContentSource_SnapshotSource{
SnapshotId: snapContentObj.Spec.VolumeSnapshotSource.CSI.SnapshotHandle,
SnapshotId: *snapContentObj.Status.SnapshotHandle,
},
}
klog.V(5).Infof("VolumeContentSource_Snapshot %+v", snapshotSource)
@@ -36,12 +36,11 @@ import (
"github.com/kubernetes-csi/csi-lib-utils/connection"
"github.com/kubernetes-csi/csi-test/driver"
"github.com/kubernetes-csi/external-provisioner/pkg/features"
crdv1 "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1alpha1"
crdv1 "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1beta1"
"github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned/fake"
"google.golang.org/grpc"
"k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
storagev1beta1 "k8s.io/api/storage/v1beta1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
@@ -1394,28 +1393,27 @@ func TestProvision(t *testing.T) {
}

// newSnapshot returns a new snapshot object
func newSnapshot(name, className, boundToContent, snapshotUID, claimName string, ready bool, err *storagev1beta1.VolumeError, creationTime *metav1.Time, size *resource.Quantity) *crdv1.VolumeSnapshot {
func newSnapshot(name, className, boundToContent, snapshotUID, claimName string, ready bool, err *crdv1.VolumeSnapshotError, creationTime *metav1.Time, size *resource.Quantity) *crdv1.VolumeSnapshot {
snapshot := crdv1.VolumeSnapshot{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: "default",
UID: types.UID(snapshotUID),
ResourceVersion: "1",
SelfLink: "/apis/snapshot.storage.k8s.io/v1alpha1/namespaces/" + "default" + "/volumesnapshots/" + name,
SelfLink: "/apis/snapshot.storage.k8s.io/v1beta1/namespaces/" + "default" + "/volumesnapshots/" + name,
},
Spec: crdv1.VolumeSnapshotSpec{
Source: &v1.TypedLocalObjectReference{
Name: claimName,
Kind: "PersistentVolumeClaim",
Source: crdv1.VolumeSnapshotSource{
PersistentVolumeClaimName: &claimName,
},
VolumeSnapshotClassName: &className,
SnapshotContentName: boundToContent,
},
Status: crdv1.VolumeSnapshotStatus{
CreationTime: creationTime,
ReadyToUse: ready,
Error: err,
RestoreSize: size,
BoundVolumeSnapshotContentName: &boundToContent,
CreationTime: creationTime,
ReadyToUse: &ready,
Error: err,
RestoreSize: size,
},
}

@@ -1560,37 +1558,35 @@ func runProvisionTest(t *testing.T, k string, tc provisioningTestcase, requested

// newContent returns a new content with given attributes
func newContent(name, className, snapshotHandle, volumeUID, volumeName, boundToSnapshotUID, boundToSnapshotName string, size *int64, creationTime *int64) *crdv1.VolumeSnapshotContent {
ready := true
content := crdv1.VolumeSnapshotContent{
ObjectMeta: metav1.ObjectMeta{
Name: name,
ResourceVersion: "1",
},
Spec: crdv1.VolumeSnapshotContentSpec{
VolumeSnapshotSource: crdv1.VolumeSnapshotSource{
CSI: &crdv1.CSIVolumeSnapshotSource{
RestoreSize: size,
Driver: "test-driver",
SnapshotHandle: snapshotHandle,
CreationTime: creationTime,
},
},
VolumeSnapshotClassName: &className,
PersistentVolumeRef: &v1.ObjectReference{
Kind: "PersistentVolume",
APIVersion: "v1",
UID: types.UID(volumeUID),
Name: volumeName,
Driver: "test-driver",
Source: crdv1.VolumeSnapshotContentSource{
SnapshotHandle: &snapshotHandle,
},
SnapshotClassName: &className,
},
}

if boundToSnapshotName != "" {
content.Spec.VolumeSnapshotRef = &v1.ObjectReference{
content.Spec.VolumeSnapshotRef = v1.ObjectReference{
Kind: "VolumeSnapshot",
APIVersion: "snapshot.storage.k8s.io/v1alpha1",
APIVersion: "snapshot.storage.k8s.io/v1beta1",
UID: types.UID(boundToSnapshotUID),
Namespace: "default",
Name: boundToSnapshotName,
}
content.Status = crdv1.VolumeSnapshotContentStatus{
RestoreSize: size,
SnapshotHandle: &snapshotHandle,
CreationTime: creationTime,
ReadyToUse: &ready,
}
}

return &content

0 comments on commit 65ce20f

Please sign in to comment.
You can’t perform that action at this time.