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

Create func to reset awsCloudInstances #15316

Merged
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
10 changes: 7 additions & 3 deletions upup/pkg/fi/cloudup/awsup/aws_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,14 @@ func (c *awsCloudImplementation) Region() string {
return c.region
}

var awsCloudInstances map[string]AWSCloud = make(map[string]AWSCloud)
var AWSCloudInstances = NewAWSCloudInstances()
Copy link
Member

Choose a reason for hiding this comment

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

Making this one public doesn't seem like a good idea. Perhaps create a function for setting a specific AWSCloud to a specific region.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is not the region, it's the AWS account. The region is the same but not the account, the second time it runs it keeps the credentials for the account that was set on the first run. When NewAWSCloud() func runs the second time it will not create again the clients because of this if. Since we want to use multi-account we need to reset those clients to use with a different AWS account, here is an example of how we did using a fork with the proposed changes.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I figured that. So what I am proposing is that you can create a new AWSCloud instance for the same region rather than just resetting the map and rerun the entire instantiation logic.

Alternatively, make a public function that resets the private map. Either is better than opening the whole map up for manipulation anywhere in the code.

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 created the public function to reset the map, thanks for the suggestion, makes much more sense than having the map public


func NewAWSCloudInstances() map[string]AWSCloud {
return make(map[string]AWSCloud)
}

func NewAWSCloud(region string, tags map[string]string) (AWSCloud, error) {
raw := awsCloudInstances[region]
raw := AWSCloudInstances[region]
if raw == nil {
c := &awsCloudImplementation{
region: region,
Expand Down Expand Up @@ -375,7 +379,7 @@ func NewAWSCloud(region string, tags map[string]string) (AWSCloud, error) {
c.ssm.Handlers.Send.PushFront(requestLogger)
c.addHandlers(region, &c.ssm.Handlers)

awsCloudInstances[region] = c
AWSCloudInstances[region] = c
raw = c
}

Expand Down
2 changes: 1 addition & 1 deletion upup/pkg/fi/cloudup/awsup/mock_aws_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var _ fi.Cloud = (*MockAWSCloud)(nil)

func InstallMockAWSCloud(region string, zoneLetters string) *MockAWSCloud {
i := BuildMockAWSCloud(region, zoneLetters)
awsCloudInstances[region] = i
AWSCloudInstances[region] = i
allRegions = []*ec2.Region{
{RegionName: aws.String(region)},
}
Expand Down