Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions internal/flink/command_detached_savepoint_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,19 @@ func (c *command) detachedSavepointCreate(cmd *cobra.Command, args []string) err
return err
}

table := output.NewTable(cmd)
table.Add(&detachedSavepointOut{
Name: detachedSavepoint.Metadata.GetName(),
Path: detachedSavepoint.Spec.GetPath(),
Format: detachedSavepoint.Spec.GetFormatType(),
BackoffLimit: detachedSavepoint.Spec.GetBackoffLimit(),
CreationTimestamp: detachedSavepoint.Metadata.GetCreationTimestamp(),
Uid: detachedSavepoint.Metadata.GetUid(),
})
return table.Print()
if output.GetFormat(cmd) == output.Human {
table := output.NewTable(cmd)
table.Add(&detachedSavepointOut{
Name: detachedSavepoint.Metadata.GetName(),
Path: detachedSavepoint.Spec.GetPath(),
Format: detachedSavepoint.Spec.GetFormatType(),
BackoffLimit: detachedSavepoint.Spec.GetBackoffLimit(),
CreationTimestamp: detachedSavepoint.Metadata.GetCreationTimestamp(),
Uid: detachedSavepoint.Metadata.GetUid(),
})
return table.Print()
}

localDetachedSavepoint := convertSdkDetachedSavepointToLocalSavepoint(detachedSavepoint)
return output.SerializedOutput(cmd, localDetachedSavepoint)
}
29 changes: 17 additions & 12 deletions internal/flink/command_savepoint_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
return cmd
}

func (c *command) savepointCreate(cmd *cobra.Command, args []string) error {

Check failure on line 43 in internal/flink/command_savepoint_create.go

View check run for this annotation

SonarQube-Confluent / SonarQube Code Analysis

Refactor this method to reduce its Cognitive Complexity from 17 to the 15 allowed.

[S3776] Cognitive Complexity of functions should not be too high See more on https://sonarqube.confluent.io/project/issues?id=cli&pullRequest=3396&issues=6e42fcf1-d953-4622-947e-f167906a6e29&open=6e42fcf1-d953-4622-947e-f167906a6e29
name := ""
if len(args) == 1 {
name = args[0]
Expand Down Expand Up @@ -113,16 +113,21 @@
}
}

table := output.NewTable(cmd)
table.Add(&savepointOut{
Name: savepointCreated.Metadata.GetName(),
Statement: statement,
Application: application,
Path: savepointCreated.Spec.GetPath(),
Format: savepointCreated.Spec.GetFormatType(),
BackoffLimit: savepointCreated.Spec.GetBackoffLimit(),
Uid: savepointCreated.Metadata.GetUid(),
State: savepointCreated.Status.GetState(),
})
return table.Print()
if output.GetFormat(cmd) == output.Human {
table := output.NewTable(cmd)
table.Add(&savepointOut{
Name: savepointCreated.Metadata.GetName(),
Statement: statement,
Application: application,
Path: savepointCreated.Spec.GetPath(),
Format: savepointCreated.Spec.GetFormatType(),
BackoffLimit: savepointCreated.Spec.GetBackoffLimit(),
Uid: savepointCreated.Metadata.GetUid(),
State: savepointCreated.Status.GetState(),
})
return table.Print()
}

localSavepoint := convertSdkSavepointToLocalSavepoint(savepointCreated)
return output.SerializedOutput(cmd, localSavepoint)
Comment on lines +131 to +132

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you please check if the nil check can be handled elegantly using the SDK in some way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is handled by the SDK's own getter. Both converters now use sdkSavepoint.Metadata.GetName(), and GetName() is nil-safe

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"apiVersion": "cmf.confluent.io/v1",
"kind": "Savepoint",
"metadata": {
"name": "savepoint1",
"creationTimestamp": "2025-03-12 23:42:00 +0000 UTC",
"uid": "id1"
},
"spec": {
"path": "abc/def",
"backoffLimit": 10,
"formatType": "Canonical"
},
"status": {
"path": "abc/def"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: cmf.confluent.io/v1
kind: Savepoint
metadata:
name: savepoint1
creationTimestamp: 2025-03-12 23:42:00 +0000 UTC
uid: id1
spec:
path: abc/def
backoffLimit: 10
formatType: Canonical
status:
path: abc/def
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"apiVersion": "cmf.confluent.io/v1",
"kind": "Savepoint",
"metadata": {
"name": "savepoint1",
"creationTimestamp": "2025-03-12 23:42:00 +0000 UTC"
},
"spec": {
"backoffLimit": 0,
"formatType": "CANONICAL"
},
"status": {
"path": ""
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: cmf.confluent.io/v1
kind: Savepoint
metadata:
name: savepoint1
creationTimestamp: 2025-03-12 23:42:00 +0000 UTC
spec:
backoffLimit: 0
formatType: CANONICAL
status:
path: ""
4 changes: 4 additions & 0 deletions test/flink_onprem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ func (s *CLITestSuite) TestFlinkEnvironmentDelete() {
func (s *CLITestSuite) TestFlinkSavepointCreate() {
tests := []CLITest{
{args: "flink savepoint create savepoint1 --environment default --application application1", fixture: "flink/savepoint/create-savepoint.golden"},
{args: "flink savepoint create savepoint1 --environment default --application application1 --output json", fixture: "flink/savepoint/create-savepoint-json.golden"},
{args: "flink savepoint create savepoint1 --environment default --application application1 --output yaml", fixture: "flink/savepoint/create-savepoint-yaml.golden"},
{args: "flink savepoint create --environment default --application application2", fixture: "flink/savepoint/create-savepoint-no-name.golden"},
{args: "flink savepoint create savepointS --environment default --statement test-stmt", fixture: "flink/savepoint/create-savepoint-statement.golden"},
{args: "flink savepoint create savepointS --environment default --statement test-stmt --path abc/def --format NATIVE --backoff-limit 10", fixture: "flink/savepoint/create-savepoint-statement-values.golden"},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you check if making additional --output yaml makes sense here?

Expand Down Expand Up @@ -184,6 +186,8 @@ func (s *CLITestSuite) TestFlinkSavepointDelete() {
func (s *CLITestSuite) TestFlinkDetachedSavepointCreate() {
tests := []CLITest{
{args: "flink detached-savepoint create savepoint1 --path abc/def", fixture: "flink/detached-savepoint/create-savepoint.golden"},
{args: "flink detached-savepoint create savepoint1 --path abc/def --output json", fixture: "flink/detached-savepoint/create-savepoint-json.golden"},
{args: "flink detached-savepoint create savepoint1 --path abc/def --output yaml", fixture: "flink/detached-savepoint/create-savepoint-yaml.golden"},
{args: "flink detached-savepoint create savepoint1", fixture: "flink/detached-savepoint/create-savepoint-nopath.golden", exitCode: 1},
}

Expand Down