Skip to content

Commit

Permalink
Update Snapshot Controller
Browse files Browse the repository at this point in the history
This PR updates snapshot controller after CRD changes.
  • Loading branch information
xing-yang committed Jul 22, 2018
1 parent 630f7b9 commit e3c46ae
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 237 deletions.
16 changes: 8 additions & 8 deletions cmd/csi-snapshotter/create_crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ func NewClient(cfg *rest.Config) (*rest.RESTClient, *runtime.Scheme, error) {
func CreateCRD(clientset apiextensionsclient.Interface) error {
crd := &apiextensionsv1beta1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: crdv1.SnapshotClassResourcePlural + "." + crdv1.GroupName,
Name: crdv1.VolumeSnapshotClassResourcePlural + "." + crdv1.GroupName,
},
Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{
Group: crdv1.GroupName,
Version: crdv1.SchemeGroupVersion.Version,
Scope: apiextensionsv1beta1.ClusterScoped,
Names: apiextensionsv1beta1.CustomResourceDefinitionNames{
Plural: crdv1.SnapshotClassResourcePlural,
Kind: reflect.TypeOf(crdv1.SnapshotClass{}).Name(),
Plural: crdv1.VolumeSnapshotClassResourcePlural,
Kind: reflect.TypeOf(crdv1.VolumeSnapshotClass{}).Name(),
},
},
}
Expand All @@ -80,22 +80,22 @@ func CreateCRD(clientset apiextensionsclient.Interface) error {

crd = &apiextensionsv1beta1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: crdv1.VolumeSnapshotDataResourcePlural + "." + crdv1.GroupName,
Name: crdv1.VolumeSnapshotContentResourcePlural + "." + crdv1.GroupName,
},
Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{
Group: crdv1.GroupName,
Version: crdv1.SchemeGroupVersion.Version,
Scope: apiextensionsv1beta1.ClusterScoped,
Names: apiextensionsv1beta1.CustomResourceDefinitionNames{
Plural: crdv1.VolumeSnapshotDataResourcePlural,
Kind: reflect.TypeOf(crdv1.VolumeSnapshotData{}).Name(),
Plural: crdv1.VolumeSnapshotContentResourcePlural,
Kind: reflect.TypeOf(crdv1.VolumeSnapshotContent{}).Name(),
},
},
}
res, err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd)

