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: add project delete subcommand #609

Merged
merged 3 commits into from
Jan 30, 2020
Merged

feat: add project delete subcommand #609

merged 3 commits into from
Jan 30, 2020

Conversation

sonofachamp
Copy link
Contributor

Added project delete sub-command which can be used to wipe out all project related data.

Address #573

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@sonofachamp sonofachamp requested a review from a team as a code owner January 16, 2020 21:50
@sonofachamp sonofachamp self-assigned this Jan 16, 2020
@efekarakus efekarakus changed the title Add project delete subcommand feat: add project delete subcommand Jan 16, 2020
@sonofachamp
Copy link
Contributor Author

Sample run with two environments and one application deployed to both environments:

ecs-preview project delete --yes
✔ Deleted app myapp from env prod.
✔ Deleted app myapp from env test.
✔ Deleted app myapp resources from project myproj.
✔ Deleted app myapp from project myproj.
✔ Deleted project resources.
✔ Deleted environment prod from project myproj.
✔ Deleted environment test from project myproj.
✔ Deleted project parameters.
✔ Deleted local workspace folder.

Comment on lines +446 to +458
Accounts: aws.StringSlice(accounts),
RetainStacks: aws.Bool(false),
Regions: aws.StringSlice(regions),
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's say that we have env_A deployed in account=1,region=us-west-2 and env_B in account=2,region=us-east-1.

Will this call try to delete a stack in account=1,region=us-east-1? In that situation does it fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So here's the scenario I tested:

ecs-preview project init myproj
// profile1 has creds for account A and region us-west-2
ecs-preview env init --name env1 --profile profile1
// profile2 has creds for account B and region us-east-2
ecs-preview env init --name env2 --profile profile2
ecs-preview app init -n myapp -d ./Dockerfile -t "Load Balanced Web App"
ecs-preview app deploy --name myapp --env env1
ecs-preview app deploy --name myapp --env env2

ecs-preview project delete --yes
✔ Deleted app myapp from env env1.
✔ Deleted app myapp from env env2.
✔ Deleted app myapp resources from project myproj.
✔ Deleted app myapp from project myproj.
✔ Deleted project resources.
✔ Deleted environment env1 from project myproj.
✘ Failed to delete environment env2 from project myproj: failed to find a stack named myproj-env2.
✔ Deleted project parameters.
✔ Deleted local workspace folder.

The StackSet instance deletion works fine across multiple accounts and regions. Environment deletion for the first environment worked, but failed for the second environment. At a glance it seems related to deleting environments requiring specific profiles, but need to dig into the details of why that is. It seems strange that one succeeded.

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 stop-gap for now is to use interactivity to enable the user to select a profile for environment deletion:

ecs-preview project delete

? Are you sure you want to delete project myproj? Yes
✔ Deleted app myapp from env env1.
✔ Deleted app myapp from env env2.
✔ Deleted app myapp resources from project myproj.
✔ Deleted app myapp from project myproj.
✔ Deleted project resources.

? Which named profile should we use to delete env1? one
✔ Deleted environment env1 from project myproj.

? Which named profile should we use to delete env2? two
✔ Deleted environment env2 from project myproj.
✔ Deleted project parameters.
✔ Deleted local workspace folder.

Copy link
Contributor

@iamhopaul123 iamhopaul123 left a comment

Choose a reason for hiding this comment

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

Overall looks good to me. Just some minor comments.

@@ -47,6 +47,28 @@ type deleteAppOpts struct {
projectEnvironments []*archer.Environment
}

func newDeleteAppOpts() (*deleteAppOpts, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Feel like this func has duplicated code with how we initialize deleteAppOpts in this file. Maybe we should reuse newDeleteAppOpts() in this file? Otherwise defining a non-exported function in one file and only use it in another file seems to be a little odd to me. What do you think?

Copy link
Contributor Author

@sonofachamp sonofachamp Jan 20, 2020

Choose a reason for hiding this comment

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

I agree we should reuse the newDeleteAppOpts() function within the BuildAppDeleteCmd() function. I don't want to include that as part of this PR since we'll also need to change the flag bindings to use viper to ensure we can properly handle an error returned from calling this function in the RunE function.

)

var (
errOperationCancelled = errors.New("operation cancelled")
Copy link
Contributor

Choose a reason for hiding this comment

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

In "env_delete" when users stop running the log message is "Aborted deletion of environment %s". I think maybe we should return nil and do nothing if they do not confirm instead of erring out? Also keep a consistent user experience when doing "delete".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After thinking about this a bit I'm torn for a couple of reasons:

  • Returning an error feels more explicit and is less likely to be mis-interpreted relative to returning a successful exit code (0) when the expectation is to have deleted something in the happy path case
  • Trying to "gracefully handle" it through a non-error introduces more state into the opts struct that's then shared between the Ask and Execute methods (both patterns of which I'm not particularly a fan of for the related reasons)

I'm all for a consistent experience, but I don't think it should come at the above costs.

Copy link
Contributor

@iamhopaul123 iamhopaul123 Jan 21, 2020

Choose a reason for hiding this comment

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

That makes sense to me. Actually I am ok with either returning an error or successful code 0. I just want our delete experience (project, env, app) to be consistent.

@sonofachamp sonofachamp requested a review from a team January 17, 2020 19:25
@iamhopaul123 iamhopaul123 requested a review from a team January 17, 2020 20:35
Copy link
Contributor

@efekarakus efekarakus left a comment

Choose a reason for hiding this comment

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

@iamhopaul123 iamhopaul123 requested review from a team, bvtujo and SoManyHs January 29, 2020 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants