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

feat(aws-asg): add retry_attempts configuration to customize the maximum waiting time #594

Merged
merged 3 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 22 additions & 3 deletions plugins/builtin/target/aws-asg/plugin/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"strconv"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
Expand All @@ -18,10 +19,18 @@ import (

const (
defaultRetryInterval = 10 * time.Second
defaultRetryLimit = 15
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this from here since there will be a configuration for it.

nodeAttrAWSInstanceID = "unique.platform.aws.instance-id"
)

func getConfigValue(config map[string]string, key string, defaultValue string) string {
value, ok := config[key]
if !ok {
return defaultValue
}

return value
}

// setupAWSClients takes the passed config mapping and instantiates the
// required AWS service clients.
func (t *TargetPlugin) setupAWSClients(config map[string]string) error {
Expand Down Expand Up @@ -300,7 +309,12 @@ func (t *TargetPlugin) ensureActivitiesComplete(ctx context.Context, asg string,
return false, fmt.Errorf("waiting for %v activities to finish", len(ids))
}

return retry(ctx, defaultRetryInterval, defaultRetryLimit, f)
retryLimit, err := strconv.Atoi(getConfigValue(t.config, configKeyRetryAttempts, configValueRetryAttemptsDefault))
if err != nil {
return err
}

return retry(ctx, defaultRetryInterval, retryLimit, f)
}

func (t *TargetPlugin) ensureASGInstancesCount(ctx context.Context, desired int64, asgName string) error {
Expand All @@ -317,7 +331,12 @@ func (t *TargetPlugin) ensureASGInstancesCount(ctx context.Context, desired int6
return false, fmt.Errorf("AutoScaling Group at %v instances of desired %v", asg.Instances, desired)
}

return retry(ctx, defaultRetryInterval, defaultRetryLimit, f)
retryLimit, err := strconv.Atoi(getConfigValue(t.config, configKeyRetryAttempts, configValueRetryAttemptsDefault))
if err != nil {
return err
}

return retry(ctx, defaultRetryInterval, retryLimit, f)
}

// awsNodeIDMap is used to identify the AWS InstanceID of a Nomad node using
Expand Down
4 changes: 3 additions & 1 deletion plugins/builtin/target/aws-asg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ const (
configKeySessionToken = "aws_session_token"
configKeyASGName = "aws_asg_name"
configKeyCredentialProvider = "aws_credential_provider"
configKeyRetryAttempts = "retry_attempts"

// configValues are the default values used when a configuration key is not
// supplied by the operator that are specific to the plugin.
configValueRegionDefault = "us-east-1"
configValueRegionDefault = "us-east-1"
configValueRetryAttemptsDefault = "15"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config values must be strings. Hence the default value should also be a string.


// credentialProvider are the valid options for the aws_credential_provider
// configuration key.
Expand Down