@@ -62,7 +62,8 @@ def simulate_appset_generation(appset_file):
6262 result = subprocess .run (cmd , capture_output = True , text = True )
6363
6464 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 ))
6667 else :
6768 print (f"Error using argocd CLI: { result .stderr } " )
6869
@@ -131,6 +132,13 @@ def validate_applications(apps, validation_rules=None):
131132 print ("No applications to validate" )
132133 return False
133134
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+
134142 print (f"Found { len (apps )} generated applications" )
135143 valid = True
136144
@@ -222,6 +230,13 @@ def export_applications(apps, output_dir):
222230 if not os .path .exists (output_dir ):
223231 os .makedirs (output_dir )
224232
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+
225240 for i , app in enumerate (apps ):
226241 name = app .get ("metadata" , {}).get ("name" , f"app-{ i + 1 } " )
227242 output_file = os .path .join (output_dir , f"{ name } .yaml" )
@@ -274,54 +289,14 @@ def validate_plain_appset_sources(apps):
274289 valid = False
275290
276291 # Check that the path is a directory in the repository
292+ # For testing environment, we accept paths starting with testing/ instead of clusters/
277293 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/ " )
280296 valid = False
281297
282298 return valid
283299
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-
325300def main ():
326301 parser = argparse .ArgumentParser (description = "Test ArgoCD ApplicationSet generator combinations and templates" )
327302
@@ -397,7 +372,6 @@ def main():
397372 validation_rules = {}
398373 if appset_name == "plain" :
399374 validation_rules ["plain_appset_sources" ] = validate_plain_appset_sources
400- validation_rules ["projects_app" ] = validate_projects_app
401375
402376 valid = validate_applications (apps , validation_rules )
403377
0 commit comments