-
Notifications
You must be signed in to change notification settings - Fork 29
CF-1870 : Manage SQL Catalog databases through CLI #3287
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0e30b78
Add flink catalog database create command
96a12c9
Add golden test files for flink catalog database command
33e3b89
Add integration tests and fix golden files for flink catalog database…
36c006d
Fix flink_onprem_handler.go
d86fb7e
Add flink catalog database list command
2c09071
Fix build
4e19e4f
Merge branch 'main' into CF-1870
paras-negi-flink f85825b
Fix ListDatabases()
paras-negi-flink 02dfaf2
Added Describe/GET database cli command
paras-negi-flink 3271eec
Fix the golden files
paras-negi-flink 8f3a1e1
Added the update database cli command
paras-negi-flink 25d8693
Add flink catalog database update command
paras-negi-flink c95ac55
Copilot suggested fixes
paras-negi-flink 021cf01
Add claude suggested fixes
paras-negi-flink 977c3c9
Fix the update method
paras-negi-flink 3086734
[CF-1870] Address Channing's review comments
paras-negi-flink d4f7d85
Merge remote-tracking branch 'origin/main' into CF-1870
paras-negi-flink 030c098
[CF-1870] Rename AlterEnvironments to DdlEnvironments
paras-negi-flink File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package flink | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| cmfsdk "github.com/confluentinc/cmf-sdk-go/v1" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| ) | ||
|
|
||
| type databaseOut struct { | ||
| CreationTime string `human:"Creation Time" serialized:"creation_time"` | ||
| Name string `human:"Name" serialized:"name"` | ||
| Catalog string `human:"Catalog" serialized:"catalog"` | ||
| } | ||
|
|
||
| func (c *command) newCatalogDatabaseCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "database", | ||
| Short: "Manage Flink databases in Confluent Platform.", | ||
| Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireCloudLogout}, | ||
| } | ||
|
|
||
|
paras-negi-flink marked this conversation as resolved.
|
||
| cmd.AddCommand(c.newCatalogDatabaseCreateCommand()) | ||
| cmd.AddCommand(c.newCatalogDatabaseListCommand()) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func convertSdkDatabaseToLocalDatabase(sdkDatabase cmfsdk.KafkaDatabase) LocalKafkaDatabase { | ||
| return LocalKafkaDatabase{ | ||
| ApiVersion: sdkDatabase.ApiVersion, | ||
| Kind: sdkDatabase.Kind, | ||
| Metadata: LocalDatabaseMetadata{ | ||
| Name: sdkDatabase.Metadata.Name, | ||
| CreationTimestamp: sdkDatabase.Metadata.CreationTimestamp, | ||
| UpdateTimestamp: sdkDatabase.Metadata.UpdateTimestamp, | ||
| Uid: sdkDatabase.Metadata.Uid, | ||
| Labels: sdkDatabase.Metadata.Labels, | ||
| Annotations: sdkDatabase.Metadata.Annotations, | ||
| }, | ||
| Spec: LocalKafkaDatabaseSpec{ | ||
| KafkaCluster: LocalKafkaDatabaseSpecKafkaCluster{ | ||
| ConnectionConfig: sdkDatabase.Spec.KafkaCluster.ConnectionConfig, | ||
| ConnectionSecretId: sdkDatabase.Spec.KafkaCluster.ConnectionSecretId, | ||
| }, | ||
| AlterEnvironments: sdkDatabase.Spec.AlterEnvironments, | ||
| }, | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package flink | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| "gopkg.in/yaml.v3" | ||
|
|
||
| cmfsdk "github.com/confluentinc/cmf-sdk-go/v1" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| "github.com/confluentinc/cli/v4/pkg/errors" | ||
| "github.com/confluentinc/cli/v4/pkg/output" | ||
| ) | ||
|
|
||
| func (c *command) newCatalogDatabaseCreateCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "create <resourceFilePath>", | ||
| Short: "Create a Flink database.", | ||
|
channingdong marked this conversation as resolved.
|
||
| Long: "Create a Flink database in a catalog in Confluent Platform.", | ||
| Args: cobra.ExactArgs(1), | ||
| RunE: c.catalogDatabaseCreate, | ||
| } | ||
|
|
||
| cmd.Flags().String("catalog", "", "Name of the catalog.") | ||
| cobra.CheckErr(cmd.MarkFlagRequired("catalog")) | ||
| addCmfFlagSet(cmd) | ||
| pcmd.AddOutputFlag(cmd) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func (c *command) catalogDatabaseCreate(cmd *cobra.Command, args []string) error { | ||
| resourceFilePath := args[0] | ||
|
|
||
| catalogName, err := cmd.Flags().GetString("catalog") | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| client, err := c.GetCmfClient(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| data, err := os.ReadFile(resourceFilePath) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to read file: %v", err) | ||
| } | ||
|
|
||
| var genericData map[string]interface{} | ||
| ext := filepath.Ext(resourceFilePath) | ||
| switch ext { | ||
| case ".json": | ||
| err = json.Unmarshal(data, &genericData) | ||
| case ".yaml", ".yml": | ||
| err = yaml.Unmarshal(data, &genericData) | ||
| default: | ||
| return errors.NewErrorWithSuggestions( | ||
| fmt.Sprintf("unsupported file format: %s", ext), | ||
| "Supported file formats are .json, .yaml, and .yml.", | ||
| ) | ||
| } | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| jsonBytes, err := json.Marshal(genericData) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to marshal intermediate data: %w", err) | ||
| } | ||
|
|
||
| var sdkDatabase cmfsdk.KafkaDatabase | ||
| if err = json.Unmarshal(jsonBytes, &sdkDatabase); err != nil { | ||
| return fmt.Errorf("failed to bind data to KafkaDatabase model: %w", err) | ||
| } | ||
|
paras-negi-flink marked this conversation as resolved.
Outdated
|
||
|
|
||
| sdkOutputDatabase, err := client.CreateDatabase(c.createContext(), catalogName, sdkDatabase) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if output.GetFormat(cmd) == output.Human { | ||
| table := output.NewTable(cmd) | ||
| var creationTime string | ||
| if sdkOutputDatabase.GetMetadata().CreationTimestamp != nil { | ||
| creationTime = *sdkOutputDatabase.GetMetadata().CreationTimestamp | ||
| } | ||
| table.Add(&databaseOut{ | ||
| CreationTime: creationTime, | ||
| Name: sdkOutputDatabase.GetMetadata().Name, | ||
| Catalog: catalogName, | ||
| }) | ||
| return table.Print() | ||
| } | ||
|
|
||
| localDatabase := convertSdkDatabaseToLocalDatabase(sdkOutputDatabase) | ||
| return output.SerializedOutput(cmd, localDatabase) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package flink | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| "github.com/confluentinc/cli/v4/pkg/output" | ||
| ) | ||
|
|
||
| func (c *command) newCatalogDatabaseListCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "list", | ||
| Short: "List Flink databases in a catalog in Confluent Platform.", | ||
| Args: cobra.NoArgs, | ||
| RunE: c.catalogDatabaseList, | ||
| } | ||
|
|
||
| cmd.Flags().String("catalog", "", "Name of the catalog.") | ||
| cobra.CheckErr(cmd.MarkFlagRequired("catalog")) | ||
| addCmfFlagSet(cmd) | ||
| pcmd.AddOutputFlag(cmd) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func (c *command) catalogDatabaseList(cmd *cobra.Command, _ []string) error { | ||
| catalogName, err := cmd.Flags().GetString("catalog") | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| client, err := c.GetCmfClient(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| sdkDatabases, err := client.ListDatabases(c.createContext(), catalogName) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if output.GetFormat(cmd) == output.Human { | ||
| list := output.NewList(cmd) | ||
| for _, db := range sdkDatabases { | ||
| var creationTime string | ||
| if db.GetMetadata().CreationTimestamp != nil { | ||
| creationTime = *db.GetMetadata().CreationTimestamp | ||
| } | ||
| list.Add(&databaseOut{ | ||
| CreationTime: creationTime, | ||
| Name: db.GetMetadata().Name, | ||
| Catalog: catalogName, | ||
| }) | ||
| } | ||
| return list.Print() | ||
| } | ||
|
|
||
| localDatabases := make([]LocalKafkaDatabase, 0, len(sdkDatabases)) | ||
| for _, sdkDatabase := range sdkDatabases { | ||
| localDatabases = append(localDatabases, convertSdkDatabaseToLocalDatabase(sdkDatabase)) | ||
| } | ||
|
|
||
| return output.SerializedOutput(cmd, localDatabases) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
test/fixtures/input/flink/catalog/database/create-invalid-failure.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "apiVersion": "cmf/api/v1/database", | ||
| "kind": "KafkaDatabase", | ||
| "metadata": { | ||
| "name": "invalid-database" | ||
| }, | ||
| "spec": { | ||
| "kafkaCluster": { | ||
| "connectionConfig": {} | ||
| } | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
test/fixtures/input/flink/catalog/database/create-successful.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "apiVersion": "cmf/api/v1/database", | ||
| "kind": "KafkaDatabase", | ||
| "metadata": { | ||
| "name": "test-database" | ||
| }, | ||
| "spec": { | ||
| "kafkaCluster": { | ||
| "connectionConfig": { | ||
| "bootstrap.servers": "localhost:9092" | ||
| } | ||
| } | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
test/fixtures/output/flink/catalog/database/create-help-onprem.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| Create a Flink database in a catalog in Confluent Platform. | ||
|
|
||
| Usage: | ||
| confluent flink catalog database create <resourceFilePath> [flags] | ||
|
|
||
| Flags: | ||
| --catalog string REQUIRED: Name of the catalog. | ||
| --url string Base URL of the Confluent Manager for Apache Flink (CMF). Environment variable "CONFLUENT_CMF_URL" may be set in place of this flag. | ||
| --client-key-path string Path to client private key for mTLS authentication. Environment variable "CONFLUENT_CMF_CLIENT_KEY_PATH" may be set in place of this flag. | ||
| --client-cert-path string Path to client cert to be verified by Confluent Manager for Apache Flink. Include for mTLS authentication. Environment variable "CONFLUENT_CMF_CLIENT_CERT_PATH" may be set in place of this flag. | ||
| --certificate-authority-path string Path to a PEM-encoded Certificate Authority to verify the Confluent Manager for Apache Flink connection. Environment variable "CONFLUENT_CMF_CERTIFICATE_AUTHORITY_PATH" may be set in place of this flag. | ||
| -o, --output string Specify the output format as "human", "json", or "yaml". (default "human") | ||
|
|
||
| Global Flags: | ||
| -h, --help Show help for this command. | ||
| --unsafe-trace Equivalent to -vvvv, but also log HTTP requests and responses which might contain plaintext secrets. | ||
| -v, --verbose count Increase verbosity (-v for warn, -vv for info, -vvv for debug, -vvvv for trace). |
1 change: 1 addition & 0 deletions
1
test/fixtures/output/flink/catalog/database/create-invalid-failure.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Error: failed to create database "invalid-database" in catalog "test-catalog": The Kafka database object from resource file is invalid |
15 changes: 15 additions & 0 deletions
15
test/fixtures/output/flink/catalog/database/create-success-json.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "apiVersion": "cmf/api/v1/database", | ||
| "kind": "KafkaDatabase", | ||
| "metadata": { | ||
| "name": "test-database", | ||
| "creationTimestamp": "2025-03-12 23:42:00 +0000 UTC" | ||
| }, | ||
| "spec": { | ||
| "kafkaCluster": { | ||
| "connectionConfig": { | ||
| "bootstrap.servers": "localhost:9092" | ||
| } | ||
| } | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
test/fixtures/output/flink/catalog/database/create-success-yaml.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| apiVersion: cmf/api/v1/database | ||
| kind: KafkaDatabase | ||
| metadata: | ||
| name: test-database | ||
| creationTimestamp: 2025-03-12 23:42:00 +0000 UTC | ||
| spec: | ||
| kafkaCluster: | ||
| connectionConfig: | ||
| bootstrap.servers: localhost:9092 |
5 changes: 5 additions & 0 deletions
5
test/fixtures/output/flink/catalog/database/create-success.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| +---------------+-------------------------------+ | ||
| | Creation Time | 2025-03-12 23:42:00 +0000 UTC | | ||
| | Name | test-database | | ||
| | Catalog | test-catalog | | ||
| +---------------+-------------------------------+ |
15 changes: 15 additions & 0 deletions
15
test/fixtures/output/flink/catalog/database/help-onprem.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| Manage Flink databases in Confluent Platform. | ||
|
|
||
| Usage: | ||
| confluent flink catalog database [command] | ||
|
|
||
| Available Commands: | ||
| create Create a Flink database. | ||
| list List Flink databases in a catalog in Confluent Platform. | ||
|
|
||
| Global Flags: | ||
| -h, --help Show help for this command. | ||
| --unsafe-trace Equivalent to -vvvv, but also log HTTP requests and responses which might contain plaintext secrets. | ||
| -v, --verbose count Increase verbosity (-v for warn, -vv for info, -vvv for debug, -vvvv for trace). | ||
|
|
||
| Use "confluent flink catalog database [command] --help" for more information about a command. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.