Skip to content

Commit

Permalink
Convergence part 1: Docker frontend on Trident
Browse files Browse the repository at this point in the history
  • Loading branch information
clintonk committed Nov 3, 2017
1 parent d5a7655 commit 93655eb
Show file tree
Hide file tree
Showing 14 changed files with 993 additions and 35 deletions.
73 changes: 73 additions & 0 deletions core/orchestrator_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ package core
import (
"fmt"
"math/rand"
"os"
"strings"
"sync"
"time"

log "github.com/Sirupsen/logrus"
dvp "github.com/netapp/netappdvp/storage_drivers"
dvp_utils "github.com/netapp/netappdvp/utils"

"github.com/netapp/trident/config"
"github.com/netapp/trident/frontend"
Expand Down Expand Up @@ -844,6 +846,77 @@ func (o *tridentOrchestrator) ListVolumesByPlugin(pluginName string) []*storage.
return volumes
}

// AttachVolume mounts a volume to the local host. It ensures the mount point exists,
// and it calls the underlying storage driver to perform the attach operation as appropriate
// for the protocol and storage controller type.
func (o *tridentOrchestrator) AttachVolume(volumeName, mountpoint string, options map[string]string) error {

volume, ok := o.volumes[volumeName]
if !ok {
return fmt.Errorf("Volume %s not found.", volumeName)
}

log.WithFields(log.Fields{"volume": volumeName, "mountpoint": mountpoint}).Debug("Mounting volume.")

// Ensure mount point exists and is a directory
fileInfo, err := os.Lstat(mountpoint)
if os.IsNotExist(err) {
// Make mount point if it doesn't exist
if err := os.MkdirAll(mountpoint, 0755); err != nil {
return err
}
} else if err != nil {
return err
} else if !fileInfo.IsDir() {
return fmt.Errorf("%v already exists and it's not a directory", mountpoint)
}

// Check if volume is already mounted
dfOutput, dfOuputErr := dvp_utils.GetDFOutput()
if dfOuputErr != nil {
err = fmt.Errorf("Error checking if %v is already mounted: %v", mountpoint, dfOuputErr)
return err
}
for _, e := range dfOutput {
if e.Target == mountpoint {
log.Debugf("%v is already mounted", mountpoint)
return nil
}
}

return volume.Backend.Driver.Attach(volume.Config.InternalName, mountpoint, options)
}

// DetachVolume unmounts a volume from the local host. It ensures the volume is already
// mounted, and it calls the underlying storage driver to perform the detach operation as
// appropriate for the protocol and storage controller type.
func (o *tridentOrchestrator) DetachVolume(volumeName, mountpoint string) error {

volume, ok := o.volumes[volumeName]
if !ok {
return fmt.Errorf("Volume %s not found.", volumeName)
}

log.WithFields(log.Fields{"volume": volumeName, "mountpoint": mountpoint}).Debug("Unmounting volume.")

// Check if the mount point exists, so we know that it's attached and must be cleaned up
_, err := os.Stat(mountpoint)
if err != nil {
// Not attached, so nothing to do
return nil
}

// Unmount the volume
err = volume.Backend.Driver.Detach(volume.Config.InternalName, mountpoint)
if err != nil {
return err
}

// Best effort removal of the mount point
os.Remove(mountpoint)
return nil
}

