-
Notifications
You must be signed in to change notification settings - Fork 29
CF-1871 : Add Catalog Update Command #3304
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package flink | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| ) | ||
|
|
||
| func (c *command) newCatalogUpdateCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "update <resourceFilePath>", | ||
| Short: "Update a Flink catalog in Confluent Platform.", | ||
| Long: "Update an existing Flink catalog in Confluent Platform from a resource file.", | ||
| Args: cobra.ExactArgs(1), | ||
| RunE: c.catalogUpdate, | ||
| } | ||
|
|
||
| addCmfFlagSet(cmd) | ||
| pcmd.AddOutputFlag(cmd) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func (c *command) catalogUpdate(cmd *cobra.Command, args []string) error { | ||
| resourceFilePath := args[0] | ||
|
|
||
| client, err := c.GetCmfClient(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| sdkCatalog, err := readCatalogResourceFile(resourceFilePath) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| catalogName := sdkCatalog.Metadata.Name | ||
| if catalogName == "" { | ||
| return fmt.Errorf("catalog name is required: ensure the resource file contains a non-empty \"metadata.name\" field") | ||
| } | ||
|
|
||
| if err := client.UpdateCatalog(c.createContext(), catalogName, sdkCatalog); err != nil { | ||
|
Contributor
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. Same comment as the catalog database, is it the design that Update command doesn't return the updated catalog to make this an atomic operation? I am seeing an additional describe call below.
Contributor
Author
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. Yes thats correct. UpdateKafkaCatalogExecute returns (*http.Response, error) only — no body. The follow-up DescribeCatalog is the only way to render the updated resource until CMF changes the PUT endpoint to return the catalog. As discussed, we will address this in a follow up PR. |
||
| return err | ||
| } | ||
|
|
||
| sdkOutputCatalog, err := client.DescribeCatalog(c.createContext(), catalogName) | ||
|
paras-negi-flink marked this conversation as resolved.
|
||
| if err != nil { | ||
| return fmt.Errorf("catalog %q was updated successfully, but failed to retrieve updated details: %w", catalogName, err) | ||
| } | ||
|
|
||
| return printCatalogOutput(cmd, sdkOutputCatalog) | ||
|
Contributor
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. Let's use this unified print out function for the
Contributor
Author
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. Done. catalogCreate now ends with return printCatalogOutput(cmd, sdkOutputCatalog) |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "apiVersion": "cmf/api/v1/catalog", | ||
| "kind": "KafkaCatalog", | ||
| "metadata": { | ||
| "name": "invalid-catalog" | ||
| }, | ||
| "spec": { | ||
| "kafkaClusters": [ | ||
| { | ||
| "databaseName": "dev" | ||
| }, | ||
| { | ||
| "databaseName": "prod" | ||
| } | ||
| ] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| apiVersion: cmf/api/v1/catalog | ||
| kind: KafkaCatalog | ||
| metadata: | ||
| name: invalid-catalog | ||
| spec: | ||
| kafkaClusters: | ||
| - databaseName: dev | ||
| - databaseName: prod |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "apiVersion": "cmf/api/v1/catalog", | ||
| "kind": "KafkaCatalog", | ||
| "metadata": { | ||
| "name": "test-catalog" | ||
| }, | ||
| "spec": { | ||
| "kafkaClusters": [ | ||
| { | ||
| "databaseName": "dev" | ||
| }, | ||
| { | ||
| "databaseName": "prod" | ||
| } | ||
| ] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| apiVersion: cmf/api/v1/catalog | ||
| kind: KafkaCatalog | ||
| metadata: | ||
| name: test-catalog | ||
| spec: | ||
| kafkaClusters: | ||
| - databaseName: dev | ||
| - databaseName: prod |
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.
printCatalogOutputcentralizes catalog rendering, butcatalogCreateandcatalogDescribestill contain their own (nearly identical) output formatting logic. To avoid future drift between commands, consider switching those commands to callprintCatalogOutputas well.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.
Robert Metzger (@rmetzger) Kumar Mallikarjuna (@kumar-mallikarjuna) does it make sense to touch other existing files to reduce duplication, or should we tackle that in another change ?
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.
I think it makes sense to fix this as part of this PR
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.
Agree with Copilot and Robert Metzger (@rmetzger) 's comment, maybe we can apply this idea to the catalog database as well.
Uh oh!
There was an error while loading. Please reload this page.
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.
Done — catalogCreate and catalogDescribe now both call printCatalogOutput.