Skip to content

Commit

Permalink
fix: show multisource details for an appset
Browse files Browse the repository at this point in the history
Signed-off-by: nitishfy <[email protected]>
  • Loading branch information
nitishfy committed Nov 21, 2024
1 parent 3b81d3c commit d011b7b
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 3 deletions.
24 changes: 21 additions & 3 deletions cmd/argocd/commands/applicationset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down
51 changes: 51 additions & 0 deletions cmd/argocd/commands/applicationset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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: <none>
`,
},
{
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: <none>
`,
},
{
name: "appset with only spec.syncPolicy set",
appSet: appsetSpecSyncPolicy,
Expand Down

0 comments on commit d011b7b

Please sign in to comment.