func GetUserRefNamespace(ns string, ref v1alpha1.UserReference) string {
	userNamespace := ref.Namespace
	if userNamespace == "" {
		return ns
	}
	return userNamespace
}
GetUserRefNamespace returns the expected namespace for a Nifi user
referenced by a parameter context CR. It takes the namespace of the CR as the first
argument and the reference itself as the second.
package controllers
import (
	"fmt"
	"github.com/Orange-OpenSource/nifikop/pkg/util/clientconfig"
	"time"
	"emperror.dev/errors"
	"github.com/Orange-OpenSource/nifikop/api/v1alpha1"
	"github.com/Orange-OpenSource/nifikop/pkg/errorfactory"
	"github.com/go-logr/logr"
	ctrl "sigs.k8s.io/controller-runtime"
	"sigs.k8s.io/controller-runtime/pkg/reconcile"
)
var ClusterRefLabel = "nifiCluster"
func RequeueWithError(logger logr.Logger, msg string, err error) (reconcile.Result, error) {
	logger.Info(msg)
	return reconcile.Result{}, err
}
func Requeue() (reconcile.Result, error) {
	return reconcile.Result{Requeue: true}, nil
}
func RequeueAfter(time time.Duration) (reconcile.Result, error) {
	return reconcile.Result{Requeue: true, RequeueAfter: time}, nil
}
func Reconciled() (reconcile.Result, error) {
	return reconcile.Result{}, nil
}
func ClusterLabelString(cluster *v1alpha1.NifiCluster) string {
	return fmt.Sprintf("%s.%s", cluster.Name, cluster.Namespace)
}
func CheckNodeConnectionError(logger logr.Logger, err error) (ctrl.Result, error) {
	switch errors.Cause(err).(type) {
	case errorfactory.NodesUnreachable:
		return ctrl.Result{
			Requeue:      true,
			RequeueAfter: time.Duration(15) * time.Second,
		}, nil
	case errorfactory.NodesNotReady:
		return ctrl.Result{
			Requeue:      true,
			RequeueAfter: time.Duration(15) * time.Second,
		}, nil
	case errorfactory.ResourceNotReady:
		logger.Info("Needed resource for node connection not found, may not be ready")
		return ctrl.Result{
			Requeue:      true,
			RequeueAfter: time.Duration(5) * time.Second,
		}, nil
	default:
		return RequeueWithError(logger, err.Error(), err)
	}
}
func ApplyClusterRefLabel(cluster *v1alpha1.NifiCluster, labels map[string]string) map[string]string {
	labelValue := ClusterLabelString(cluster)
	if labels == nil {
		labels = make(map[string]string, 0)
	}
	if label, ok := labels[ClusterRefLabel]; ok {
		if label != labelValue {
			labels[ClusterRefLabel] = labelValue
		}
	} else {
		labels[ClusterRefLabel] = labelValue
	}
	return labels
}
func ApplyClusterReferenceLabel(cluster clientconfig.ClusterConnect, labels map[string]string) map[string]string {
	labelValue := cluster.ClusterLabelString()
	if labels == nil {
		labels = make(map[string]string, 0)
	}
	if label, ok := labels[ClusterRefLabel]; ok {
		if label != labelValue {
			labels[ClusterRefLabel] = labelValue
		}
	} else {
		labels[ClusterRefLabel] = labelValue
	}
	return labels
}
func GetClusterRefNamespace(ns string, ref v1alpha1.ClusterReference) string {
	clusterNamespace := ref.Namespace
	if clusterNamespace == "" {
		return ns
	}
	return clusterNamespace
}
func GetRegistryClientRefNamespace(ns string, ref v1alpha1.RegistryClientReference) string {
	registryClientNamespace := ref.Namespace
	if registryClientNamespace == "" {
		return ns
	}
	return registryClientNamespace
}
func GetParameterContextRefNamespace(ns string, ref v1alpha1.ParameterContextReference) string {
	parameterContextNamespace := ref.Namespace
	if parameterContextNamespace == "" {
		return ns
	}
	return parameterContextNamespace
}
func GetSecretRefNamespace(ns string, ref v1alpha1.SecretReference) string {
	secretNamespace := ref.Namespace
	if secretNamespace == "" {
		return ns
	}
	return secretNamespace
}