@@ -1162,14 +1162,30 @@ func syncApplication(client argoclient.Interface, app *argoapi.Application, with
11621162
11631163// returns the child applications owned by the app-of-apps parentApp
11641164func getChildApplications (client argoclient.Interface , parentApp * argoapi.Application ) ([]argoapi.Application , error ) {
1165- listOptions := metav1.ListOptions {
1166- LabelSelector : fmt .Sprintf ("app.kubernetes.io/instance=%s" , parentApp .Name ),
1167- }
1168-
1169- appList , err := client .ArgoprojV1alpha1 ().Applications ("" ).List (context .Background (), listOptions )
1165+ appList , err := client .ArgoprojV1alpha1 ().
1166+ Applications ("" ).
1167+ List (context .Background (), metav1.ListOptions {})
11701168 if err != nil {
11711169 return nil , fmt .Errorf ("failed to list child applications of %s: %w" , parentApp .Name , err )
11721170 }
11731171
1174- return appList .Items , nil
1172+ var result []argoapi.Application
1173+
1174+ // Build expected tracking prefix
1175+ // Example:
1176+ // multicloud-gitops-hub:argoproj.io/Application:multicloud-gitops-hub/
1177+ expectedPrefix := fmt .Sprintf (
1178+ "%s:argoproj.io/Application:%s/" ,
1179+ parentApp .Name ,
1180+ parentApp .Namespace ,
1181+ )
1182+
1183+ for _ , app := range appList .Items { //nolint:gocritic // rangeValCopy: each iteration copies 992 bytes
1184+ if trackingID , ok := app .Annotations ["argocd.argoproj.io/tracking-id" ]; ok {
1185+ if strings .HasPrefix (trackingID , expectedPrefix ) {
1186+ result = append (result , app )
1187+ }
1188+ }
1189+ }
1190+ return result , nil
11751191}
0 commit comments