func IsIngressManaged()

in pkg/controller/nginxingress/index.go [34:60]


func IsIngressManaged(ctx context.Context, cl client.Client, ing *netv1.Ingress, ingressClassNameIndex string) (bool, error) {
	ic := ing.Spec.IngressClassName
	if ic == nil {
		return false, nil
	}

	// if it's the default one we should assume we own it because there's time in the upgrade from non crd app routing to crd app routing where a crd for the default doesn't exist
	if *ic == DefaultIcName {
		return true, nil
	}

	nics := &approutingv1alpha1.NginxIngressControllerList{}
	err := cl.List(ctx, nics, client.MatchingFields{ingressClassNameIndex: *ic})
	if err == nil {
		if len(nics.Items) == 0 {
			return false, nil
		}

		return true, nil
	}
	if !k8serrors.IsNotFound(err) {
		return false, fmt.Errorf("listing nginx ingress controllers: %w", err)
	}

	return false, nil

}