Skip to content

Commit

Permalink
Merge pull request #331 from jacobwolfaws/master
Browse files Browse the repository at this point in the history
Allow for extra tags in controller deployment
  • Loading branch information
k8s-ci-robot committed Jun 20, 2023
2 parents 81efc3b + 93a4264 commit beb3eb8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions cmd/options/controller_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<key1>=<value1>,<key2>=<value2>'")
}
9 changes: 5 additions & 4 deletions docs/options.md
Original file line number Diff line number Diff line change
@@ -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 |
10 changes: 9 additions & 1 deletion pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions pkg/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
}

0 comments on commit beb3eb8

Please sign in to comment.