@@ -42,7 +42,12 @@ func (d DirectoryProvisioner) Provision(ctx context.Context, req *csi.CreateVolu
42
42
return nil , err
43
43
}
44
44
45
- mountOptions , err := getMountOptions (ctx , localCloud , fileSystemId , roleArn , crossAccountDNSEnabled )
45
+ var azName string
46
+ if value , ok := volumeParams [AzName ]; ok {
47
+ azName = value
48
+ }
49
+
50
+ mountOptions , mountTargetAddress , err := getMountOptions (ctx , localCloud , fileSystemId , roleArn , crossAccountDNSEnabled , azName )
46
51
if err != nil {
47
52
return nil , err
48
53
}
@@ -108,15 +113,8 @@ func (d DirectoryProvisioner) Provision(ctx context.Context, req *csi.CreateVolu
108
113
// not be used as a mount option in this case.
109
114
volContext [CrossAccount ] = strconv .FormatBool (true )
110
115
} else {
111
- var azName string
112
- if value , ok := volumeParams [AzName ]; ok {
113
- azName = value
114
- }
115
- mountTarget , err := localCloud .DescribeMountTargets (ctx , fileSystemId , azName )
116
- if err != nil {
117
- klog .Warningf ("Failed to describe mount targets for file system %v. Skip using `mounttargetip` mount option: %v" , fileSystemId , err )
118
- } else {
119
- volContext [MountTargetIp ] = mountTarget .IPAddress
116
+ if mountTargetAddress != "" {
117
+ volContext [MountTargetIp ] = mountTargetAddress
120
118
}
121
119
122
120
}
@@ -141,7 +139,7 @@ func (d DirectoryProvisioner) Delete(ctx context.Context, req *csi.DeleteVolumeR
141
139
return err
142
140
}
143
141
144
- mountOptions , err := getMountOptions (ctx , localCloud , fileSystemId , roleArn , crossAccountDNSEnabled )
142
+ mountOptions , _ , err := getMountOptions (ctx , localCloud , fileSystemId , roleArn , crossAccountDNSEnabled , "" )
145
143
if err != nil {
146
144
return err
147
145
}
@@ -186,20 +184,22 @@ func (d DirectoryProvisioner) Delete(ctx context.Context, req *csi.DeleteVolumeR
186
184
return nil
187
185
}
188
186
189
- func getMountOptions (ctx context.Context , cloud cloud.Cloud , fileSystemId string , roleArn string , crossAccountDNSEnabled bool ) ([]string , error ) {
187
+ func getMountOptions (ctx context.Context , cloud cloud.Cloud , fileSystemId string , roleArn string , crossAccountDNSEnabled bool , azName string ) ([]string , string , error ) {
190
188
mountOptions := []string {"tls" , "iam" }
189
+ mountTargetAddress := ""
191
190
if roleArn != "" {
192
191
if crossAccountDNSEnabled {
193
192
// Connect via dns rather than mounttargetip
194
193
mountOptions = append (mountOptions , CrossAccount )
195
194
} else {
196
- mountTarget , err := cloud .DescribeMountTargets (ctx , fileSystemId , "" )
195
+ mountTarget , err := cloud .DescribeMountTargets (ctx , fileSystemId , azName )
197
196
if err == nil {
198
- mountOptions = append (mountOptions , MountTargetIp + "=" + mountTarget .IPAddress )
197
+ mountTargetAddress = mountTarget .IPAddress
198
+ mountOptions = append (mountOptions , MountTargetIp + "=" + mountTargetAddress )
199
199
} else {
200
200
klog .Warningf ("Failed to describe mount targets for file system %v. Skip using `mounttargetip` mount option: %v" , fileSystemId , err )
201
201
}
202
202
}
203
203
}
204
- return mountOptions , nil
204
+ return mountOptions , mountTargetAddress , nil
205
205
}
0 commit comments