Skip to content

Commit

Permalink
DataRepositoryAssociations should set the same extra tags with the FS…
Browse files Browse the repository at this point in the history
…x filesystem
  • Loading branch information
everpeace committed Dec 28, 2023
1 parent 3120d26 commit 063cd00
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
18 changes: 18 additions & 0 deletions pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ type DataRepositoryAssociationOptions struct {
DataRepositoryPath string `yaml:"dataRepositoryPath,omitempty" json:"dataRepositoryPath,omitempty"`
FileSystemPath string `yaml:"fileSystemPath,omitempty" json:"fileSystemPath,omitempty"`
S3 *S3DataRepositoryConfiguration `yaml:"s3,omitempty" json:"s3,omitempty"`

extraTags []string
}

func (o *DataRepositoryAssociationOptions) SetExtraTags(extraTags []string) {
o.extraTags = extraTags
}

type S3DataRepositoryConfiguration struct {
Expand Down Expand Up @@ -420,12 +426,24 @@ func (c *cloud) WaitForFileSystemResize(ctx context.Context, fileSystemId string
func (c *cloud) CreateDataRepositoryAssociation(
ctx context.Context, filesystemId string, draOptions *DataRepositoryAssociationOptions,
) (*DataRepositoryAssociation, error) {
var tags = []*fsx.Tag{}
for _, extraTag := range draOptions.extraTags {
extraTagSplit := strings.Split(extraTag, "=")
tagKey := extraTagSplit[0]
tagValue := extraTagSplit[1]

tags = append(tags, &fsx.Tag{
Key: aws.String(tagKey),
Value: aws.String(tagValue),
})
}

input := &fsx.CreateDataRepositoryAssociationInput{
BatchImportMetaDataOnCreate: aws.Bool(draOptions.BatchImportMetaDataOnCreate),
DataRepositoryPath: aws.String(draOptions.DataRepositoryPath),
FileSystemId: aws.String(filesystemId),
FileSystemPath: aws.String(draOptions.FileSystemPath),
Tags: tags,
}
if draOptions.S3 != nil {
s3config := &fsx.S3DataRepositoryConfiguration{}
Expand Down
31 changes: 17 additions & 14 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,6 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol
fsOptions.S3ExportPath = val
}

drasOptions := []*cloud.DataRepositoryAssociationOptions{}
if val, ok := volumeParams[volumeDataRepositoryAssociations]; ok {
if err := yaml.Unmarshal(([]byte)(val), &drasOptions); err != nil {
msg := fmt.Sprintf("Fail to decode '%s' parameter for volume '%s': %s", volumeDataRepositoryAssociations, volName, err.Error())
return nil, status.Error(codes.Aborted, msg)
}
if (fsOptions.S3ImportPath != "" ||
fsOptions.S3ExportPath != "" ||
fsOptions.AutoImportPolicy != "") &&
len(drasOptions) > 0 {
return nil, status.Error(codes.InvalidArgument, "When specifying dataRepositoryAssociations, s3ImportPath,s3ExportPath and autoImportPolicy can not be specified")
}
}

if val, ok := volumeParams[volumeParamsDeploymentType]; ok {
fsOptions.DeploymentType = val
}
Expand Down Expand Up @@ -243,6 +229,23 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol
}
fsOptions.ExtraTags = tagArray

drasOptions := []*cloud.DataRepositoryAssociationOptions{}
if val, ok := volumeParams[volumeDataRepositoryAssociations]; ok {
if err := yaml.Unmarshal(([]byte)(val), &drasOptions); err != nil {
msg := fmt.Sprintf("Fail to decode '%s' parameter for volume '%s': %s", volumeDataRepositoryAssociations, volName, err.Error())
return nil, status.Error(codes.Aborted, msg)
}
if (fsOptions.S3ImportPath != "" ||
fsOptions.S3ExportPath != "" ||
fsOptions.AutoImportPolicy != "") &&
len(drasOptions) > 0 {
return nil, status.Error(codes.InvalidArgument, "When specifying dataRepositoryAssociations, s3ImportPath,s3ExportPath and autoImportPolicy can not be specified")
}
for _, draOptions := range drasOptions {
draOptions.SetExtraTags(fsOptions.ExtraTags)
}
}

fs, err := d.cloud.CreateFileSystem(ctx, volName, fsOptions)
if err != nil {
switch err {
Expand Down

0 comments on commit 063cd00

Please sign in to comment.