@@ -45,6 +45,32 @@ func (w *worker) run(ctx context.Context) {
45
45
}
46
46
}
47
47
48
+ type pathAndRepoUrl struct {
49
+ Path , RepoURL , TargetRevision string
50
+ }
51
+
52
+ func getAppSources (app v1alpha1.Application ) []pathAndRepoUrl {
53
+ var items []pathAndRepoUrl
54
+
55
+ if src := app .Spec .Source ; src != nil {
56
+ items = append (items , pathAndRepoUrl {
57
+ Path : src .Path ,
58
+ RepoURL : src .RepoURL ,
59
+ TargetRevision : src .TargetRevision ,
60
+ })
61
+ }
62
+
63
+ for _ , src := range app .Spec .Sources {
64
+ items = append (items , pathAndRepoUrl {
65
+ Path : src .Path ,
66
+ RepoURL : src .RepoURL ,
67
+ TargetRevision : src .TargetRevision ,
68
+ })
69
+ }
70
+
71
+ return items
72
+ }
73
+
48
74
// processApp is a function that validates and processes a given application manifest against various checks,
49
75
// such as ArgoCD schema validation, diff generation, conftest policy validation, and pre-upgrade checks using kubepug.
50
76
// It takes a context (ctx), application name (app), directory (dir) as input and returns an error if any check fails.
@@ -54,27 +80,22 @@ func (w *worker) processApp(ctx context.Context, app v1alpha1.Application) {
54
80
var (
55
81
err error
56
82
57
- appName = app .Name
58
- appSrc = app .Spec .Source
59
- appPath = appSrc .Path
60
- appRepoUrl = appSrc .RepoURL
83
+ appName = app .Name
61
84
62
- logger = w .logger .With ().
63
- Str ("app_name" , appName ).
64
- Str ("app_path" , appPath ).
65
- Logger ()
85
+ rootLogger = w .logger .With ().
86
+ Str ("app_name" , appName ).
87
+ Logger ()
66
88
)
67
89
68
90
ctx , span := tracer .Start (ctx , "processApp" , trace .WithAttributes (
69
91
attribute .String ("app" , appName ),
70
- attribute .String ("dir" , appPath ),
71
92
))
72
93
defer span .End ()
73
94
74
95
atomic .AddInt32 (& inFlight , 1 )
75
96
defer atomic .AddInt32 (& inFlight , - 1 )
76
97
77
- logger .Info ().Msg ("Processing app" )
98
+ rootLogger .Info ().Msg ("Processing app" )
78
99
79
100
// Build a new section for this app in the parent comment
80
101
w .vcsNote .AddNewApp (ctx , appName )
@@ -94,47 +115,58 @@ func (w *worker) processApp(ctx context.Context, app v1alpha1.Application) {
94
115
}
95
116
}()
96
117
97
- repo , err := w .getRepo (ctx , w .ctr .VcsClient , appRepoUrl , appSrc .TargetRevision )
98
- if err != nil {
99
- logger .Error ().Err (err ).Msg ("Unable to clone repository" )
100
- w .vcsNote .AddToAppMessage (ctx , appName , msg.Result {
101
- State : pkg .StateError ,
102
- Summary : "failed to clone repo" ,
103
- Details : fmt .Sprintf ("Clone URL: `%s`\n Target Revision: `%s`\n ```\n %s\n ```" , appRepoUrl , appSrc .TargetRevision , err .Error ()),
104
- })
105
- return
106
- }
107
- repoPath := repo .Directory
118
+ var jsonManifests []string
119
+ sources := getAppSources (app )
120
+ for _ , appSrc := range sources {
121
+ var (
122
+ appPath = appSrc .Path
123
+ appRepoUrl = appSrc .RepoURL
124
+ logger = rootLogger .With ().
125
+ Str ("app_path" , appPath ).
126
+ Logger ()
127
+ )
128
+
129
+ repo , err := w .getRepo (ctx , w .ctr .VcsClient , appRepoUrl , appSrc .TargetRevision )
130
+ if err != nil {
131
+ logger .Error ().Err (err ).Msg ("Unable to clone repository" )
132
+ w .vcsNote .AddToAppMessage (ctx , appName , msg.Result {
133
+ State : pkg .StateError ,
134
+ Summary : "failed to clone repo" ,
135
+ Details : fmt .Sprintf ("Clone URL: `%s`\n Target Revision: `%s`\n ```\n %s\n ```" , appRepoUrl , appSrc .TargetRevision , err .Error ()),
136
+ })
137
+ return
138
+ }
139
+ repoPath := repo .Directory
140
+
141
+ logger .Debug ().Str ("repo_path" , repoPath ).Msg ("Getting manifests" )
142
+ someJsonManifests , err := w .ctr .ArgoClient .GetManifestsLocal (ctx , appName , repoPath , appPath , app )
143
+ if err != nil {
144
+ logger .Error ().Err (err ).Msg ("Unable to get manifests" )
145
+ w .vcsNote .AddToAppMessage (ctx , appName , msg.Result {
146
+ State : pkg .StateError ,
147
+ Summary : "Unable to get manifests" ,
148
+ Details : fmt .Sprintf ("```\n %s\n ```" , cleanupGetManifestsError (err , repo .Directory )),
149
+ })
150
+ return
151
+ }
108
152
109
- logger .Debug ().Str ("repo_path" , repoPath ).Msg ("Getting manifests" )
110
- jsonManifests , err := w .ctr .ArgoClient .GetManifestsLocal (ctx , appName , repoPath , appPath , app )
111
- if err != nil {
112
- logger .Error ().Err (err ).Msg ("Unable to get manifests" )
113
- w .vcsNote .AddToAppMessage (ctx , appName , msg.Result {
114
- State : pkg .StateError ,
115
- Summary : "Unable to get manifests" ,
116
- Details : fmt .Sprintf ("```\n %s\n ```" , cleanupGetManifestsError (err , repo .Directory )),
117
- })
118
- return
153
+ jsonManifests = append (jsonManifests , someJsonManifests ... )
119
154
}
120
155
121
156
// Argo diff logic wants unformatted manifests but everything else wants them as YAML, so we prepare both
122
157
yamlManifests := argo_client .ConvertJsonToYamlManifests (jsonManifests )
123
- logger .Trace ().Msgf ("Manifests:\n %+v\n " , yamlManifests )
158
+ rootLogger .Trace ().Msgf ("Manifests:\n %+v\n " , yamlManifests )
124
159
125
160
k8sVersion , err := w .ctr .ArgoClient .GetKubernetesVersionByApplication (ctx , app )
126
161
if err != nil {
127
- logger .Error ().Err (err ).Msg ("Error retrieving the Kubernetes version" )
162
+ rootLogger .Error ().Err (err ).Msg ("Error retrieving the Kubernetes version" )
128
163
k8sVersion = w .ctr .Config .FallbackK8sVersion
129
164
} else {
130
165
k8sVersion = fmt .Sprintf ("%s.0" , k8sVersion )
131
- logger .Info ().Msgf ("Kubernetes version: %s" , k8sVersion )
166
+ rootLogger .Info ().Msgf ("Kubernetes version: %s" , k8sVersion )
132
167
}
133
168
134
- runner := newRunner (
135
- w .ctr , app , repo , appName , k8sVersion , jsonManifests , yamlManifests , logger , w .vcsNote ,
136
- w .queueApp , w .removeApp ,
137
- )
169
+ runner := newRunner (w .ctr , app , appName , k8sVersion , jsonManifests , yamlManifests , rootLogger , w .vcsNote , w .queueApp , w .removeApp )
138
170
139
171
for _ , processor := range w .processors {
140
172
runner .Run (ctx , processor .Name , processor .Processor , processor .WorstState )
0 commit comments