(_ T, c client.Client)
| 707 | } |
| 708 | |
| 709 | func mapObjectToMonitor[T client.Object](_ T, c client.Client) func(ctx context.Context, obj client.Object) []reconcile.Request { |
| 710 | return func(ctx context.Context, obj client.Object) []reconcile.Request { |
| 711 | concrete, ok := obj.(T) |
| 712 | if !ok { |
| 713 | return nil |
| 714 | } |
| 715 | |
| 716 | var monitorList cozyv1alpha1.WorkloadMonitorList |
| 717 | // List all WorkloadMonitors in the same namespace |
| 718 | if err := c.List(ctx, &monitorList, client.InNamespace(concrete.GetNamespace())); err != nil { |
| 719 | return nil |
| 720 | } |
| 721 | |
| 722 | labels := concrete.GetLabels() |
| 723 | // Match each monitor's selector with the Pod's labels |
| 724 | var requests []reconcile.Request |
| 725 | for _, m := range monitorList.Items { |
| 726 | matches := true |
| 727 | for k, v := range m.Spec.Selector { |
| 728 | if labelVal, exists := labels[k]; !exists || labelVal != v { |
| 729 | matches = false |
| 730 | break |
| 731 | } |
| 732 | } |
| 733 | if matches { |
| 734 | requests = append(requests, reconcile.Request{ |
| 735 | NamespacedName: types.NamespacedName{ |
| 736 | Namespace: m.Namespace, |
| 737 | Name: m.Name, |
| 738 | }, |
| 739 | }) |
| 740 | } |
| 741 | } |
| 742 | return requests |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | func (r *WorkloadMonitorReconciler) getWorkloadMetadata(obj client.Object) map[string]string { |
| 747 | labels := make(map[string]string) |
no test coverage detected