-
Notifications
You must be signed in to change notification settings - Fork 330
Conversation
The runner uninstall for AWS will now loop correctly through all file systems' paginated results using a marker. Some other updates are made in this commit to skip deleting the file system if certain conditions are met (if there are no file systems that exist, or none with the right tag). Step groups were also updated.
79fe273
to
c596458
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nitpicks but nothing major that I see yet
internal/runnerinstall/ecs.go
Outdated
done = true | ||
} else { | ||
marker = *fileSystemsResp.NextMarker | ||
time.Sleep(5 * time.Second) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't need the sleep here since we are not waiting for an installation or otherwise status change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this sleep because during testing, I triggered the API's rate limiting. That was before I had this loop working correctly, though so it shouldn't still happen. I will go ahead and remove this.
internal/runnerinstall/ecs.go
Outdated
efsSvc := efs.New(sess) | ||
marker := "" | ||
done := false | ||
var fileSystems []*efs.FileSystemDescription | ||
for !done { | ||
fileSystemsResp, err := efsSvc.DescribeFileSystems(&efs.DescribeFileSystemsInput{ | ||
Marker: aws.String(marker), | ||
req := &efs.DescribeFileSystemsInput{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could possibly reduce this function by using DescribeFileSystemsPages to handle the pagination logic for us, so something like this:
var fileSystems []*efs.FileSystemDescription
err := client.DescribeFileSystemsPages(
&efs.DescribeFileSystemsInput{}, // don't need to set marker. MaxItems also defaults to 100
func(page *efs.DescribeFileSystemsOutput, lastPage bool) bool {
fileSystems = append(fileSystems, page.FileSystems...)
// double check that lastPage is the API telling us it's the last page though
return lastPage
})
fileSystemId = fileSystem.FileSystemId | ||
goto DeleteFileSystem | ||
if len(fileSystems) == 0 { | ||
s.Update("No file systems detected, skipping deletion") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this scenario effectively skips us down to the return
way down around line 462, the else
is unnecessary if we simply add a return nil
here, and it improves readability by reducing the mental stack people will make when reading by 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you here, will update this!
To add a bit of context as to why I did it this way, initially I had both cases of this if statement hitting the same step.Done()
at the end of this function, just before the return. I moved that inside the else
case, so the step is completed before the return nil
is hit when the file system gets deleted, but forgot to apply the same up here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The license header needs to be restored
internal/runnerinstall/ecs.go
Outdated
@@ -1,6 +1,3 @@ | |||
// Copyright (c) HashiCorp, Inc. | |||
// SPDX-License-Identifier: MPL-2.0 | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need these
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how I managed to remove those - added back.
455f74a
to
29c0687
Compare
Simplify runner uninstall func for ECS by removing an `if`. Add the copyright headers back in.
29c0687
to
9329438
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks for making those changes. Just a question remaining about the removed err check other than that ✅
internal/runnerinstall/ecs.go
Outdated
@@ -411,19 +420,16 @@ DeleteFileSystem: | |||
describeMountTargetsResp, err := efsSvc.DescribeMountTargets(&efs.DescribeMountTargetsInput{ | |||
FileSystemId: fileSystemId, | |||
}) | |||
if err != nil { | |||
return err | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not need to check this error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do! I lost this while moving other things around, but fixed up!
Thanks @catsby, pushed up that last |
This PR fixes an error which sometimes occurred during a
runner uninstall
for AWS ECS runners:This occurred when no AWS EFS file systems were detected which had a tag
waypoint-runner
, with the value of the runner's ID assigned to it. This PR fixes that by properly looping through all paginated results of AWS EFS file systems to find a match, and later use that match correctly during deletion. If no matching file systems are found,runner uninstall
will skip attempting to delete it.There was also a possible resource leak with a
defer
inside of afor
loop, which has been fixed.Successful output looks like: