Skip to content

Commit

Permalink
Allow running the controller service separately
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranzke committed Jan 10, 2020
1 parent c1fdc87 commit 79cb969
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
FROM golang:1.12.7-stretch as builder
WORKDIR /go/src/github.com/kubernetes-sigs/aws-ebs-csi-driver
ADD . .
RUN make
RUN make

FROM amazonlinux:2
RUN yum install ca-certificates e2fsprogs xfsprogs util-linux -y
Expand Down
10 changes: 8 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ import (

func main() {
var (
version bool
endpoint string
extraVolumeTags map[string]string
region string
runAsController bool
version bool
)

flag.BoolVar(&version, "version", false, "Print the version and exit.")
flag.StringVar(&endpoint, "endpoint", driver.DefaultCSIEndpoint, "CSI Endpoint")
flag.Var(cliflag.NewMapStringString(&extraVolumeTags), "extra-volume-tags", "Extra volume tags to attach to each dynamically provisioned volume. It is a comma separated list of key value pairs like '<key1>=<value1>,<key2>=<value2>'")
flag.StringVar(&region, "region", "", "If specified then the given AWS region will be taken instead of trying to look it up via the AWS EC2 metadata service.")
flag.BoolVar(&runAsController, "run-as-controller", false, "If set to true then the CSI driver runs the controller only and does not start the node service.")
flag.BoolVar(&version, "version", false, "Print the version and exit.")

klog.InitFlags(nil)
flag.Parse()
Expand All @@ -52,6 +56,8 @@ func main() {
drv, err := driver.NewDriver(
driver.WithEndpoint(endpoint),
driver.WithExtraVolumeTags(extraVolumeTags),
driver.WithRegion(region),
driver.WithRunAsController(runAsController),
)
if err != nil {
klog.Fatalln(err)
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ github.com/codedellemc/goscaleio v0.0.0-20170830184815-20e2ce2cf885/go.mod h1:JI
github.com/codegangsta/negroni v1.0.0/go.mod h1:v0y3T5G7Y1UlFfyxFn/QLRU4a2EuNau2iZY63YTKWo0=
github.com/container-storage-interface/spec v1.1.0 h1:qPsTqtR1VUPvMPeK0UnCZMtXaKGyyLPG8gj/wG6VqMs=
github.com/container-storage-interface/spec v1.1.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=
github.com/container-storage-interface/spec v1.2.0 h1:bD9KIVgaVKKkQ/UbVUY9kCaH/CJbhNxe0eeB4JeJV2s=
github.com/containerd/console v0.0.0-20170925154832-84eeaae905fa/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw=
github.com/containerd/containerd v1.0.2/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
github.com/containerd/typeurl v0.0.0-20190228175220-2a93cfde8c20/go.mod h1:Cm3kwCdlkCfMSHURc+r6fwoGH6/F1hH3S4sg0rLFWPc=
Expand Down
12 changes: 8 additions & 4 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,15 @@ type controllerService struct {
// newControllerService creates a new controller service
// it panics if failed to create the service
func newControllerService(driverOptions *DriverOptions) controllerService {
metadata, err := cloud.NewMetadata()
if err != nil {
panic(err)
region := driverOptions.region
if region == "" {
metadata, err := cloud.NewMetadata()
if err != nil {
panic(err)
}
region = metadata.GetRegion()
}
region := metadata.GetRegion()

cloud, err := cloud.NewCloud(region)
if err != nil {
panic(err)
Expand Down
22 changes: 20 additions & 2 deletions pkg/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ type Driver struct {
type DriverOptions struct {
endpoint string
extraVolumeTags map[string]string
region string
runAsController bool
}

func NewDriver(options ...func(*DriverOptions)) (*Driver, error) {
klog.Infof("Driver: %v Version: %v", DriverName, driverVersion)

driverOptions := DriverOptions{
endpoint: DefaultCSIEndpoint,
endpoint: DefaultCSIEndpoint,
runAsController: false,
}
for _, option := range options {
option(&driverOptions)
Expand All @@ -61,10 +64,13 @@ func NewDriver(options ...func(*DriverOptions)) (*Driver, error) {

driver := Driver{
controllerService: newControllerService(&driverOptions),
nodeService: newNodeService(),
options: &driverOptions,
}

if driverOptions.runAsController {
driver.nodeService = newNodeService()
}

return &driver, nil
}

Expand Down Expand Up @@ -110,6 +116,18 @@ func WithEndpoint(endpoint string) func(*DriverOptions) {
}
}

func WithRegion(region string) func(*DriverOptions) {
return func(o *DriverOptions) {
o.region = region
}
}

func WithRunAsController(runAsController bool) func(*DriverOptions) {
return func(o *DriverOptions) {
o.runAsController = runAsController
}
}

func WithExtraVolumeTags(extraVolumeTags map[string]string) func(*DriverOptions) {
return func(o *DriverOptions) {
o.extraVolumeTags = extraVolumeTags
Expand Down

0 comments on commit 79cb969

Please sign in to comment.