Skip to content

Commit

Permalink
fix: show multisource details for an appset when using `argocd appset…
Browse files Browse the repository at this point in the history
… get` command (argoproj#20903)

* fix: show multisource details for an appset

Signed-off-by: nitishfy <[email protected]>

* remove extra comment

Signed-off-by: nitishfy <[email protected]>

* fix failing tests

Signed-off-by: nitishfy <[email protected]>

* fix lint issues

Signed-off-by: nitishfy <[email protected]>

---------

Signed-off-by: nitishfy <[email protected]>
  • Loading branch information
nitishfy authored Nov 22, 2024
1 parent 9f1431e commit 32cc663
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
14 changes: 11 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 @@ -435,7 +434,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 +443,17 @@ func printAppSetSummaryTable(appSet *arogappsetv1.ApplicationSet) {
} else {
fmt.Println("Sources:")
}
printAppSourceDetails(&source)

// if no source has been defined, print the default value for a source
if len(appSet.Spec.Template.Spec.GetSources()) == 0 {
src := appSet.Spec.Template.Spec.GetSource()
printAppSourceDetails(&src)
} else {
// otherwise range over the sources and print each source details
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 @@ -210,6 +230,37 @@ Source:
- Repo:
Target:
SyncPolicy: Automated
`,
},
{
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>
`,
},
} {
Expand Down

0 comments on commit 32cc663

Please sign in to comment.