Skip to content

Commit

Permalink
move snapshotter implementation to its own package pkg/snapshotter
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsykim committed Mar 25, 2019
1 parent a46a826 commit 2f11d41
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
17 changes: 9 additions & 8 deletions cmd/csi-snapshotter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/kubernetes-csi/csi-lib-utils/connection"
csirpc "github.com/kubernetes-csi/csi-lib-utils/rpc"
"github.com/kubernetes-csi/external-snapshotter/pkg/controller"
"github.com/kubernetes-csi/external-snapshotter/pkg/snapshotter"

clientset "github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned"
snapshotscheme "github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned/scheme"
Expand All @@ -54,7 +55,7 @@ const (

// Command line flags
var (
snapshotter = flag.String("snapshotter", "", "This option is deprecated.")
snapshotterName = flag.String("snapshotter", "", "This option is deprecated.")
kubeconfig = flag.String("kubeconfig", "", "Absolute path to the kubeconfig file. Required only when running out of cluster.")
connectionTimeout = flag.Duration("connection-timeout", 0, "The --connection-timeout flag is deprecated")
csiAddress = flag.String("csi-address", "/run/csi/socket", "Address of the CSI driver socket.")
Expand Down Expand Up @@ -83,7 +84,7 @@ func main() {
if *connectionTimeout != 0 {
glog.Warning("--connection-timeout is deprecated and will have no effect")
}
if *snapshotter != "" {
if *snapshotterName != "" {
glog.Warning("--snapshotter is deprecated and will have no effect")
}

Expand Down Expand Up @@ -138,13 +139,13 @@ func main() {
defer cancel()

// Find driver name
*snapshotter, err = csirpc.GetDriverName(ctx, csiConn)
*snapshotterName, err = csirpc.GetDriverName(ctx, csiConn)
if err != nil {
glog.Errorf("error getting CSI driver name: %v", err)
os.Exit(1)
}

glog.V(2).Infof("CSI driver name: %q", *snapshotter)
glog.V(2).Infof("CSI driver name: %q", *snapshotterName)

// Check it's ready
if err = csirpc.ProbeForever(csiConn, csiTimeout); err != nil {
Expand All @@ -160,7 +161,7 @@ func main() {
os.Exit(1)
}
if !supportsCreateSnapshot {
glog.Errorf("CSI driver %s does not support ControllerCreateSnapshot", *snapshotter)
glog.Errorf("CSI driver %s does not support ControllerCreateSnapshot", *snapshotterName)
os.Exit(1)
}

Expand All @@ -169,13 +170,13 @@ func main() {
os.Exit(1)
}

glog.V(2).Infof("Start NewCSISnapshotController with snapshotter [%s] kubeconfig [%s] connectionTimeout [%+v] csiAddress [%s] createSnapshotContentRetryCount [%d] createSnapshotContentInterval [%+v] resyncPeriod [%+v] snapshotNamePrefix [%s] snapshotNameUUIDLength [%d]", *snapshotter, *kubeconfig, *connectionTimeout, *csiAddress, createSnapshotContentRetryCount, *createSnapshotContentInterval, *resyncPeriod, *snapshotNamePrefix, snapshotNameUUIDLength)
glog.V(2).Infof("Start NewCSISnapshotController with snapshotter [%s] kubeconfig [%s] connectionTimeout [%+v] csiAddress [%s] createSnapshotContentRetryCount [%d] createSnapshotContentInterval [%+v] resyncPeriod [%+v] snapshotNamePrefix [%s] snapshotNameUUIDLength [%d]", *snapshotterName, *kubeconfig, *connectionTimeout, *csiAddress, createSnapshotContentRetryCount, *createSnapshotContentInterval, *resyncPeriod, *snapshotNamePrefix, snapshotNameUUIDLength)

snapShotter := controller.NewSnapshotter(csiConn)
snapShotter := snapshotter.NewSnapshotter(csiConn)
ctrl := controller.NewCSISnapshotController(
snapClient,
kubeClient,
*snapshotter,
*snapshotterName,
factory.Volumesnapshot().V1alpha1().VolumeSnapshots(),
factory.Volumesnapshot().V1alpha1().VolumeSnapshotContents(),
factory.Volumesnapshot().V1alpha1().VolumeSnapshotClasses(),
Expand Down
5 changes: 3 additions & 2 deletions pkg/controller/csi_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

crdv1 "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1alpha1"
"github.com/kubernetes-csi/external-snapshotter/pkg/snapshotter"

"k8s.io/api/core/v1"
)
Expand All @@ -36,15 +37,15 @@ type Handler interface {

// csiHandler is a handler that calls CSI to create/delete volume snapshot.
type csiHandler struct {
snapshotter Snapshotter
snapshotter snapshotter.Snapshotter
timeout time.Duration
snapshotNamePrefix string
snapshotNameUUIDLength int
}

// NewCSIHandler returns a handler which includes the csi connection and Snapshot name details
func NewCSIHandler(
snapshotter Snapshotter,
snapshotter snapshotter.Snapshotter,
timeout time.Duration,
snapshotNamePrefix string,
snapshotNameUUIDLength int,
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/snapshot_controller_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
clientset "github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned"
storageinformers "github.com/kubernetes-csi/external-snapshotter/pkg/client/informers/externalversions/volumesnapshot/v1alpha1"
storagelisters "github.com/kubernetes-csi/external-snapshotter/pkg/client/listers/volumesnapshot/v1alpha1"
"github.com/kubernetes-csi/external-snapshotter/pkg/snapshotter"

"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -81,7 +82,7 @@ func NewCSISnapshotController(
pvcInformer coreinformers.PersistentVolumeClaimInformer,
createSnapshotContentRetryCount int,
createSnapshotContentInterval time.Duration,
snapshotter Snapshotter,
snapshotter snapshotter.Snapshotter,
timeout time.Duration,
resyncPeriod time.Duration,
snapshotNamePrefix string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package controller
package snapshotter

import (
"context"
Expand All @@ -31,6 +31,7 @@ import (
"k8s.io/api/core/v1"
)

// Snapshotter implements CreateSnapshot/DeleteSnapshot operations against a remote CSI driver.
type Snapshotter interface {
// CreateSnapshot creates a snapshot for a volume
CreateSnapshot(ctx context.Context, snapshotName string, volume *v1.PersistentVolume, parameters map[string]string, snapshotterCredentials map[string]string) (driverName string, snapshotId string, timestamp int64, size int64, readyToUse bool, err error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package controller
package snapshotter

import (
"context"
Expand Down

0 comments on commit 2f11d41

Please sign in to comment.