MCPcopy Create free account
hub / github.com/cozystack/cozystack / mapObjectToMonitor

Function mapObjectToMonitor

internal/controller/workloadmonitor_controller.go:709–744  ·  view source on GitHub ↗
(_ T, c client.Client)

Source from the content-addressed store, hash-verified

707}
708
709func 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
746func (r *WorkloadMonitorReconciler) getWorkloadMetadata(obj client.Object) map[string]string {
747 labels := make(map[string]string)

Callers 1

SetupWithManagerMethod · 0.85

Calls 2

ListMethod · 0.65
GetNamespaceMethod · 0.65

Tested by

no test coverage detected