Skip to content

Commit

Permalink
Merge pull request kubernetes-csi#335 from xing-yang/snapshot_beta
Browse files Browse the repository at this point in the history
Update snapshot CRD to v1beta
  • Loading branch information
k8s-ci-robot authored Oct 30, 2019
2 parents 16a2da3 + a77d006 commit f807aff
Show file tree
Hide file tree
Showing 29 changed files with 971 additions and 605 deletions.
2 changes: 1 addition & 1 deletion cmd/csi-provisioner/csi-provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ github.com/kubernetes-csi/csi-lib-utils v0.6.1 h1:+AZ58SRSRWh2vmMoWAAGcv7x6fIyBM
github.com/kubernetes-csi/csi-lib-utils v0.6.1/go.mod h1:GVmlUmxZ+SUjVLXicRFjqWUUvWez0g0Y78zNV9t7KfQ=
github.com/kubernetes-csi/csi-test v2.0.0+incompatible h1:ia04uVFUM/J9n/v3LEMn3rEG6FmKV5BH9QLw7H68h44=
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 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=
Expand Down
45 changes: 24 additions & 21 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -120,6 +120,8 @@ const (
deleteVolumeRetryCount = 5

annStorageProvisioner = "volume.beta.kubernetes.io/storage-provisioner"

snapshotNotBound = "snapshot %s not bound"
)

var (
Expand Down Expand Up @@ -800,49 +802,50 @@ 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 {
return nil, fmt.Errorf("snapshot %s is not Ready", options.PVC.Spec.DataSource.Name)
}

if snapshotObj.ObjectMeta.DeletionTimestamp != nil {
return nil, fmt.Errorf("snapshot %s is currently being deleted", options.PVC.Spec.DataSource.Name)
}
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 == nil || snapshotObj.Status.BoundVolumeSnapshotContentName == nil {
return nil, fmt.Errorf(snapshotNotBound, 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 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(snapshotNotBound, options.PVC.Spec.DataSource.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.Spec.SnapshotContentName, snapshotObj.Namespace, snapshotObj.Name)
return nil, fmt.Errorf("snapshot in dataSource not bound or invalid")
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(snapshotNotBound, options.PVC.Spec.DataSource.Name)
}

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)
return nil, fmt.Errorf("snapshot in dataSource not bound or invalid")
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(snapshotNotBound, options.PVC.Spec.DataSource.Name)
}

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)
return nil, fmt.Errorf("snapshot in dataSource not bound or invalid")
if snapshotObj.Status.ReadyToUse == nil || *snapshotObj.Status.ReadyToUse == false {
return nil, fmt.Errorf("snapshot %s is not Ready", options.PVC.Spec.DataSource.Name)
}

klog.V(5).Infof("VolumeSnapshotContent %+v", snapContentObj)

if snapContentObj.Status == nil || snapContentObj.Status.SnapshotHandle == nil {
return nil, fmt.Errorf("snapshot handle %s is not available", options.PVC.Spec.DataSource.Name)
}

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)
Expand Down
Loading

0 comments on commit f807aff

Please sign in to comment.