if err != nil && !apierrors.IsAlreadyExists(err) {
glog.Fatalf("failed to create VolumeSnapshotDataResource: %#v, err: %#v",
glog.Fatalf("failed to create VolumeSnapshotContentResource: %#v, err: %#v",
res, err)
}

Expand Down Expand Up @@ -127,7 +127,7 @@ func CreateCRD(clientset apiextensionsclient.Interface) error {
func WaitForSnapshotResource(snapshotClient *rest.RESTClient) error {
return wait.Poll(100*time.Millisecond, 60*time.Second, func() (bool, error) {
_, err := snapshotClient.Get().
Resource(crdv1.VolumeSnapshotDataResourcePlural).DoRaw()
Resource(crdv1.VolumeSnapshotContentResourcePlural).DoRaw()
if err == nil {
return true, nil
}
Expand Down
22 changes: 11 additions & 11 deletions cmd/csi-snapshotter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ const (

// Command line flags
var (
snapshotter = flag.String("snapshotter", "", "Name of the snapshotter. The snapshotter will only create snapshot data for snapshot that request a StorageClass with a snapshotter field set equal to this name.")
kubeconfig = flag.String("kubeconfig", "", "Absolute path to the kubeconfig file. Required only when running out of cluster.")
resync = flag.Duration("resync", 10*time.Second, "Resync interval of the controller.")
connectionTimeout = flag.Duration("connection-timeout", 1*time.Minute, "Timeout for waiting for CSI driver socket.")
csiAddress = flag.String("csi-address", "/run/csi/socket", "Address of the CSI driver socket.")
createSnapshotDataRetryCount = flag.Int("createSnapshotDataRetryCount", 5, "Number of retries when we create a snapshot data object for a snapshot.")
createSnapshotDataInterval = flag.Duration("createSnapshotDataInterval", 10*time.Second, "Interval between retries when we create a snapshot data object for a snapshot.")
resyncPeriod = flag.Duration("resyncPeriod", 60*time.Second, "The period that should be used to re-sync the snapshot.")
snapshotter = flag.String("snapshotter", "", "Name of the snapshotter. The snapshotter will only create snapshot data for snapshot that request a StorageClass with a snapshotter field set equal to this name.")
kubeconfig = flag.String("kubeconfig", "", "Absolute path to the kubeconfig file. Required only when running out of cluster.")
resync = flag.Duration("resync", 10*time.Second, "Resync interval of the controller.")
connectionTimeout = flag.Duration("connection-timeout", 1*time.Minute, "Timeout for waiting for CSI driver socket.")
csiAddress = flag.String("csi-address", "/run/csi/socket", "Address of the CSI driver socket.")
createSnapshotContentRetryCount = flag.Int("createSnapshotContentRetryCount", 5, "Number of retries when we create a snapshot data object for a snapshot.")
createSnapshotContentInterval = flag.Duration("createSnapshotContentInterval", 10*time.Second, "Interval between retries when we create a snapshot data object for a snapshot.")
resyncPeriod = flag.Duration("resyncPeriod", 60*time.Second, "The period that should be used to re-sync the snapshot.")
)

func main() {
Expand Down Expand Up @@ -145,9 +145,9 @@ func main() {
kubeClient,
*snapshotter,
factory.Volumesnapshot().V1alpha1().VolumeSnapshots(),
factory.Volumesnapshot().V1alpha1().VolumeSnapshotDatas(),
*createSnapshotDataRetryCount,
*createSnapshotDataInterval,
factory.Volumesnapshot().V1alpha1().VolumeSnapshotContents(),
*createSnapshotContentRetryCount,
*createSnapshotContentInterval,
csiConn,
*connectionTimeout,
*resyncPeriod,
Expand Down
10 changes: 5 additions & 5 deletions pkg/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type CSIConnection interface {
DeleteSnapshot(ctx context.Context, snapshotID string) (err error)

// ListSnapshots lists snapshot from a volume
ListSnapshots(ctx context.Context, snapshotID string) (*csi.SnapshotStatus, error)
ListSnapshots(ctx context.Context, snapshotID string) (*csi.SnapshotStatus, int64, error)

// Probe checks that the CSI driver is ready to process requests
Probe(ctx context.Context) error
Expand Down Expand Up @@ -233,7 +233,7 @@ func (c *csiConnection) DeleteSnapshot(ctx context.Context, snapshotID string) (
return nil
}

func (c *csiConnection) ListSnapshots(ctx context.Context, snapshotID string) (*csi.SnapshotStatus, error) {
func (c *csiConnection) ListSnapshots(ctx context.Context, snapshotID string) (*csi.SnapshotStatus, int64, error) {
client := csi.NewControllerClient(c.conn)

req := csi.ListSnapshotsRequest{
Expand All @@ -242,14 +242,14 @@ func (c *csiConnection) ListSnapshots(ctx context.Context, snapshotID string) (*

rsp, err := client.ListSnapshots(ctx, &req)
if err != nil {
return nil, err
return nil, 0, err
}

if rsp.Entries == nil || len(rsp.Entries) == 0 {
return nil, fmt.Errorf("can not find snapshot for snapshotID %s", snapshotID)
return nil, 0, fmt.Errorf("can not find snapshot for snapshotID %s", snapshotID)
}

return rsp.Entries[0].Snapshot.Status, nil
return rsp.Entries[0].Snapshot.Status, rsp.Entries[0].Snapshot.CreatedAt, nil
}

func (c *csiConnection) Close() error {
Expand Down
Loading

0 comments on commit e3c46ae

Please sign in to comment.