// enforceEffectiveIngressDomain determines the effective ingress domain for the
// given ingresscontroller and ingress configuration and publishes it to the
// ingresscontroller's status.
enforceEffectiveIngressDomain determines the effective ingress domain for the
given ingresscontroller and ingress configuration and publishes it to the
ingresscontroller's status.
// enforceEffectiveIngressDomain determines the effective ingress domain for the // given ingresscontroller and ingress configuration and publishes it to the // ingresscontroller ' s status .
func (r *reconciler) enforceEffectiveIngressDomain(ic *operatorv1.IngressController, ingressConfig *configv1.Ingress) error {
	if len(ic.Status.Domain) > 0 {
		return nil
	}
	updated := ic.DeepCopy()
	var domain string
	switch {
	case len(ic.Spec.Domain) > 0:
		domain = ic.Spec.Domain
	default:
		domain = ingressConfig.Spec.Domain
	}
	unique, err := r.isDomainUnique(domain)
	if err != nil {
		return err
	}
	if !unique {
		log.Info("domain not unique, not setting status domain for IngressController", "namespace", ic.Namespace, "name", ic.Name)
		availableCondition := operatorv1.OperatorCondition{
			Type:    operatorv1.IngressControllerAvailableConditionType,
			Status:  operatorv1.ConditionFalse,
			Reason:  "InvalidDomain",
			Message: fmt.Sprintf("domain %q is already in use by another IngressController", domain),
		}
		oldAvailableCondition := getIngressAvailableCondition(updated.Status.Conditions)
		setIngressLastTransitionTime(&availableCondition, oldAvailableCondition)
		updated.Status.Conditions = []operatorv1.OperatorCondition{availableCondition}
	} else {
		updated.Status.Domain = domain
	}
	if err := r.client.Status().Update(context.TODO(), updated); err != nil {
		return fmt.Errorf("failed to update status of IngressController %s/%s: %v", updated.Namespace, updated.Name, err)
	}
	if err := r.client.Get(context.TODO(), types.NamespacedName{Namespace: updated.Namespace, Name: updated.Name}, ic); err != nil {
		return fmt.Errorf("failed to get IngressController %s/%s: %v", updated.Namespace, updated.Name, err)
	}
	return nil
}
func ( r * reconciler ) enforceEffectiveIngressDomain ( ic * operatorv1 . IngressController , ingressConfig * configv1 . Ingress ) error { if len ( ic . Status . Domain ) > 0 { return nil } updated := ic . DeepCopy ( ) var domain string switch { case len ( ic . Spec . Domain ) > 0 : domain = ic . Spec . Domain default : domain = ingressConfig . Spec . Domain } unique , err := r . isDomainUnique ( domain ) if err != nil { return err } if ! unique { log . Info ( " " , " " , ic . Namespace , " " , ic . Name ) availableCondition := operatorv1 . OperatorCondition { Type : operatorv1 . IngressControllerAvailableConditionType , Status : operatorv1 . ConditionFalse , Reason : " " , Message : fmt . Sprintf ( " " , domain ) , } oldAvailableCondition := getIngressAvailableCondition ( updated . Status . Conditions ) setIngressLastTransitionTime ( & availableCondition , oldAvailableCondition ) updated . Status . Conditions = [ ] operatorv1 . OperatorCondition { availableCondition } } else { updated . Status . Domain = domain } if err := r . client . Status ( ) . Update ( context . TODO ( ) , updated ) ; err != nil { return fmt . Errorf ( " " , updated . Namespace , updated . Name , err ) } if err := r . client . Get ( context . TODO ( ) , types . NamespacedName { Namespace : updated . Namespace , Name : updated . Name } , ic ) ; err != nil { return fmt . Errorf ( " " , updated . Namespace , updated . Name , err ) } return nil }
enforceEffectiveIngressDomain determines the effective ingress domain for the
given ingresscontroller and ingress configuration and publishes it to the
ingresscontroller's status.
enforceEffectiveIngressDomain determines the effective ingress domain for the given ingresscontroller and ingress configuration and publishes it to the ingresscontroller ' s status .
// The ingresscontroller's ingress domain is immutable, so if we have // published a domain to status, we must continue using it. // TODO: refactor when we deal with multiple ingress conditions