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

Add --storage-id flag to Repo Create CLI #8557

Merged
merged 19 commits into from
Feb 10, 2025
Merged

Conversation

itaigilo
Copy link
Contributor

Closes #8511.

Change Description

Support creating a repository with storageID in the CLI.

@itaigilo itaigilo added exclude-changelog PR description should not be included in next release changelog minor-change Used for PRs that don't require issue attached msb labels Jan 27, 2025
Copy link

github-actions bot commented Jan 27, 2025

🎊 PR Preview 2049918 has been successfully built and deployed to https://treeverse-lakeFS-preview-pr-8557.surge.sh

🕐 Build time: 0.01s

🤖 By surge-preview

Copy link

E2E Test Results - DynamoDB Local - Local Block Adapter

13 passed

Copy link

github-actions bot commented Jan 27, 2025

E2E Test Results - Quickstart

11 passed

Copy link
Member

@N-o-Z N-o-Z left a comment

Choose a reason for hiding this comment

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

Thanks!
Some comments regarding documentation +
Please add esti tests

I have some reservations on documenting this parameter ATM.
Also, lets have a discussion on this in a different forum

@@ -16,7 +16,7 @@ const (

// repoCreateCmd represents the create repo command
var repoCreateCmd = &cobra.Command{
Use: "create <repository URI> <storage namespace>",
Use: "create <repository URI> <storage namespace> [--storage-id <storage id>]",
Copy link
Member

Choose a reason for hiding this comment

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

Lets not document this flag ATM and open an issue to discuss that

@@ -48,6 +52,7 @@ var repoCreateCmd = &cobra.Command{
//nolint:gochecknoinits
func init() {
repoCreateCmd.Flags().StringP("default-branch", "d", DefaultBranch, "the default branch of this repository")
repoCreateCmd.Flags().String("storage-id", "", "the storage of this repository")
Copy link
Member

Choose a reason for hiding this comment

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

Suggest we make this a hidden flag for now

@@ -10,7 +10,7 @@ import (

// repoCreateBareCmd represents the create repo command
var repoCreateBareCmd = &cobra.Command{
Use: "create-bare <repository URI> <storage namespace>",
Use: "create-bare <repository URI> <storage namespace> [--storage-id <storage id>]",
Copy link
Member

Choose a reason for hiding this comment

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

Same comments as the "create" command

@itaigilo
Copy link
Contributor Author

@N-o-Z regarding esti -
repo create is already covered by esti.
I don't think there's any point of also verifying that--storage-id is passed with an empty value.

Any other esti tests you think should be added?

@itaigilo itaigilo requested a review from N-o-Z January 28, 2025 12:02
@N-o-Z
Copy link
Member

N-o-Z commented Feb 4, 2025

@N-o-Z regarding esti - repo create is already covered by esti. I don't think there's any point of also verifying that--storage-id is passed with an empty value.

Any other esti tests you think should be added?

We should test 2 things:

  1. Explicitly passing storage_id with "" value will create a valid repository
  2. Explicitly passing storage_id with any other value should fail

@itaigilo
Copy link
Contributor Author

itaigilo commented Feb 6, 2025

We should test 2 things:

  1. Explicitly passing storage_id with "" value will create a valid repository
  2. Explicitly passing storage_id with any other value should fail

Add the first,
And regarding the second - the CLI isn't failing it, but the Config validation.
So using RunCmdAndVerifyFailureWithFile doesn't work with a proper golden file, since it's not a CLI error.

@N-o-Z Can you think of a way to test this, or are you OK with having the Config tests covering this part?

Copy link
Member

@N-o-Z N-o-Z left a comment

Choose a reason for hiding this comment

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

Looks good.
Still missing a couple of things

@@ -52,7 +52,7 @@ var repoCreateCmd = &cobra.Command{
//nolint:gochecknoinits
func init() {
repoCreateCmd.Flags().StringP("default-branch", "d", DefaultBranch, "the default branch of this repository")
repoCreateCmd.Flags().String("storage-id", "", "the storage of this repository")
repoCreateCmd.Flags().String("storage-id", "", "")
Copy link
Member

Choose a reason for hiding this comment

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

Can you please define the storage-id flag globally (see withNoProgress as example) and set its property to hidden so it won't show up in the CLI docs (MarkHidden)

"BRANCH": mainBranch,
}
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" repo create lakefs://"+repoNameSID+" "+storageSID+" --storage-id \"\"", false, "lakectl_repo_create", vars)

Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better to separate this into a different test.
Also, missing the failure scenario when running it with storage_id != ""

@itaigilo itaigilo requested a review from N-o-Z February 6, 2025 17:11
@itaigilo
Copy link
Contributor Author

itaigilo commented Feb 7, 2025

@N-o-Z fixed -
Can you PTAL again?

# Conflicts:
#	cmd/lakectl/cmd/repo_create.go
#	docs/reference/cli.md
Copy link
Contributor

@nadavsteindler nadavsteindler left a comment

Choose a reason for hiding this comment

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

Looks good- added a few comments


defaultBranch, err := cmd.Flags().GetString(defaultBranchFlagName)
if err != nil {
DieErr(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the difference between the Must and this error handling? What is the reason for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's some merges mixed up.
Updating.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Following a talk with @N-o-Z -
Changed it to Must. Same effect, also for optional params.

DieErr(err)
}
sampleData := Must(cmd.Flags().GetBool(sampleDataFlagName))
storageID, _ := cmd.Flags().GetString(storageIDFlagName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why ignore the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since it's an optional param.

Copy link
Contributor

Choose a reason for hiding this comment

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

There are other possible errors than "flag accessed but not defined"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks.
Added error handling for this (obviously, copied from other commands).

@@ -187,6 +188,13 @@ func withRecursiveFlag(cmd *cobra.Command, usage string) {
cmd.Flags().BoolP(recursiveFlagName, recursiveFlagShort, false, usage)
}

func withStorageID(cmd *cobra.Command) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Clean code- add a one line comment explaining what this does

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn't clean code about self-explained code?

And again, StorageID is not very documented in the OSS at the moment,
And this a part of it.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, hmm I find it takes me a while to read this function and understand what I'm looking at. Maybe a better function name rather than a comment? Maybe it should be addStorageID? withStorageID sounds like it's more of a query checking if the command has this flag than a command that does something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the convention for global flags in lakectl...
(See @N-o-Z 's comment on this PR.)

Copy link
Contributor Author

@itaigilo itaigilo left a comment

Choose a reason for hiding this comment

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

@nadavsteindler thanks.
Addressed - PTAL again.

DieErr(err)
}
sampleData := Must(cmd.Flags().GetBool(sampleDataFlagName))
storageID, _ := cmd.Flags().GetString(storageIDFlagName)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since it's an optional param.

@@ -187,6 +188,13 @@ func withRecursiveFlag(cmd *cobra.Command, usage string) {
cmd.Flags().BoolP(recursiveFlagName, recursiveFlagShort, false, usage)
}

func withStorageID(cmd *cobra.Command) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn't clean code about self-explained code?

And again, StorageID is not very documented in the OSS at the moment,
And this a part of it.


defaultBranch, err := cmd.Flags().GetString(defaultBranchFlagName)
if err != nil {
DieErr(err)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's some merges mixed up.
Updating.

Copy link
Member

@N-o-Z N-o-Z left a comment

Choose a reason for hiding this comment

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

Thanks!
Approved with 2 comments that need to be addressed


defaultBranch := Must(cmd.Flags().GetString(defaultBranchFlagName))
sampleData := Must(cmd.Flags().GetBool(sampleDataFlagName))
storageID, err := cmd.Flags().GetString(storageIDFlagName)
Copy link
Member

Choose a reason for hiding this comment

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

Should also be under a Must

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn't the --storage flag optional for the OSS?

}

defaultBranch := Must(cmd.Flags().GetString(defaultBranchFlagName))
storageID, _ := cmd.Flags().GetString(storageIDFlagName)
Copy link
Member

Choose a reason for hiding this comment

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

Must

@itaigilo itaigilo enabled auto-merge (squash) February 10, 2025 17:46
@itaigilo itaigilo merged commit 502432d into master Feb 10, 2025
38 checks passed
@itaigilo itaigilo deleted the feature/add-storage-id-to-cli branch February 10, 2025 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exclude-changelog PR description should not be included in next release changelog minor-change Used for PRs that don't require issue attached msb
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add --storage-id flag to repo create CLI
3 participants