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 2159cdf
Show file tree
Hide file tree
Showing 9 changed files with 58 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
6 changes: 6 additions & 0 deletions aws-ebs-csi-driver/templates/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ spec:
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
args:
- --endpoint=$(CSI_ENDPOINT)
{{- if .Values.region }}
- --region={{ .Values.region }}
{{- end }}
{{- if .Values.runAsController }}
- --run-as-controller={{ .Values.runAsController }}
{{- end }}
- --logtostderr
- --v=5
{{ include "aws-ebs-csi-driver.extra-volume-tags" . }}
Expand Down
2 changes: 2 additions & 0 deletions aws-ebs-csi-driver/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ affinity: {}
# key1: value1
# key2: value2
extraVolumeTags: {}
region: ""
runAsController: false
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
2 changes: 2 additions & 0 deletions deploy/kubernetes/base/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ spec:
args :
- --endpoint=$(CSI_ENDPOINT)
- --logtostderr
# - --region=us-east-1 # overwrite the AWS region instead of looking it up dynamically via the AWS EC2 metadata svc
# - --run-as-controller=true # only run the controller service of the driver
- --v=5
env:
- name: CSI_ENDPOINT
Expand Down
10 changes: 10 additions & 0 deletions docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,13 @@ Blindly return:
rpc:
- STAGE\_UNSTAGE\_VOLUME
```

## Running the controller separately

Traditionally, you run the CSI controllers with the EBS driver in the same Kubernetes cluster.
Though, in some scenarios you might want to run the CSI controllers (csi-provisioner, csi-attacher, etc.) together with the EBS controller service of this driver separately from the Kubernetes cluster it serves (while the EBS driver with an activated node service still runs inside the cluster).
Also, this may not necessarily have to be an AWS EC2 instance.
To support these cases, the AWS EBS CSI driver plugin supports two command line flags:

* `--region=<...>` which allows you to specify the AWS region the served Kubernetes cluster is deployed to (if not specified then the controller service of the EBS driver will try to look the region up dynamically via the AWS EC2 metadata service).
* `--run-as-controller=true` which allows you to only start the controller service (and not the node service) of the EBS driver.
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 2159cdf

Please sign in to comment.