Skip to content

Commit

Permalink
feat: add the ability to filter apps based on clusters (#10465)
Browse files Browse the repository at this point in the history
Signed-off-by: xin.li <xin.li@daocloud.io>

Signed-off-by: xin.li <xin.li@daocloud.io>
  • Loading branch information
my-git9 committed Oct 1, 2022
1 parent 2c3bc81 commit fa26801
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,7 @@ func NewApplicationListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
projects []string
repo string
appNamespace string
cluster string
)
var command = &cobra.Command{
Use: "list",
Expand Down Expand Up @@ -1285,7 +1286,9 @@ func NewApplicationListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
if repo != "" {
appList = argo.FilterByRepo(appList, repo)
}

if cluster != "" {
appList = argo.FilterByCluster(appList, cluster)
}
var appsWithDeprecatedPlugins []string
for _, app := range appList {
if app.Spec.Source.Plugin != nil && app.Spec.Source.Plugin.Name != "" {
Expand Down Expand Up @@ -1316,6 +1319,7 @@ func NewApplicationListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
command.Flags().StringArrayVarP(&projects, "project", "p", []string{}, "Filter by project name")
command.Flags().StringVarP(&repo, "repo", "r", "", "List apps by source repo URL")
command.Flags().StringVarP(&appNamespace, "app-namespace", "N", "", "Only list applications in namespace")
command.Flags().StringVarP(&cluster, "cluster", "c", "", "List apps by cluster name or url")
return command
}

Expand Down
1 change: 1 addition & 0 deletions docs/user-guide/commands/argocd_app_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ argocd app list [flags]

```
-N, --app-namespace string Only list applications in namespace
-c, --cluster string List apps by cluster name or url
-h, --help help for list
-o, --output string Output format. One of: wide|name|json|yaml (default "wide")
-p, --project stringArray Filter by project name
Expand Down
14 changes: 14 additions & 0 deletions util/argo/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ func FilterByRepo(apps []argoappv1.Application, repo string) []argoappv1.Applica
return items
}

// FilterByCluster returns an application
func FilterByCluster(apps []argoappv1.Application, cluster string) []argoappv1.Application {
if cluster == "" {
return apps
}
items := make([]argoappv1.Application, 0)
for i := 0; i < len(apps); i++ {
if apps[i].Spec.Destination.Server == cluster || apps[i].Spec.Destination.Name == cluster {
items = append(items, apps[i])
}
}
return items
}

// FilterByName returns an application
func FilterByName(apps []argoappv1.Application, name string) ([]argoappv1.Application, error) {
if name == "" {
Expand Down

0 comments on commit fa26801

Please sign in to comment.