Skip to content

Commit

Permalink
Migrate maxAttempts to more generic handling code for adding enviro…
Browse files Browse the repository at this point in the history
…nment variables.
  • Loading branch information
Simon Beal committed Jun 26, 2024
1 parent d2ec184 commit 2b9b184
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions pkg/driver/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,20 +239,7 @@ func (m *S3Mounter) Mount(bucketName string, target string,
if credentials != nil {
env = credentials.Env()
}

// Max attempts is passed to the driver as a mount option, but is passed to mp via env variable
// so we need to remove it from the options and add it to the env.
maxAttemptsIdx := -1
for i, o := range options {
if strings.HasPrefix(o, awsMaxAttemptsOption) {
maxAttemptsIdx = i
break
}
}
if maxAttemptsIdx != -1 {
env = append(env, strings.Replace(options[maxAttemptsIdx], awsMaxAttemptsOption, awsMaxAttemptsEnv, 1))
options = append(options[:maxAttemptsIdx], options[maxAttemptsIdx+1:]...)
}
env, options = addOptionToEnvironmentVariables(awsMaxAttemptsOption, awsMaxAttemptsEnv, options, env)

output, err := m.Runner.StartService(timeoutCtx, &system.ExecConfig{
Name: "mount-s3-" + m.MpVersion + "-" + uuid.New().String() + ".service",
Expand All @@ -272,6 +259,23 @@ func (m *S3Mounter) Mount(bucketName string, target string,
return nil
}

func addOptionToEnvironmentVariables(optionName string, envName string, options []string, env []string) ([]string, []string) {
// optionName is passed to the driver as a mount option, but is passed to MP via env variable
// so we need to remove it from the options and add it to the env.
optionIdx := -1
for i, o := range options {
if strings.HasPrefix(o, optionName) {
optionIdx = i
break
}
}
if optionIdx != -1 {
env = append(env, strings.Replace(options[optionIdx], optionName, envName, 1))
options = append(options[:optionIdx], options[optionIdx+1:]...)
}
return env, options
}

// method to add the user agent prefix to the Mountpoint headers
// https://github.com/awslabs/mountpoint-s3/pull/548
func addUserAgentToOptions(options []string) []string {
Expand Down

0 comments on commit 2b9b184

Please sign in to comment.