-
Notifications
You must be signed in to change notification settings - Fork 30
[CF-4208] Add --name/--status filtering to on-prem application list
#3428
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
Open
Paras Negi (paras-negi-flink)
wants to merge
4
commits into
main
from
cli-cf-4208-application-filtering
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9c3e56c
[CF-4208] Add --page-size to on-prem Flink list commands
paras-negi-flink f873c37
[CF-4208] Clarify --page-size help, cover the upper bound, drop tauto…
paras-negi-flink aecd01c
[CF-4208] Address review: default --page-size to 100, drop client-sid…
paras-negi-flink a153efd
[CF-4208] Add --name/--status filtering to on-prem application list
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
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
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 |
|---|---|---|
|
|
@@ -2,13 +2,22 @@ | |
|
|
||
| import ( | ||
| "fmt" | ||
| "slices" | ||
| "strings" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| "github.com/confluentinc/cli/v4/pkg/output" | ||
| "github.com/confluentinc/cli/v4/pkg/utils" | ||
| ) | ||
|
|
||
| // allowedApplicationStatuses lists the Flink job states recognized by the CMF applications | ||
| // "state=" filter, per the cmf-sdk-go GetApplications filter documentation. Unknown values are | ||
| // still forwarded (the server returns no matches rather than erroring); this list only drives | ||
| // the advisory --status warning. | ||
| var allowedApplicationStatuses = []string{"RUNNING", "FINISHED", "FAILED", "CANCELED", "RECONCILING", "COMPLETED", "UNKNOWN"} | ||
|
|
||
| func (c *command) newApplicationListCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "list", | ||
|
|
@@ -18,6 +27,9 @@ | |
| } | ||
|
|
||
| cmd.Flags().String("environment", "", "Name of the Flink environment.") | ||
| cmd.Flags().String("name", "", `Filter the Flink applications by name. Supports wildcards, for example "my-app*".`) | ||
| cmd.Flags().String("status", "", "Filter the Flink applications by status.") | ||
|
Member
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. I think we should name this |
||
| addPageSizeFlag(cmd) | ||
| addCmfFlagSet(cmd) | ||
| pcmd.AddOutputFlag(cmd) | ||
|
|
||
|
|
@@ -26,18 +38,39 @@ | |
| return cmd | ||
| } | ||
|
|
||
| func (c *command) applicationList(cmd *cobra.Command, _ []string) error { | ||
|
Check failure on line 41 in internal/flink/command_application_list.go
|
||
| environment, err := cmd.Flags().GetString("environment") | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| name, err := cmd.Flags().GetString("name") | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| status, err := cmd.Flags().GetString("status") | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if status != "" { | ||
| status = strings.ToUpper(status) | ||
| if !slices.Contains(allowedApplicationStatuses, status) { | ||
| output.ErrPrintf(c.Config.EnableColor, "[WARN] Invalid status %q. Valid statuses are %s.\n", status, utils.ArrayToCommaDelimitedString(allowedApplicationStatuses, "and")) | ||
| } | ||
| } | ||
|
|
||
| pageSize, err := getPageSize(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| client, err := c.GetCmfClient(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| applications, err := client.ListApplications(c.createContext(), environment) | ||
| applications, err := client.ListApplications(c.createContext(), environment, buildApplicationFilter(name, status), pageSize) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -76,3 +109,19 @@ | |
|
|
||
| return output.SerializedOutput(cmd, localApps) | ||
| } | ||
|
|
||
| // buildApplicationFilter composes the CMF applications "filter" query from the user-facing | ||
| // --name and --status flags. The grammar (comma-separated "key=value" expressions, "name=" | ||
| // with an optional "*" suffix wildcard, and "state=" for status) follows the CMF applications | ||
| // list API. Values are not escaped: Kubernetes application names and Flink states cannot | ||
| // contain "," or "=", so no ambiguity arises. The caller normalizes and warns about status. | ||
| func buildApplicationFilter(name, status string) string { | ||
| filters := make([]string, 0, 2) | ||
| if name != "" { | ||
| filters = append(filters, fmt.Sprintf("name=%s", name)) | ||
| } | ||
| if status != "" { | ||
| filters = append(filters, fmt.Sprintf("state=%s", status)) | ||
| } | ||
| return strings.Join(filters, ",") | ||
| } | ||
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,28 @@ | ||
| package flink | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestBuildApplicationFilter(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| appn string | ||
| status string | ||
| want string | ||
| }{ | ||
| {name: "empty", appn: "", status: "", want: ""}, | ||
| {name: "name only", appn: "my-app", status: "", want: "name=my-app"}, | ||
| {name: "name wildcard", appn: "my-app*", status: "", want: "name=my-app*"}, | ||
| {name: "status only", appn: "", status: "RUNNING", want: "state=RUNNING"}, | ||
| {name: "name and status", appn: "a*", status: "RUNNING", want: "name=a*,state=RUNNING"}, | ||
| } | ||
|
|
||
| for _, test := range tests { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| require.Equal(t, test.want, buildApplicationFilter(test.appn, test.status)) | ||
| }) | ||
| } | ||
| } |
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
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
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
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
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.
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.
Just to confirm: are all of these statuses accepted filter arguments? The spec's description for filterParam implies that only
RUNNINGorFAILEDare valid; so the description may be out of date for the spec.