// requestsForSecretChange returns a reconcile request when a Secret changes
requestsForSecretChange returns a reconcile request when a Secret changes
// requestsForSecretChange returns a reconcile request when a Secret changes
func (r *ProgressiveSyncReconciler) requestsForSecretChange(o client.Object) []reconcile.Request {
	var requests []reconcile.Request
	var prList syncv1alpha1.ProgressiveSyncList
	var appList argov1alpha1.ApplicationList
	requestsMap := make(map[types.NamespacedName]bool)
	ctx := context.Background()
	s, ok := o.(*corev1.Secret)
	if !ok {
		err := fmt.Errorf("expected secret, got %T", o)
		r.Log.Error(err, "failed to convert object to secret")
		return nil
	}
	r.Log.Info("received secret event", "name", s.Name, "Namespace", s.Namespace)
	if !utils.IsArgoCDCluster(s.GetLabels()) {
		return nil
	}
	if err := r.List(ctx, &prList); err != nil {
		r.Log.Error(err, "failed to list ProgressiveSync")
		return nil
	}
	if err := r.List(ctx, &appList); err != nil {
		r.Log.Error(err, "failed to list Application")
		return nil
	}
	for _, pr := range prList.Items {
		for _, app := range appList.Items {
			if app.Spec.Destination.Server == string(s.Data["server"]) && pr.Owns(app.GetOwnerReferences()) {
				namespacedName := types.NamespacedName{Name: pr.Name, Namespace: pr.Namespace}
				if _, ok := requestsMap[namespacedName]; !ok {
					requestsMap[namespacedName] = true
					requests = append(requests, reconcile.Request{NamespacedName: namespacedName})
				}
			}
		}
	}
	return requests
}
func ( r * ProgressiveSyncReconciler ) requestsForSecretChange ( o client . Object ) [ ] reconcile . Request { var requests [ ] reconcile . Request var prList syncv1alpha1 . ProgressiveSyncList var appList argov1alpha1 . ApplicationList requestsMap := make ( map [ types . NamespacedName ] bool ) ctx := context . Background ( ) s , ok := o . ( * corev1 . Secret ) if ! ok { err := fmt . Errorf ( " " , o ) r . Log . Error ( err , " " ) return nil } r . Log . Info ( " " , " " , s . Name , " " , s . Namespace ) if ! utils . IsArgoCDCluster ( s . GetLabels ( ) ) { return nil } if err := r . List ( ctx , & prList ) ; err != nil { r . Log . Error ( err , " " ) return nil } if err := r . List ( ctx , & appList ) ; err != nil { r . Log . Error ( err , " " ) return nil } for _ , pr := range prList . Items { for _ , app := range appList . Items { if app . Spec . Destination . Server == string ( s . Data [ " " ] ) && pr . Owns ( app . GetOwnerReferences ( ) ) { namespacedName := types . NamespacedName { Name : pr . Name , Namespace : pr . Namespace } if _ , ok := requestsMap [ namespacedName ] ; ! ok { requestsMap [ namespacedName ] = true requests = append ( requests , reconcile . Request { NamespacedName : namespacedName } ) } } } } return requests }
requestsForSecretChange returns a reconcile request when a Secret changes
requestsForSecretChange returns a reconcile request when a Secret changes
/*
		We trigger a reconciliation loop on a Secret event if:
		- the Secret is an ArgoCD cluster, AND
		- there is an Application targeting that secret/cluster, AND
		- that Application owner is referenced by a ProgressiveSync object
	*/ /*
						Consider the following scenario:
						- two Applications
						- owned by the same ApplicationSet
						- referenced by the same ProgressiveSync
						- targeting the same cluster

						In this scenario, we would trigger the reconciliation loop twice.
						To avoid that, we use a map to store for which ProgressiveSync object
					    we already triggered the reconciliation loop.
				*/