(ctx *cu.Context)
| 102 | } |
| 103 | |
| 104 | func (comp *migrationsComponent) Reconcile(ctx *cu.Context) (cu.Result, error) { |
| 105 | obj := ctx.Object.(*migrationsv1beta1.Migrator) |
| 106 | |
| 107 | // Create the selectors. |
| 108 | rawSelector := obj.Spec.Selector |
| 109 | if rawSelector == nil { |
| 110 | rawSelector = &metav1.LabelSelector{MatchLabels: map[string]string{}} |
| 111 | } |
| 112 | selector, err := metav1.LabelSelectorAsSelector(rawSelector) |
| 113 | if err != nil { |
| 114 | return cu.Result{}, errors.Wrap(err, "error parsing selector") |
| 115 | } |
| 116 | rawSelector = obj.Spec.TemplateSelector |
| 117 | if rawSelector == nil { |
| 118 | rawSelector = &metav1.LabelSelector{MatchLabels: map[string]string{}} |
| 119 | } |
| 120 | templateSelector, err := metav1.LabelSelectorAsSelector(rawSelector) |
| 121 | if err != nil { |
| 122 | return cu.Result{}, errors.Wrap(err, "error parsing template selector") |
| 123 | } |
| 124 | |
| 125 | // Find a template pod to start from. |
| 126 | allPods := &unstructured.UnstructuredList{} |
| 127 | allPods.SetAPIVersion("v1") |
| 128 | allPods.SetKind("Pod") |
| 129 | err = ctx.Client.List(ctx, allPods, &client.ListOptions{Namespace: obj.Namespace}) |
| 130 | if err != nil { |
| 131 | return cu.Result{}, errors.Wrapf(err, "error listing pods in namespace %s", obj.Namespace) |
| 132 | } |
| 133 | pods := []*unstructured.Unstructured{} |
| 134 | var templatePod *unstructured.Unstructured |
| 135 | for i := range allPods.Items { |
| 136 | pod := &allPods.Items[i] |
| 137 | labelSet := labels.Set(pod.GetLabels()) |
| 138 | if selector.Matches(labelSet) { |
| 139 | pods = append(pods, pod) |
| 140 | if templatePod == nil && templateSelector.Matches(labelSet) { |
| 141 | templatePod = pod |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | if len(pods) == 0 { |
| 146 | // No matching pods, just bail out for now. |
| 147 | return cu.Result{}, nil |
| 148 | } |
| 149 | if templatePod == nil { |
| 150 | // We had at least one matching pod, but no valid templates, error out. |
| 151 | return cu.Result{}, errors.New("no template pods found") |
| 152 | } |
| 153 | |
| 154 | // Find the template pod spec, possibly from an owner object. |
| 155 | templatePodSpec, err := comp.findOwnerSpec(ctx, templatePod) |
| 156 | if err != nil { |
| 157 | return cu.Result{}, errors.Wrap(err, "error finding template pod spec") |
| 158 | } |
| 159 | |
| 160 | // Find the template container. |
| 161 | templatePodSpecContainers := templatePodSpec["containers"].([]interface{}) |
no test coverage detected