in pkg/controller/nginxingress/nginx_ingress_controller.go [283:334]
func (n *nginxIngressControllerReconciler) collides(ctx context.Context, nic *approutingv1alpha1.NginxIngressController) (collision, error) {
lgr := log.FromContext(ctx)
// ignore any collisions on default nic for migration story. Need to acquire ownership of old app routing resources
if IsDefaultNic(nic) {
return collisionNone, nil
}
res := n.ManagedResources(nic)
if res == nil {
return collisionNone, fmt.Errorf("getting managed objects")
}
for _, obj := range res.Objects() {
lgr := lgr.WithValues("kind", obj.GetObjectKind().GroupVersionKind().Kind, "name", obj.GetName(), "namespace", obj.GetNamespace())
// if we won't own the resource, we don't care about collisions.
// this is most commonly used for namespaces since we shouldn't own
// namespaces
if !manifests.HasTopLevelLabels(obj.GetLabels()) {
lgr.Info("skipping collision check because we don't own the resource")
continue
}
u := &unstructured.Unstructured{}
u.SetGroupVersionKind(obj.GetObjectKind().GroupVersionKind())
err := n.client.Get(ctx, client.ObjectKeyFromObject(obj), u)
if err != nil {
if apierrors.IsNotFound(err) {
continue
}
return collisionNone, fmt.Errorf("getting object: %w", err)
}
if owner := util.FindOwnerKind(u.GetOwnerReferences(), nic.Kind); owner == nic.Name {
lgr.Info("the nginxIngressController owns this resource")
continue
}
lgr.Info("collision detected")
if obj.GetObjectKind().GroupVersionKind().Kind == "IngressClass" {
lgr.Info("collision is with an IngressClass")
return collisionIngressClass, nil
}
return collisionOther, nil
}
lgr.Info("no collisions detected")
return collisionNone, nil
}