@@ -167,58 +167,58 @@ func (ps *PoliciesSynthesizer) ConnectionsFromFolderPaths(dirPaths []string) ([]
167
167
168
168
func (ps * PoliciesSynthesizer ) extractConnectionsFromInfos (infos []* resource.Info ) (
169
169
[]* Resource , []* Connections , []FileProcessingError ) {
170
- resFinder := newResourceFinder (ps .logger , ps .stopOnError , ps .walkFn )
171
- fileErrors := []FileProcessingError {}
172
- for _ , info := range infos {
173
- err := resFinder .parseInfo (info )
174
- if err != nil {
175
- kind := "<unknown>"
176
- if info != nil && info .Object != nil {
177
- kind = info .Object .GetObjectKind ().GroupVersionKind ().Kind
178
- }
179
- fileErrors = appendAndLogNewError (fileErrors , failedScanningResource (kind , info .Source , err ), ps .logger )
180
- }
170
+ resAcc := newResourceAccumulator (ps .logger , ps .stopOnError )
171
+ parseErrors := resAcc .parseInfos (infos )
172
+ if stopProcessing (ps .stopOnError , parseErrors ) {
173
+ return nil , nil , parseErrors
181
174
}
182
175
183
- wls , conns , errs := ps .extractConnections (resFinder )
184
- fileErrors = append (fileErrors , errs ... )
185
- return wls , conns , fileErrors
176
+ wls , conns , errs := ps .extractConnections (resAcc )
177
+ errs = append (parseErrors , errs ... )
178
+ return wls , conns , errs
186
179
}
187
180
188
- // Scans the given directory for YAMLs with k8s resources and extracts required connections between workloads
181
+ // Scans the given directories for YAMLs with k8s resources and extracts required connections between workloads
189
182
func (ps * PoliciesSynthesizer ) extractConnectionsFromFolderPaths (dirPaths []string ) (
190
183
[]* Resource , []* Connections , []FileProcessingError ) {
191
- resFinder := newResourceFinder (ps .logger , ps .stopOnError , ps .walkFn )
192
- fileErrors := []FileProcessingError {}
193
- for _ , dirPath := range dirPaths {
194
- errs := resFinder .getRelevantK8sResources (dirPath )
195
- fileErrors = append (fileErrors , errs ... )
196
- if stopProcessing (ps .stopOnError , errs ) {
197
- return nil , nil , fileErrors
198
- }
184
+ // Find all manifest YAML files
185
+ mf := manifestFinder {ps .logger , ps .stopOnError , ps .walkFn }
186
+ manifestFiles , fileErrors := mf .searchForManifestsInDirs (dirPaths )
187
+ if stopProcessing (ps .stopOnError , fileErrors ) {
188
+ return nil , nil , fileErrors
199
189
}
200
- wls , conns , errs := ps .extractConnections (resFinder )
190
+
191
+ // Parse YAMLs and extract relevant resources
192
+ resAcc := newResourceAccumulator (ps .logger , ps .stopOnError )
193
+ parseErrors := resAcc .parseK8sYamls (manifestFiles )
194
+ fileErrors = append (fileErrors , parseErrors ... )
195
+ if stopProcessing (ps .stopOnError , fileErrors ) {
196
+ return nil , nil , fileErrors
197
+ }
198
+
199
+ // discover connections from the set of resources
200
+ wls , conns , errs := ps .extractConnections (resAcc )
201
201
fileErrors = append (fileErrors , errs ... )
202
202
return wls , conns , fileErrors
203
203
}
204
204
205
- func (ps * PoliciesSynthesizer ) extractConnections (resFinder * resourceFinder ) (
205
+ func (ps * PoliciesSynthesizer ) extractConnections (resAcc * resourceAccumulator ) (
206
206
[]* Resource , []* Connections , []FileProcessingError ) {
207
- if len (resFinder .workloads ) == 0 {
207
+ if len (resAcc .workloads ) == 0 {
208
208
return nil , nil , appendAndLogNewError (nil , noK8sResourcesFound (), ps .logger )
209
209
}
210
210
211
211
// Inline configmaps values as workload envs
212
- fileErrors := resFinder .inlineConfigMapRefsAsEnvs ()
212
+ fileErrors := resAcc .inlineConfigMapRefsAsEnvs ()
213
213
if stopProcessing (ps .stopOnError , fileErrors ) {
214
214
return nil , nil , fileErrors
215
215
}
216
216
217
- resFinder .exposeServices ()
217
+ resAcc .exposeServices ()
218
218
219
219
// Discover all connections between resources
220
- connections := discoverConnections (resFinder .workloads , resFinder .services , ps .logger )
221
- return resFinder .workloads , connections , fileErrors
220
+ connections := discoverConnections (resAcc .workloads , resAcc .services , ps .logger )
221
+ return resAcc .workloads , connections , fileErrors
222
222
}
223
223
224
224
func hasFatalError (errs []FileProcessingError ) error {
0 commit comments