-
Notifications
You must be signed in to change notification settings - Fork 788
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: sfn delete workflow (with prod token validation and messaging) #1379
Changes from 3 commits
d29e954
ec63ea9
62716c4
d8abdaf
ebd6689
42c2f6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -333,23 +333,12 @@ def resolve_token( | |
# we allow the user who deployed the previous version to re-deploy, | ||
# even if they don't have the token | ||
if prev_user != get_username() and authorize != prev_token: | ||
obj.echo( | ||
"There is an existing version of *%s* on AWS Step " | ||
"Functions which was deployed by the user " | ||
"*%s*." % (name, prev_user) | ||
) | ||
obj.echo( | ||
"To deploy a new version of this flow, you need to use " | ||
"the same production token that they used. " | ||
) | ||
obj.echo( | ||
"Please reach out to them to get the token. Once you " | ||
"have it, call this command:" | ||
) | ||
obj.echo(" step-functions create --authorize MY_TOKEN", fg="green") | ||
obj.echo( | ||
'See "Organizing Results" at docs.metaflow.org for more ' | ||
"information about production tokens." | ||
echo_token_instructions( | ||
obj, | ||
name, | ||
prev_user, | ||
cmd_name="create", | ||
cmd_description="deploy a new version of", | ||
) | ||
raise IncorrectProductionToken( | ||
"Try again with the correct " "production token." | ||
|
@@ -545,3 +534,91 @@ def list_runs( | |
"No executions for *%s* found on AWS Step Functions." | ||
% (obj.state_machine_name) | ||
) | ||
|
||
|
||
@step_functions.command(help="Delete a workflow") | ||
@click.option( | ||
"--authorize", | ||
default=None, | ||
type=str, | ||
help="Authorize the deletion with a production token", | ||
) | ||
@click.pass_obj | ||
def delete(obj, authorize=None): | ||
validate_token(obj.state_machine_name, obj.token_prefix, obj, authorize, "delete") | ||
|
||
obj.echo( | ||
"Deleting Step Function *{name}*...".format(name=obj.state_machine_name), | ||
saikonen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bold=True, | ||
) | ||
schedule_deleted, sfn_deleted = StepFunctions.delete(obj.state_machine_name) | ||
|
||
if schedule_deleted: | ||
obj.echo( | ||
"Deleting EventBridge rule *{name}* as well...".format( | ||
saikonen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
name=obj.state_machine_name | ||
), | ||
bold=True, | ||
) | ||
if sfn_deleted: | ||
obj.echo( | ||
"Deleting the Step Function may take a while. " | ||
saikonen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"Deploying the flow again to Step Functions while the delete is in-flight will fail." | ||
) | ||
obj.echo( | ||
"In-flight executions will not be affected. " | ||
"If necessary, terminate them manually." | ||
) | ||
|
||
|
||
def validate_token(name, token_prefix, obj, authorize, cmd_name): | ||
# 1) retrieve the previous deployment, if one exists | ||
workflow = StepFunctions.get_existing_deployment(name) | ||
if workflow is None: | ||
prev_token = None | ||
else: | ||
prev_user, prev_token = workflow | ||
|
||
# 2) authorize this deployment | ||
if prev_token is not None: | ||
if authorize is None: | ||
authorize = load_token(token_prefix) | ||
elif authorize.startswith("production:"): | ||
authorize = authorize[11:] | ||
|
||
# we allow the user who deployed the previous version to re-deploy, | ||
# even if they don't have the token | ||
# NOTE: The username is visible in multiple sources, and can be set by the user. | ||
# Should we consider being stricter here? | ||
if prev_user != get_username() and authorize != prev_token: | ||
echo_token_instructions(obj, name, prev_user, cmd_name) | ||
raise IncorrectProductionToken( | ||
"Try again with the correct production token." | ||
) | ||
|
||
# 3) all validations passed, store the previous token for future use | ||
token = prev_token | ||
|
||
store_token(token_prefix, token) | ||
return True | ||
|
||
|
||
def echo_token_instructions(obj, name, prev_user, cmd_name, cmd_description=None): | ||
obj.echo( | ||
"There is an existing version of *%s* on AWS Step " | ||
"Functions which was deployed by the user " | ||
"*%s*." % (name, prev_user) | ||
) | ||
obj.echo( | ||
"To deploy a new version of this flow, you need to use " | ||
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. this wouldn't work for deletes. also, it is likely that we may have more commands that wouldn't allow us to combine the token instructions into one. Maybe it is indeed okay to have some repetition. 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. seems I simply forgot to make this line dynamic, the same output works in the argo-workflows delete/terminate feature already. refactored this so token usage instructions can be passed to the validator as a function instead, keeping the |
||
"the same production token that they used. " | ||
) | ||
obj.echo( | ||
"Please reach out to them to get the token. Once you " | ||
"have it, call this command:" | ||
) | ||
obj.echo(" step-functions %s --authorize MY_TOKEN" % cmd_name, fg="green") | ||
obj.echo( | ||
'See "Organizing Results" at docs.metaflow.org for more ' | ||
"information about production tokens." | ||
) |
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.
any specific reasons to use
delete
vsdisable
?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.
main reason would be for cleanup purposes, so deleted flows do not leave any residual resources in AWS. A disabled rule would not incur any costs so impact is the same as with delete.
what would the case be for preferring disable over delete? My expectation for how
step-functions delete
command works would be that resources are removed, not simply disabled.