diff --git a/apis/config/v1alpha1/projectconfig_types.go b/apis/config/v1alpha1/projectconfig_types.go index a182146cb..37ac71dfa 100644 --- a/apis/config/v1alpha1/projectconfig_types.go +++ b/apis/config/v1alpha1/projectconfig_types.go @@ -75,8 +75,8 @@ type OpenShiftFeatureGates struct { // More details: https://docs.openshift.com/container-platform/latest/networking/understanding-networking.html OpenShiftRoute bool `json:"openshiftRoute,omitempty"` - // BaseDomain is used internally for redirect URL in gateway OpenShift auth mode. - // If empty the operator automatically derives the domain from the cluster. + // BaseDomain is used internally for redirect URL in gateway OpenShift auth mode and as Ingress host. + // If empty and the route is enabled the operator automatically derives the domain from the cluster. BaseDomain string `json:"baseDomain,omitempty"` // ClusterTLSPolicy enables usage of TLS policies set in the API Server. diff --git a/controllers/tempo/tempostack_create_or_update.go b/controllers/tempo/tempostack_create_or_update.go index 7783bf908..0b4d0127e 100644 --- a/controllers/tempo/tempostack_create_or_update.go +++ b/controllers/tempo/tempostack_create_or_update.go @@ -99,7 +99,7 @@ func (r *TempoStackReconciler) createOrUpdate(ctx context.Context, log logr.Logg } } - if tempo.Spec.Tenants != nil && tempo.Spec.Tenants.Mode == v1alpha1.ModeOpenShift && r.CtrlConfig.Gates.OpenShift.BaseDomain == "" { + if r.CtrlConfig.Gates.OpenShift.OpenShiftRoute && r.CtrlConfig.Gates.OpenShift.BaseDomain == "" { domain, err := gateway.GetOpenShiftBaseDomain(ctx, r.Client) if err != nil { return err diff --git a/docs/operator/feature-gates.md b/docs/operator/feature-gates.md index 642b435c9..42f824bb7 100644 --- a/docs/operator/feature-gates.md +++ b/docs/operator/feature-gates.md @@ -772,8 +772,8 @@ string -

BaseDomain is used internally for redirect URL in gateway OpenShift auth mode. -If empty the operator automatically derives the domain from the cluster.

+

BaseDomain is used internally for redirect URL in gateway OpenShift auth mode and as Ingress host. +If empty and the route is enabled the operator automatically derives the domain from the cluster.

diff --git a/internal/manifests/queryfrontend/query_frontend.go b/internal/manifests/queryfrontend/query_frontend.go index 84b82d76d..4ea846b33 100644 --- a/internal/manifests/queryfrontend/query_frontend.go +++ b/internal/manifests/queryfrontend/query_frontend.go @@ -73,7 +73,7 @@ func BuildQueryFrontend(params manifestutils.Params) ([]client.Object, error) { //exhaustive:ignore switch tempo.Spec.Template.QueryFrontend.JaegerQuery.Ingress.Type { case v1alpha1.IngressTypeIngress: - manifests = append(manifests, ingress(tempo)) + manifests = append(manifests, ingress(tempo, params.CtrlConfig.Gates.OpenShift.BaseDomain)) case v1alpha1.IngressTypeRoute: routeObj, err := route(tempo) if err != nil { @@ -433,7 +433,7 @@ func services(tempo v1alpha1.TempoStack) []*corev1.Service { return []*corev1.Service{frontEndService, frontEndDiscoveryService} } -func ingress(tempo v1alpha1.TempoStack) *networkingv1.Ingress { +func ingress(tempo v1alpha1.TempoStack, openshiftBaseDomain string) *networkingv1.Ingress { queryFrontendName := naming.Name(manifestutils.QueryFrontendComponentName, tempo.Name) labels := manifestutils.ComponentLabels(manifestutils.QueryFrontendComponentName, tempo.Name) @@ -449,6 +449,12 @@ func ingress(tempo v1alpha1.TempoStack) *networkingv1.Ingress { }, } + host := tempo.Spec.Template.QueryFrontend.JaegerQuery.Ingress.Host + // On OpenShift always use baseDomain, but on kubernetes it should be possible to configure the default backend + if host == "" && openshiftBaseDomain != "" { + host = fmt.Sprintf("%s-%s.%s", tempo.Name, tempo.Namespace, openshiftBaseDomain) + } + backend := networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: queryFrontendName, @@ -458,13 +464,13 @@ func ingress(tempo v1alpha1.TempoStack) *networkingv1.Ingress { }, } - if tempo.Spec.Template.QueryFrontend.JaegerQuery.Ingress.Host == "" { + if host == "" { ingress.Spec.DefaultBackend = &backend } else { pathType := networkingv1.PathTypePrefix ingress.Spec.Rules = []networkingv1.IngressRule{ { - Host: tempo.Spec.Template.QueryFrontend.JaegerQuery.Ingress.Host, + Host: host, IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ diff --git a/internal/manifests/queryfrontend/query_frontend_test.go b/internal/manifests/queryfrontend/query_frontend_test.go index 938db204d..29bb1cc67 100644 --- a/internal/manifests/queryfrontend/query_frontend_test.go +++ b/internal/manifests/queryfrontend/query_frontend_test.go @@ -434,6 +434,69 @@ func TestQueryFrontendJaegerIngress(t *testing.T) { }, objects[3].(*networkingv1.Ingress)) } +func TestQueryFrontendJaegerIngressEmptyHostOpenShift(t *testing.T) { + tempo := v1alpha1.TempoStack{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test", + Namespace: "project1", + }, + Spec: v1alpha1.TempoStackSpec{ + Template: v1alpha1.TempoTemplateSpec{ + QueryFrontend: v1alpha1.TempoQueryFrontendSpec{ + JaegerQuery: v1alpha1.JaegerQuerySpec{ + Enabled: true, + Ingress: v1alpha1.IngressSpec{ + Type: v1alpha1.IngressTypeIngress, + Host: "", + }, + }, + }, + }, + }, + } + + ing := ingress(tempo, "apps-crc.testing") + require.NotNil(t, ing) + pathType := networkingv1.PathTypePrefix + assert.Equal(t, &networkingv1.Ingress{ + ObjectMeta: metav1.ObjectMeta{ + Name: "tempo-test-query-frontend", + Namespace: "project1", + Labels: map[string]string{ + "app.kubernetes.io/component": "query-frontend", + "app.kubernetes.io/instance": "test", + "app.kubernetes.io/managed-by": "tempo-operator", + "app.kubernetes.io/name": "tempo", + }, + }, + Spec: networkingv1.IngressSpec{ + Rules: []networkingv1.IngressRule{ + { + Host: "test-project1.apps-crc.testing", + IngressRuleValue: networkingv1.IngressRuleValue{ + HTTP: &networkingv1.HTTPIngressRuleValue{ + Paths: []networkingv1.HTTPIngressPath{ + { + Path: "/", + PathType: &pathType, + Backend: networkingv1.IngressBackend{ + Service: &networkingv1.IngressServiceBackend{ + Name: "tempo-test-query-frontend", + Port: networkingv1.ServiceBackendPort{ + Name: "jaeger-ui", + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, ing) +} + func TestQueryFrontendJaegerRoute(t *testing.T) { objects, err := BuildQueryFrontend(manifestutils.Params{Tempo: v1alpha1.TempoStack{ ObjectMeta: metav1.ObjectMeta{