MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / clusterMatchesPod

Function clusterMatchesPod

pkg/reconciler/podselector/mapper.go:38–50  ·  view source on GitHub ↗

clusterMatchesPod returns true if any of the cluster's podSelectorRefs match the given pod's labels.

(cluster *apiv1.Cluster, pod *corev1.Pod)

Source from the content-addressed store, hash-verified

36// clusterMatchesPod returns true if any of the cluster's podSelectorRefs
37// match the given pod's labels.
38func clusterMatchesPod(cluster *apiv1.Cluster, pod *corev1.Pod) bool {
39 for i := range cluster.Spec.PodSelectorRefs {
40 ref := &cluster.Spec.PodSelectorRefs[i]
41 selector, err := metav1.LabelSelectorAsSelector(&ref.Selector)
42 if err != nil {
43 continue
44 }
45 if selector.Matches(labels.Set(pod.Labels)) {
46 return true
47 }
48 }
49 return false
50}
51
52// MapExternalPodsToClusters returns a handler that maps pod events to
53// Cluster reconcile requests when the pod matches any Cluster's podSelectorRefs.

Callers 2

mapper_test.goFile · 0.85

Calls 1

SetMethod · 0.45

Tested by

no test coverage detected