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
5 changes: 5 additions & 0 deletions cmd/lakectl/cmd/repo_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@ var repoCreateCmd = &cobra.Command{
clt := getClient()
u := MustParseRepoURI("repository URI", args[0])
fmt.Println("Repository:", u)

defaultBranch, err := cmd.Flags().GetString("default-branch")
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.

}
storageID, _ := cmd.Flags().GetString("storage-id")

resp, err := clt.CreateRepositoryWithResponse(cmd.Context(),
&apigen.CreateRepositoryParams{},
apigen.CreateRepositoryJSONRequestBody{
Name: u.Repository,
StorageId: &storageID,
StorageNamespace: args[1],
DefaultBranch: &defaultBranch,
})
Expand All @@ -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", "", "")
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)


repoCmd.AddCommand(repoCreateCmd)
}
6 changes: 6 additions & 0 deletions cmd/lakectl/cmd/repo_create_bare.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,21 @@ var repoCreateBareCmd = &cobra.Command{
clt := getClient()
u := MustParseRepoURI("repository URI", args[0])
fmt.Println("Repository:", u)

defaultBranch, err := cmd.Flags().GetString("default-branch")
if err != nil {
DieErr(err)
}
storageID, _ := cmd.Flags().GetString("storage-id")

bareRepo := true

resp, err := clt.CreateRepositoryWithResponse(cmd.Context(), &apigen.CreateRepositoryParams{
Bare: &bareRepo,
}, apigen.CreateRepositoryJSONRequestBody{
DefaultBranch: &defaultBranch,
Name: u.Repository,
StorageId: &storageID,
StorageNamespace: args[1],
})
DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusCreated)
Expand All @@ -44,6 +49,7 @@ var repoCreateBareCmd = &cobra.Command{
//nolint:gochecknoinits
func init() {
repoCreateBareCmd.Flags().StringP("default-branch", "d", DefaultBranch, "the default branch name of this repository (will not be created)")
repoCreateBareCmd.Flags().String("storage-id", "", "")

repoCmd.AddCommand(repoCreateBareCmd)
}
2 changes: 2 additions & 0 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -2626,6 +2626,7 @@ lakectl repo create lakefs://my-repo s3://my-bucket
```
-d, --default-branch string the default branch of this repository (default "main")
-h, --help help for create
--storage-id string
```


Expand Down Expand Up @@ -2724,6 +2725,7 @@ lakectl create-bare lakefs://my-repo s3://my-bucket
```
-d, --default-branch string the default branch name of this repository (will not be created) (default "main")
-h, --help help for create-bare
--storage-id string
```


Expand Down
10 changes: 10 additions & 0 deletions esti/lakectl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ func TestLakectlBasicRepoActions(t *testing.T) {
newStorage := storage + "/new-storage/"
RunCmdAndVerifyFailureWithFile(t, Lakectl()+" repo create lakefs://"+repoName+" "+newStorage, false, "lakectl_repo_create_not_unique", vars)

// Validate the --storage-id flag (currently only allowed to be empty)
repoNameSID := generateUniqueRepositoryName()
storageSID := generateUniqueStorageNamespace(repoNameSID)
vars = map[string]string{
"REPO": repoNameSID,
"STORAGE": storageSID,
"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 != ""

// Fails due to the usage of repos for isolation - esti creates repos in parallel and
// the output of 'repo list' command cannot be well-defined
// RunCmdAndVerifySuccessWithFile(t, Lakectl()+" repo list", false, "lakectl_repo_list_1", vars)
Expand Down
Loading