Skip to content

Commit

Permalink
Use base path to set ingress on openshift
Browse files Browse the repository at this point in the history
Signed-off-by: Pavol Loffay <[email protected]>
  • Loading branch information
pavolloffay committed Nov 23, 2023
1 parent f1cb190 commit 9e27620
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 9 deletions.
4 changes: 2 additions & 2 deletions apis/config/v1alpha1/projectconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion controllers/tempo/tempostack_create_or_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/operator/feature-gates.md
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,8 @@ string

<td>

<p>BaseDomain is used internally for redirect URL in gateway OpenShift auth mode.
If empty the operator automatically derives the domain from the cluster.</p>
<p>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.</p>

</td>
</tr>
Expand Down
14 changes: 10 additions & 4 deletions internal/manifests/queryfrontend/query_frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)

Expand All @@ -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,
Expand All @@ -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{
Expand Down
63 changes: 63 additions & 0 deletions internal/manifests/queryfrontend/query_frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 9e27620

Please sign in to comment.