Skip to content

Commit

Permalink
Merge pull request #179 from digitalocean/awg/custom-driver-name-master
Browse files Browse the repository at this point in the history
Allow a custom driver name to be specified on the commandline
  • Loading branch information
adamwg authored Sep 17, 2019
2 parents 9c75c0b + 221481b commit 2ca8c14
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 24 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,20 @@ $ kubectl exec -ti my-csi-app /bin/sh
hello-world
```

## Upgrading

When upgrading to a new Kubernetes minor version, you should upgrade the CSI
driver to match. See the table above for which driver version is used with each
Kubernetes version.

Special consideration is necessary when upgrading from Kubernetes 1.11 or
earlier, which uses CSI driver version 0.2 or earlier. In these early releases,
the driver name was `com.digitalocean.csi.dobs`, while in all subsequent
releases it is `dobs.csi.digitalocean.com`. When upgrading, use the commandline
flag `--driver-name` to force the new driver to use the old name. Failing to do
so will cause any existing PVs to be unusable since the new driver will not
manage them and the old driver is no longer running.

## Development

Requirements:
Expand Down
13 changes: 7 additions & 6 deletions cmd/do-csi-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ import (

func main() {
var (
endpoint = flag.String("endpoint", "unix:///var/lib/kubelet/plugins/"+driver.DriverName+"/csi.sock", "CSI endpoint")
token = flag.String("token", "", "DigitalOcean access token")
url = flag.String("url", "https://api.digitalocean.com/", "DigitalOcean API URL")
doTag = flag.String("do-tag", "", "Tag DigitalOcean volumes on Create/Attach")
version = flag.Bool("version", false, "Print the version and exit.")
endpoint = flag.String("endpoint", "unix:///var/lib/kubelet/plugins/"+driver.DefaultDriverName+"/csi.sock", "CSI endpoint")
token = flag.String("token", "", "DigitalOcean access token")
url = flag.String("url", "https://api.digitalocean.com/", "DigitalOcean API URL")
doTag = flag.String("do-tag", "", "Tag DigitalOcean volumes on Create/Attach")
driverName = flag.String("driver-name", driver.DefaultDriverName, "Name for the driver")
version = flag.Bool("version", false, "Print the version and exit.")
)
flag.Parse()

Expand All @@ -40,7 +41,7 @@ func main() {
os.Exit(0)
}

drv, err := driver.NewDriver(*endpoint, *token, *url, *doTag)
drv, err := driver.NewDriver(*endpoint, *token, *url, *doTag, *driverName)
if err != nil {
log.Fatalln(err)
}
Expand Down
10 changes: 3 additions & 7 deletions driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ const (
)

const (
// PublishInfoVolumeName is used to pass the volume name from
// `ControllerPublishVolume` to `NodeStageVolume or `NodePublishVolume`
PublishInfoVolumeName = DriverName + "/volume-name"

// minimumVolumeSizeInBytes is used to validate that the user is not trying
// to create a volume that is smaller than what we support
minimumVolumeSizeInBytes int64 = 1 * giB
Expand Down Expand Up @@ -304,7 +300,7 @@ func (d *Driver) ControllerPublishVolume(ctx context.Context, req *csi.Controlle
ll.Info("volume is already attached")
return &csi.ControllerPublishVolumeResponse{
PublishContext: map[string]string{
PublishInfoVolumeName: vol.Name,
d.publishInfoVolumeName: vol.Name,
},
}, nil
}
Expand All @@ -329,7 +325,7 @@ func (d *Driver) ControllerPublishVolume(ctx context.Context, req *csi.Controlle
}).Warn("assuming volume is attached already")
return &csi.ControllerPublishVolumeResponse{
PublishContext: map[string]string{
PublishInfoVolumeName: vol.Name,
d.publishInfoVolumeName: vol.Name,
},
}, nil
}
Expand Down Expand Up @@ -357,7 +353,7 @@ func (d *Driver) ControllerPublishVolume(ctx context.Context, req *csi.Controlle
ll.Info("volume is attached")
return &csi.ControllerPublishVolumeResponse{
PublishContext: map[string]string{
PublishInfoVolumeName: vol.Name,
d.publishInfoVolumeName: vol.Name,
},
}, nil
}
Expand Down
18 changes: 15 additions & 3 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import (
)

const (
// DriverName defines the name that is used in Kubernetes and the CSI
// DefaultDriverName defines the name that is used in Kubernetes and the CSI
// system for the canonical, official name of this plugin
DriverName = "dobs.csi.digitalocean.com"
DefaultDriverName = "dobs.csi.digitalocean.com"
)

var (
Expand All @@ -54,6 +54,11 @@ var (
// csi.NodeServer
//
type Driver struct {
name string
// publishInfoVolumeName is used to pass the volume name from
// `ControllerPublishVolume` to `NodeStageVolume or `NodePublishVolume`
publishInfoVolumeName string

endpoint string
nodeId string
region string
Expand All @@ -80,7 +85,11 @@ type Driver struct {
// NewDriver returns a CSI plugin that contains the necessary gRPC
// interfaces to interact with Kubernetes over unix domain sockets for
// managaing DigitalOcean Block Storage
func NewDriver(ep, token, url, doTag string) (*Driver, error) {
func NewDriver(ep, token, url, doTag, driverName string) (*Driver, error) {
if driverName == "" {
driverName = DefaultDriverName
}

tokenSource := oauth2.StaticTokenSource(&oauth2.Token{
AccessToken: token,
})
Expand Down Expand Up @@ -114,6 +123,9 @@ func NewDriver(ep, token, url, doTag string) (*Driver, error) {
})

return &Driver{
name: driverName,
publishInfoVolumeName: driverName + "/volume-name",

doTag: doTag,
endpoint: ep,
nodeId: nodeId,
Expand Down
1 change: 1 addition & 0 deletions driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func TestDriverSuite(t *testing.T) {
}

driver := &Driver{
name: DefaultDriverName,
endpoint: endpoint,
nodeId: strconv.Itoa(nodeID),
doTag: doTag,
Expand Down
2 changes: 1 addition & 1 deletion driver/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
// GetPluginInfo returns metadata of the plugin
func (d *Driver) GetPluginInfo(ctx context.Context, req *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) {
resp := &csi.GetPluginInfoResponse{
Name: DriverName,
Name: d.name,
VendorVersion: version,
}

Expand Down
27 changes: 20 additions & 7 deletions driver/node.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2ca8c14

Please sign in to comment.