Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move maxAttempts to more generic handling code for adding environment variables #214

Merged
merged 3 commits into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
passaro marked this conversation as resolved.
Show resolved Hide resolved
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
Loading