From d011b7b7f7ed3e2441dcdf56ab685c59884ddad4 Mon Sep 17 00:00:00 2001 From: nitishfy Date: Thu, 21 Nov 2024 23:46:37 +0530 Subject: [PATCH] fix: show multisource details for an appset Signed-off-by: nitishfy --- cmd/argocd/commands/applicationset.go | 24 ++++++++-- cmd/argocd/commands/applicationset_test.go | 51 ++++++++++++++++++++++ 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/cmd/argocd/commands/applicationset.go b/cmd/argocd/commands/applicationset.go index 9d8a71e0b12125..c6e6546d589171 100644 --- a/cmd/argocd/commands/applicationset.go +++ b/cmd/argocd/commands/applicationset.go @@ -93,7 +93,6 @@ func NewApplicationSetGetCommand(clientOpts *argocdclient.ClientOptions) *cobra. errors.CheckError(err) case "wide", "": printAppSetSummaryTable(appSet) - if len(appSet.Status.Conditions) > 0 { fmt.Println() w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0) @@ -325,6 +324,24 @@ func NewApplicationSetListCommand(clientOpts *argocdclient.ClientOptions) *cobra return command } +// NewApplicationSetSetCommand returns a new instance of an `argocd appset set` command +//func NewApplicationSetSetCommand(clientOpts *argocdclient.Client) *cobra.Command { +// command := &cobra.Command{ +// Use: "set", +// Short: "Set ApplicationSets Parameters", +// Example: templates.Examples(""), +// Run: func(c *cobra.Command, args []string) { +// ctx := c.Context() +// +// if len(args) != 1 { +// c.HelpFunc()(c, args) +// os.Exit(1) +// } +// +// }, +// } +//} + // NewApplicationSetDeleteCommand returns a new instance of an `argocd appset delete` command func NewApplicationSetDeleteCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command { var noPrompt bool @@ -435,7 +452,6 @@ func getServerForAppSet(appSet *arogappsetv1.ApplicationSet) string { } func printAppSetSummaryTable(appSet *arogappsetv1.ApplicationSet) { - source := appSet.Spec.Template.Spec.GetSource() fmt.Printf(printOpFmtStr, "Name:", appSet.QualifiedName()) fmt.Printf(printOpFmtStr, "Project:", appSet.Spec.Template.Spec.GetProject()) fmt.Printf(printOpFmtStr, "Server:", getServerForAppSet(appSet)) @@ -445,7 +461,9 @@ func printAppSetSummaryTable(appSet *arogappsetv1.ApplicationSet) { } else { fmt.Println("Sources:") } - printAppSourceDetails(&source) + for _, source := range appSet.Spec.Template.Spec.GetSources() { + printAppSourceDetails(&source) + } var ( syncPolicyStr string diff --git a/cmd/argocd/commands/applicationset_test.go b/cmd/argocd/commands/applicationset_test.go index dd293ba57b415a..ecbc24bf1c8a80 100644 --- a/cmd/argocd/commands/applicationset_test.go +++ b/cmd/argocd/commands/applicationset_test.go @@ -145,6 +145,26 @@ func TestPrintAppSetSummaryTable(t *testing.T) { }, }, } + appsetSpecSource := baseAppSet.DeepCopy() + appsetSpecSource.Spec.Template.Spec.Source = &v1alpha1.ApplicationSource{ + RepoURL: "test1", + TargetRevision: "master1", + Path: "/test1", + } + + appsetSpecSources := baseAppSet.DeepCopy() + appsetSpecSources.Spec.Template.Spec.Sources = v1alpha1.ApplicationSources{ + { + RepoURL: "test1", + TargetRevision: "master1", + Path: "/test1", + }, + { + RepoURL: "test2", + TargetRevision: "master2", + Path: "/test2", + }, + } appsetSpecSyncPolicy := baseAppSet.DeepCopy() appsetSpecSyncPolicy.Spec.SyncPolicy = &v1alpha1.ApplicationSetSyncPolicy{ @@ -173,6 +193,37 @@ func TestPrintAppSetSummaryTable(t *testing.T) { appSet *v1alpha1.ApplicationSet expectedOutput string }{ + { + name: "appset with a single source", + appSet: appsetSpecSource, + expectedOutput: `Name: app-name +Project: default +Server: +Namespace: +Source: +- Repo: test1 + Target: master1 + Path: /test1 +SyncPolicy: +`, + }, + { + name: "appset with a multiple sources", + appSet: appsetSpecSources, + expectedOutput: `Name: app-name +Project: default +Server: +Namespace: +Sources: +- Repo: test1 + Target: master1 + Path: /test1 +- Repo: test2 + Target: master2 + Path: /test2 +SyncPolicy: +`, + }, { name: "appset with only spec.syncPolicy set", appSet: appsetSpecSyncPolicy,