From 93a4264b9c16797bdba179ff6e4e396e40aae405 Mon Sep 17 00:00:00 2001 From: Jacob Wolf Date: Tue, 20 Jun 2023 16:46:19 +0000 Subject: [PATCH] Allow for extra tags in controller deployment --- cmd/main.go | 1 + cmd/options/controller_options.go | 3 +++ docs/options.md | 9 +++++---- pkg/driver/controller.go | 10 +++++++++- pkg/driver/driver.go | 11 +++++++++-- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 20955528..740f8511 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -37,6 +37,7 @@ func main() { drv, err := driver.NewDriver( driver.WithEndpoint(options.ServerOptions.Endpoint), driver.WithMode(options.ServerOptions.DriverMode), + driver.WithExtraTags(options.ControllerOptions.ExtraTags), ) if err != nil { diff --git a/cmd/options/controller_options.go b/cmd/options/controller_options.go index 990d5e2c..53609b6c 100644 --- a/cmd/options/controller_options.go +++ b/cmd/options/controller_options.go @@ -22,7 +22,10 @@ import ( // ControllerOptions contains options and configuration settings for the controller service. type ControllerOptions struct { + // ExtraTags is a map of tags that will be attached to each dynamically provisioned resource. + ExtraTags string } func (s *ControllerOptions) AddFlags(fs *flag.FlagSet) { + fs.StringVar(&s.ExtraTags, "extra-tags", "", "Extra tags to attach to each dynamically provisioned resource. It is a comma separated list of key value pairs like '=,='") } diff --git a/docs/options.md b/docs/options.md index 499c8826..e38bf62c 100644 --- a/docs/options.md +++ b/docs/options.md @@ -1,7 +1,8 @@ # Driver Options There are a couple of driver options that can be passed as arguments when starting the driver container. -| Option argument | value sample | default | Description | -|-----------------------------|---------------------------------------------------|-----------------------------------------------------|---------------------| -| endpoint | tcp://127.0.0.1:10000/ | unix:///var/lib/csi/sockets/pluginproxy/csi.sock | The socket on which the driver will listen for CSI RPCs| -| logging-format | json | text | Sets the log format. Permitted formats: text, json| +| Option argument | value sample | default | Description | +|-----------------------------|---------------------------------------------------|-----------------------------------------------------|---------------------------------------------------------------------------------------------| +| endpoint | tcp://127.0.0.1:10000/ | unix:///var/lib/csi/sockets/pluginproxy/csi.sock | The socket on which the driver will listen for CSI RPCs | +| extra-tags | key1=value1,key2=value2 | | Tags specified in the controller spec are attached to each dynamically provisioned resource | +| logging-format | json | text | Sets the log format. Permitted formats: text, json | diff --git a/pkg/driver/controller.go b/pkg/driver/controller.go index 24d1b4ce..2b4a54c9 100644 --- a/pkg/driver/controller.go +++ b/pkg/driver/controller.go @@ -213,10 +213,18 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol fsOptions.CapacityGiB = util.RoundUpVolumeSize(capRange.GetRequiredBytes(), fsOptions.DeploymentType, fsOptions.StorageType, fsOptions.PerUnitStorageThroughput) } + var tagArray []string + optionsTags := d.driverOptions.extraTags + + if optionsTags != "" { + tagArray = strings.Split(optionsTags, ",") + } + if val, ok := volumeParams[volumeParamsExtraTags]; ok { extraTags := strings.Split(val, ",") - fsOptions.ExtraTags = extraTags + tagArray = append(tagArray, extraTags...) } + fsOptions.ExtraTags = tagArray fs, err := d.cloud.CreateFileSystem(ctx, volName, fsOptions) if err != nil { diff --git a/pkg/driver/driver.go b/pkg/driver/driver.go index 46368d86..5c8d9d5e 100644 --- a/pkg/driver/driver.go +++ b/pkg/driver/driver.go @@ -52,8 +52,9 @@ type Driver struct { } type DriverOptions struct { - endpoint string - mode string + endpoint string + mode string + extraTags string } func NewDriver(options ...func(*DriverOptions)) (*Driver, error) { @@ -143,3 +144,9 @@ func WithMode(mode string) func(*DriverOptions) { o.mode = mode } } + +func WithExtraTags(extraTags string) func(*DriverOptions) { + return func(o *DriverOptions) { + o.extraTags = extraTags + } +}