This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 330
AWS ECS Runner Uninstall Fix #4792
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:bug | ||
runneruninstall/aws-ecs: Fix deletion of file system for AWS ECS runner. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -359,28 +359,28 @@ func (i *ECSRunnerInstaller) Uninstall(ctx context.Context, opts *InstallOpts) e | |
return err | ||
} | ||
|
||
s.Update("Runner uninstalled") | ||
s.Update("Waypoint runner AWS ECS service deleted") | ||
} | ||
s.Done() | ||
|
||
// TODO: Still attempt to delete the EFS volume if the ECS service | ||
// uninstall fails | ||
s = sg.Add("Deleting runner file system") | ||
efsSvc := efs.New(sess) | ||
marker := "" | ||
done := false | ||
var fileSystems []*efs.FileSystemDescription | ||
for !done { | ||
fileSystemsResp, err := efsSvc.DescribeFileSystems(&efs.DescribeFileSystemsInput{ | ||
Marker: aws.String(marker), | ||
MaxItems: aws.Int64(100), | ||
err = efsSvc.DescribeFileSystemsPages(&efs.DescribeFileSystemsInput{}, | ||
func(page *efs.DescribeFileSystemsOutput, lastPage bool) bool { | ||
fileSystems = append(fileSystems, page.FileSystems...) | ||
return !lastPage | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
if marker == *fileSystemsResp.Marker { | ||
done = true | ||
} | ||
fileSystems = append(fileSystems, fileSystemsResp.FileSystems...) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(fileSystems) == 0 { | ||
s.Update("No file systems detected, skipping deletion") | ||
s.Done() | ||
return nil | ||
} | ||
|
||
var fileSystemId *string | ||
|
@@ -389,11 +389,20 @@ func (i *ECSRunnerInstaller) Uninstall(ctx context.Context, opts *InstallOpts) e | |
for _, tag := range fileSystem.Tags { | ||
if *tag.Key == "runner-id" && *tag.Value == opts.Id { | ||
fileSystemId = fileSystem.FileSystemId | ||
// This goto skips to the logic for deleting the file system - | ||
// we know which one we need to delete now, so there's no need | ||
// to iterate through any additional fileSystems | ||
goto DeleteFileSystem | ||
} | ||
} | ||
} | ||
|
||
if *fileSystemId == "" { | ||
s.Update("File system with tag key `runner-id` and value " + opts.Id + " not detected, skipping deletion") | ||
s.Done() | ||
return nil | ||
} | ||
|
||
DeleteFileSystem: | ||
describeAccessPointsResp, err := efsSvc.DescribeAccessPoints(&efs.DescribeAccessPointsInput{ | ||
FileSystemId: fileSystemId, | ||
|
@@ -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 commentThe 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 commentThe 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! |
||
for _, mountTarget := range describeMountTargetsResp.MountTargets { | ||
_, err = efsSvc.DeleteMountTarget(&efs.DeleteMountTargetInput{MountTargetId: mountTarget.MountTargetId}) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
ctx, cancel := context.WithTimeout(ctx, 5*time.Minute) | ||
defer cancel() | ||
for { | ||
ctx, cancel := context.WithTimeout(ctx, 5*time.Minute) | ||
defer cancel() | ||
select { | ||
case <-ctx.Done(): | ||
return errors.New("after 5 minutes, the file system could" + | ||
|
@@ -439,6 +445,8 @@ DeleteFileSystem: | |
return err | ||
} | ||
// if we reach this point, we're done | ||
s.Update("Runner file system deleted") | ||
s.Done() | ||
return nil | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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, theelse
is unnecessary if we simply add areturn nil
here, and it improves readability by reducing the mental stack people will make when reading by 1There 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 theelse
case, so the step is completed before thereturn nil
is hit when the file system gets deleted, but forgot to apply the same up here.