Skip to content

Commit

Permalink
Move maxAttempts to more generic handling code for adding environme…
Browse files Browse the repository at this point in the history
…nt variables (#214)

* Migrate `maxAttempts` to more generic handling code for adding environment variables.


---------

Co-authored-by: Simon Beal <simobeal@amazon.com>
  • Loading branch information
muddyfish and Simon Beal committed Jun 27, 2024
1 parent d2ec184 commit 2234a3b
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 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:]...)
}
options, env = moveOptionToEnvironmentVariables(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,25 @@ func (m *S3Mounter) Mount(bucketName string, target string,
return nil
}

// Moves a parameter optionName from the options list to MP's environment variable list. We need this as options are
// passed to the driver in a single field, but MP sometimes only supports config from environment variables.
// Returns an updated options and environment.
func moveOptionToEnvironmentVariables(optionName string, envName string, options []string, env []string) ([]string, []string) {
optionIdx := -1
for i, o := range options {
if strings.HasPrefix(o, optionName) {
optionIdx = i
break
}
}
if optionIdx != -1 {
// We can do replace here as we've just verified it has the right prefix
env = append(env, strings.Replace(options[optionIdx], optionName, envName, 1))
options = append(options[:optionIdx], options[optionIdx+1:]...)
}
return options, env
}

// 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 2234a3b

Please sign in to comment.