MCPcopy Index your code
hub / github.com/coderanger/migrations-operator / ListMatchingMigrators

Function ListMatchingMigrators

utils/utils.go:30–51  ·  view source on GitHub ↗
(ctx context.Context, c client.Client, pod metav1.Object)

Source from the content-addressed store, hash-verified

28)
29
30func ListMatchingMigrators(ctx context.Context, c client.Client, pod metav1.Object) ([]*migrationsv1beta1.Migrator, error) {
31 // Find any Migrator objects that match this pod.
32 allMigrators := &migrationsv1beta1.MigratorList{}
33 err := c.List(ctx, allMigrators, &client.ListOptions{Namespace: pod.GetNamespace()})
34 if err != nil {
35 return nil, errors.Wrapf(err, "error listing migrators in %s", pod.GetNamespace())
36 }
37 migrators := []*migrationsv1beta1.Migrator{}
38 podLabels := labels.Set(pod.GetLabels())
39 for _, m := range allMigrators.Items {
40 selector, err := metav1.LabelSelectorAsSelector(m.Spec.Selector)
41 if err != nil {
42 // Ignore this migrator. Maybe print a warning in the future? This should probably be handled via a validator on Migrator.
43 continue
44 }
45 if selector.Matches(podLabels) {
46 migrator := m
47 migrators = append(migrators, &migrator)
48 }
49 }
50 return migrators, nil
51}

Callers 2

SetupMethod · 0.92
handleInnerMethod · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected