@@ -62,7 +62,8 @@ def simulate_appset_generation(appset_file):
62
62
result = subprocess .run (cmd , capture_output = True , text = True )
63
63
64
64
if result .returncode == 0 :
65
- return list (yaml .safe_load_all (result .stdout ))[0 ]
65
+ # Return all applications, not just the first one
66
+ return list (yaml .safe_load_all (result .stdout ))
66
67
else :
67
68
print (f"Error using argocd CLI: { result .stderr } " )
68
69
@@ -131,6 +132,13 @@ def validate_applications(apps, validation_rules=None):
131
132
print ("No applications to validate" )
132
133
return False
133
134
135
+ # Filter out None values
136
+ apps = [app for app in apps if app is not None ]
137
+
138
+ if not apps :
139
+ print ("No valid applications to validate after filtering None values" )
140
+ return False
141
+
134
142
print (f"Found { len (apps )} generated applications" )
135
143
valid = True
136
144
@@ -222,6 +230,13 @@ def export_applications(apps, output_dir):
222
230
if not os .path .exists (output_dir ):
223
231
os .makedirs (output_dir )
224
232
233
+ # Filter out None values
234
+ apps = [app for app in apps if app is not None ]
235
+
236
+ if not apps :
237
+ print ("No valid applications to export" )
238
+ return
239
+
225
240
for i , app in enumerate (apps ):
226
241
name = app .get ("metadata" , {}).get ("name" , f"app-{ i + 1 } " )
227
242
output_file = os .path .join (output_dir , f"{ name } .yaml" )
@@ -274,54 +289,14 @@ def validate_plain_appset_sources(apps):
274
289
valid = False
275
290
276
291
# Check that the path is a directory in the repository
292
+ # For testing environment, we accept paths starting with testing/ instead of clusters/
277
293
path = source .get ("path" , "" )
278
- if not path .startswith ("clusters/" ):
279
- print (f" ERROR: Application { app .get ('metadata' , {}).get ('name' )} source path is { path } , expected to start with clusters/" )
294
+ if not ( path .startswith ("clusters/" ) or path . startswith ( "testing/" ) ):
295
+ print (f" ERROR: Application { app .get ('metadata' , {}).get ('name' )} source path is { path } , expected to start with clusters/ or testing/ " )
280
296
valid = False
281
297
282
298
return valid
283
299
284
- def validate_projects_app (apps ):
285
- """Validate that the 'projects' application has the correct source configuration"""
286
- valid = True
287
-
288
- # Find the projects application
289
- projects_app = None
290
- for app in apps :
291
- if app .get ("metadata" , {}).get ("name" ) == "in-cluster-projects" :
292
- projects_app = app
293
- break
294
-
295
- if not projects_app :
296
- print (" ERROR: Could not find application named 'in-cluster-projects'" )
297
- return False
298
-
299
- # Check for sources
300
- sources = projects_app .get ("spec" , {}).get ("sources" , [])
301
- if not sources :
302
- print (" ERROR: 'in-cluster-projects' application missing sources" )
303
- return False
304
-
305
- # Check that there is exactly one source
306
- if len (sources ) != 1 :
307
- print (f" ERROR: 'in-cluster-projects' application has { len (sources )} sources, expected 1" )
308
- return False
309
-
310
- # Check that the source points to the repository
311
- source = sources [0 ]
312
- if source .get ("repoURL" ) != "https://github.com/max06/deployments" :
313
- print (f" ERROR: 'in-cluster-projects' application source repoURL is { source .get ('repoURL' )} , expected https://github.com/max06/deployments" )
314
- valid = False
315
-
316
- # Check that the path is the correct directory in the repository
317
- path = source .get ("path" , "" )
318
- expected_path = "clusters/in-cluster/apps/projects"
319
- if path != expected_path :
320
- print (f" ERROR: 'in-cluster-projects' application source path is { path } , expected { expected_path } " )
321
- valid = False
322
-
323
- return valid
324
-
325
300
def main ():
326
301
parser = argparse .ArgumentParser (description = "Test ArgoCD ApplicationSet generator combinations and templates" )
327
302
@@ -397,7 +372,6 @@ def main():
397
372
validation_rules = {}
398
373
if appset_name == "plain" :
399
374
validation_rules ["plain_appset_sources" ] = validate_plain_appset_sources
400
- validation_rules ["projects_app" ] = validate_projects_app
401
375
402
376
valid = validate_applications (apps , validation_rules )
403
377
0 commit comments