diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index e20110722..7679abd13 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -221,6 +221,7 @@ rules: - apiGroups: - networking.k8s.io resources: + - ingressclasses - ingresses verbs: - create diff --git a/controllers/jaegertracing/jaeger_controller.go b/controllers/jaegertracing/jaeger_controller.go index 122b395fa..8a63daa0e 100644 --- a/controllers/jaegertracing/jaeger_controller.go +++ b/controllers/jaegertracing/jaeger_controller.go @@ -48,7 +48,7 @@ func NewReconciler(client client.Client, clientReader client.Reader, scheme *run // +kubebuilder:rbac:groups=apps,resources=deployments;daemonsets;replicasets;statefulsets,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=extensions,resources=ingresses,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=autoscaling,resources=horizontalpodautoscalers,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=networking.k8s.io,resources=ingresses,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=networking.k8s.io,resources=ingresses;ingressclasses,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=route.openshift.io,resources=routes,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=console.openshift.io,resources=consolelinks,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=batch,resources=jobs;cronjobs,verbs=get;list;watch;create;update;patch;delete diff --git a/pkg/ingress/query.go b/pkg/ingress/query.go index 503be7d47..82843ff09 100644 --- a/pkg/ingress/query.go +++ b/pkg/ingress/query.go @@ -1,10 +1,12 @@ package ingress import ( + "context" "fmt" - networkingv1 "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/kubernetes" + "k8s.io/client-go/rest" v1 "github.com/jaegertracing/jaeger-operator/apis/v1" "github.com/jaegertracing/jaeger-operator/pkg/service" @@ -52,6 +54,38 @@ func (i *QueryIngress) Get() *networkingv1.Ingress { if i.jaeger.Spec.Ingress.IngressClassName != nil { spec.IngressClassName = i.jaeger.Spec.Ingress.IngressClassName + } else { + class := "" + nginxIngressAvailable := false + config, err := rest.InClusterConfig() + if err == nil { + clientSet, err := kubernetes.NewForConfig(config) + if err == nil { + ingressList, err := clientSet.NetworkingV1().IngressClasses().List(context.Background(), metav1.ListOptions{}) + if err == nil { + for _, ingress := range ingressList.Items { + if ingress.Name == "nginx" { + nginxIngressAvailable = true + } + for k, v := range ingress.Annotations { + if k == "ingressclass.kubernetes.io/is-default-class" { + if v == "true" { + class = ingress.Name + break + } + } + } + } + } + } + } + + if len(class) > 0 { + spec.IngressClassName = &class + } else if nginxIngressAvailable { + class = "nginx" + spec.IngressClassName = &class + } } return &networkingv1.Ingress{