github.com/verrazzano/verrazzano@v1.7.0/pkg/nginxutil/nginxutil.go (about)

     1  // Copyright (c) 2023, Oracle and/or its affiliates.
     2  // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     3  
     4  package nginxutil
     5  
     6  import (
     7  	"github.com/verrazzano/verrazzano/pkg/log/vzlog"
     8  	"github.com/verrazzano/verrazzano/pkg/namespace"
     9  	vpoconst "github.com/verrazzano/verrazzano/platform-operator/constants"
    10  )
    11  
    12  // This is set by verrazzano controller.go at startup.  It has to be injected
    13  // since is an import cycle if this code uses component.nginx.
    14  var ingressNGINXNamespace = vpoconst.IngressNginxNamespace
    15  
    16  // SetIngressNGINXNamespace sets the namespace, this is done at VZ reconcile startup, see controller.go
    17  func SetIngressNGINXNamespace(ns string) {
    18  	ingressNGINXNamespace = ns
    19  }
    20  
    21  // IngressNGINXNamespace returns the ingress-nginx namespace
    22  func IngressNGINXNamespace() string {
    23  	return ingressNGINXNamespace
    24  }
    25  
    26  // DetermineNamespaceForIngressNGINX determines the namespace for Ingress NGINX
    27  func DetermineNamespaceForIngressNGINX(log vzlog.VerrazzanoLogger) (string, error) {
    28  	// Check if Verrazzano NGINX is installed in the ingress-nginx namespace
    29  	legacyNSExists, err := namespace.CheckIfVerrazzanoManagedNamespaceExists(vpoconst.LegacyIngressNginxNamespace)
    30  	if err != nil {
    31  		return "", log.ErrorfNewErr("Failed checking for legacy Ingress NGINX namespace %s: %v", vpoconst.LegacyIngressNginxNamespace, err.Error())
    32  	}
    33  	ingressNGINXNamespace = getNamespaceForIngressNGINX(legacyNSExists)
    34  	log.Oncef("Ingress NGINX namespace is %s", ingressNGINXNamespace)
    35  	return ingressNGINXNamespace, nil
    36  }
    37  
    38  func getNamespaceForIngressNGINX(legacy bool) string {
    39  	if legacy {
    40  		// If Ingress NGINX is already installed ingress-nginx then don't change it.
    41  		// This is to avoid creating a new service in the new namespace, thus causing an
    42  		// LB to be created.
    43  		return vpoconst.LegacyIngressNginxNamespace
    44  	}
    45  	return vpoconst.IngressNginxNamespace
    46  }