// getProtocol returns the appropriate protocol name based on volume access mode
//or an empty string if all protocols are applicable.
// ReadWriteOnce -> Any (File + Block)
Expand Down
42 changes: 33 additions & 9 deletions core/orchestrator_core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,9 @@ func TestAddStorageClassVolumes(t *testing.T) {
poolNames: []string{tu.SlowNoSnapshots, tu.SlowSnapshots},
},
{
name: "slow-block",
protocol: config.Block,
poolNames: []string{tu.SlowNoSnapshots, tu.SlowSnapshots,
"medium-overlap"},
name: "slow-block",
protocol: config.Block,
poolNames: []string{tu.SlowNoSnapshots, tu.SlowSnapshots, tu.MediumOverlap},
},
} {
pools := make(map[string]*fake.FakeStoragePool, len(c.poolNames))
Expand Down Expand Up @@ -504,8 +503,8 @@ func TestAddStorageClassVolumes(t *testing.T) {
config: &storage_class.Config{
Name: "specific",
BackendStoragePools: map[string][]string{
"fast-a": []string{tu.FastThinOnly},
"slow-block": []string{tu.SlowNoSnapshots, tu.MediumOverlap},
"fast-a": {tu.FastThinOnly},
"slow-block": {tu.SlowNoSnapshots, tu.MediumOverlap},
},
},
expected: []*tu.PoolMatch{
Expand All @@ -514,12 +513,21 @@ func TestAddStorageClassVolumes(t *testing.T) {
{Backend: "slow-block", Pool: tu.MediumOverlap},
},
},
{
config: &storage_class.Config{
Name: "specificNoMatch",
BackendStoragePools: map[string][]string{
"unknown": {tu.FastThinOnly},
},
},
expected: []*tu.PoolMatch{},
},
{
config: &storage_class.Config{
Name: "mixed",
BackendStoragePools: map[string][]string{
"slow-file": []string{tu.SlowNoSnapshots},
"fast-b": []string{tu.FastThinOnly, tu.FastUniqueAttr},
"slow-file": {tu.SlowNoSnapshots},
"fast-b": {tu.FastThinOnly, tu.FastUniqueAttr},
},
Attributes: map[string]sa.Request{
sa.IOPS: sa.NewIntRequest(2000),
Expand All @@ -535,6 +543,22 @@ func TestAddStorageClassVolumes(t *testing.T) {
{Backend: "slow-file", Pool: tu.SlowNoSnapshots},
},
},
{
config: &storage_class.Config{
Name: "emptyStorageClass",
},
expected: []*tu.PoolMatch{
{Backend: "fast-a", Pool: tu.FastSmall},
{Backend: "fast-a", Pool: tu.FastThinOnly},
{Backend: "fast-b", Pool: tu.FastThinOnly},
{Backend: "fast-b", Pool: tu.FastUniqueAttr},
{Backend: "slow-file", Pool: tu.SlowNoSnapshots},
{Backend: "slow-file", Pool: tu.SlowSnapshots},
{Backend: "slow-block", Pool: tu.SlowNoSnapshots},
{Backend: "slow-block", Pool: tu.SlowSnapshots},
{Backend: "slow-block", Pool: tu.MediumOverlap},
},
},
}
for _, s := range scTests {
_, err := orchestrator.AddStorageClass(s.config)
Expand Down Expand Up @@ -1523,7 +1547,7 @@ func TestBootstrapEtcdV2ToEtcdV3Migration(t *testing.T) {
t.Fatalf("Couldn't unmarshall the orchestrator persistent state version: %v",
err)
}
if config.OrchestratorAPIVersion != version.OrchestratorVersion ||
if config.OrchestratorAPIVersion != version.OrchestratorAPIVersion ||
string(orchestratorV3.storeClient.GetType()) != version.PersistentStoreVersion {
t.Fatalf("Failed to set the orchestrator persistent state version after bootsrapping: %v",
err)
Expand Down
10 changes: 9 additions & 1 deletion core/orchestrator_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (m *MockOrchestrator) AddFrontend(f frontend.FrontendPlugin) {
// NOP for the time being, since users of MockOrchestrator don't need this
}

func (o *MockOrchestrator) GetVersion() string {
func (m *MockOrchestrator) GetVersion() string {
return config.OrchestratorVersion.String()
}

Expand Down Expand Up @@ -299,6 +299,14 @@ func (m *MockOrchestrator) ListVolumesByPlugin(pluginName string) []*storage.Vol
return nil
}

func (m *MockOrchestrator) AttachVolume(volumeName, mountpoint string, options map[string]string) error {
return nil
}

func (m *MockOrchestrator) DetachVolume(volumeName, mountpoint string) error {
return nil
}

func NewMockOrchestrator() *MockOrchestrator {
return &MockOrchestrator{
backends: make(map[string]*storage.StorageBackend),
Expand Down
2 changes: 2 additions & 0 deletions core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type Orchestrator interface {
ListVolumes() []*storage.VolumeExternal
DeleteVolume(volume string) (found bool, err error)
ListVolumesByPlugin(pluginName string) []*storage.VolumeExternal
AttachVolume(volumeName, mountpoint string, options map[string]string) error
DetachVolume(volumeName, mountpoint string) error

AddStorageClass(scConfig *storage_class.Config) (*storage_class.StorageClassExternal, error)
GetStorageClass(scName string) *storage_class.StorageClassExternal
Expand Down
2 changes: 1 addition & 1 deletion extras/external-etcd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ For more information about the Secrets used by the operator, please see
and [Generating Self-signed Certificates](https://coreos.com/os/docs/latest/generate-self-signed-certificates.html).


### Testing etcd Cluster
### Test etcd Cluster

To verify the cluster we brought up in the previous step is working properly,
we can run the following commands:
Expand Down
11 changes: 11 additions & 0 deletions frontend/docker/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2017 NetApp, Inc. All Rights Reserved.

package docker

const (
pluginName = "docker"
pluginVersion = "0.1"

auto_storage_class_prefix = "auto_sc_%d"
default_volume_size = "1g"
)
Loading

0 comments on commit 93655eb

Please sign in to comment.