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

Support creating required KV stores during application deploys #170

Merged

Conversation

kate-goldenring
Copy link
Collaborator

@kate-goldenring kate-goldenring commented Jan 19, 2024

Updates the deploy flow to prompt and create KV stores for an application. The flow matches that of SQL, and I updated the code to share most of the code across SQL and KV using the term inside the database.rs module. This file should be renamed to resource.rs in a subsequent PR. I didn't want to rename it and make it hard to discern the changes.

Note that the deploy --key-values flag only applies to the default store. Should we introduce a way to set pairs during deploy or deprecate this flag and instead instruct them to use the spin cloud kv set (#171) command to set pairs?

TODOs for later PRs:

  • Rename database.rs to resource.rs
  • Handle rollback of created resources in the case of a failure or user termination (we don't do this for SQL either currently)

Copy link
Contributor

@itowlson itowlson left a comment

Choose a reason for hiding this comment

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

This is a tricky one! I did feel a bit "you are lost in a maze of twisty things called resource, all alike" at times, but I don't have a better name (and if I did it would be outside the scope of this PR), and streamlining the "similar but not quite the same enough" bits that make it challenging to follow would take a significant refactor, which I don't think should hold up this PR. Anyway, I left some suggestions but I'm happy to defer most of the style ones to a later refactor - there is one on line 1058 (and surrounding areas) which I care about, and a couple of things I think might be leftovers, but the rest are nits / think-out-louds.

So, sorry for maundering at you, and LGTM!

src/commands/deploy.rs Outdated Show resolved Hide resolved
src/commands/deploy.rs Show resolved Hide resolved
src/commands/deploy.rs Outdated Show resolved Hide resolved
src/commands/deploy.rs Outdated Show resolved Hide resolved
src/commands/deploy/database.rs Outdated Show resolved Hide resolved
src/commands/deploy/database.rs Outdated Show resolved Hide resolved
}
ResourceType::KeyValueStore => {
client
.create_key_value_store(&r, Some(resource_label))
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious why this takes &r and the SQLite arms takes r.clone(). Is the API inconsistent or should it have been &db in the previous code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the create APIs for KV and SQL are inconsistent. The SQL one sends db name in the body of the request while the KV one is updated to send the name in the path. I am hoping down the line to update the sql one to be at parity with KV

src/commands/deploy/database.rs Outdated Show resolved Hide resolved
.await
.with_context(|| {
format!(
r#"Could not link {resource_type} "{}" to app "{}""#,
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh man... the nesting is getting a bit much for me - I find it hard to keep my mental stack when it gets this deep. Maybe that's a matter for a later refactor though.

Copy link
Contributor

@rylev rylev left a comment

Choose a reason for hiding this comment

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

I think I agree with @itowlson here in that this is fine for us to land for now, but it's becoming very clear that a refactor is in order.

.is_none()
{
// User canceled terminal interaction
// TODO: Clean up created databases and kv stores
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this something we need to tackle before we merge this PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think so because we also do not cleanup for SQL and users have the ability to use the CLI to clean up resources with other CLI commands. I'd like to expose get_limit endpoints in the cloud API to support knowing a users limit before we start this flow in case they hit their max on a resource.

src/commands/deploy.rs Outdated Show resolved Hide resolved
@@ -1,80 +1,110 @@
// TODO(kate): rename this module to something more generic like `resource`
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to not do this now? Renaming modules tends to be a pretty straight forward refactor.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I call this out in the PR description. I didn't want to rename it and make it hard to discern the changes.

src/commands/deploy/database.rs Outdated Show resolved Hide resolved
@kate-goldenring kate-goldenring force-pushed the create-kv-stores-during-deploys branch from 869f3ed to 9a4981a Compare January 19, 2024 21:08
@kate-goldenring kate-goldenring merged commit 72ffeab into fermyon:main Jan 22, 2024
8 checks passed
@kate-goldenring kate-goldenring deleted the create-kv-stores-during-deploys branch January 22, 2024 01:17
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