This is an automated email from the ASF dual-hosted git repository. astefanutti pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/main by this push: new 8936bd929 trait(ingress): Configure backend in ingress rule 8936bd929 is described below commit 8936bd9292a1883a24a917b5122e8b0e1d7aba5d Author: Antonin Stefanutti <anto...@stefanutti.fr> AuthorDate: Fri Sep 16 14:03:06 2022 +0200 trait(ingress): Configure backend in ingress rule --- pkg/trait/ingress.go | 34 +++++++++++++++++++++------------- pkg/trait/ingress_test.go | 6 +++++- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/pkg/trait/ingress.go b/pkg/trait/ingress.go index f674c1ac7..99da27bba 100644 --- a/pkg/trait/ingress.go +++ b/pkg/trait/ingress.go @@ -85,6 +85,8 @@ func (t *ingressTrait) Apply(e *Environment) error { return errors.New("cannot Apply ingress trait: no target service") } + pathType := networkingv1.PathTypePrefix + ingress := networkingv1.Ingress{ TypeMeta: metav1.TypeMeta{ Kind: "Ingress", @@ -95,17 +97,27 @@ func (t *ingressTrait) Apply(e *Environment) error { Namespace: service.Namespace, }, Spec: networkingv1.IngressSpec{ - DefaultBackend: &networkingv1.IngressBackend{ - Service: &networkingv1.IngressServiceBackend{ - Name: service.Name, - Port: networkingv1.ServiceBackendPort{ - Name: "http", - }, - }, - }, Rules: []networkingv1.IngressRule{ { Host: t.Host, + IngressRuleValue: networkingv1.IngressRuleValue{ + HTTP: &networkingv1.HTTPIngressRuleValue{ + Paths: []networkingv1.HTTPIngressPath{ + { + Path: "/", + PathType: &pathType, + Backend: networkingv1.IngressBackend{ + Service: &networkingv1.IngressServiceBackend{ + Name: service.Name, + Port: networkingv1.ServiceBackendPort{ + Name: "http", + }, + }, + }, + }, + }, + }, + }, }, }, }, @@ -113,11 +125,7 @@ func (t *ingressTrait) Apply(e *Environment) error { e.Resources.Add(&ingress) - message := fmt.Sprintf("%s(%s) -> %s(%s)", - ingress.Name, - t.Host, - ingress.Spec.DefaultBackend.Service.Name, - ingress.Spec.DefaultBackend.Service.Port.Name) + message := fmt.Sprintf("%s(%s) -> %s(%s)", ingress.Name, t.Host, service.Name, "http") e.Integration.Status.SetCondition( v1.IntegrationConditionExposureAvailable, diff --git a/pkg/trait/ingress_test.go b/pkg/trait/ingress_test.go index 1090a0c1f..3d620cf75 100644 --- a/pkg/trait/ingress_test.go +++ b/pkg/trait/ingress_test.go @@ -114,9 +114,13 @@ func TestApplyIngressTraitDoesSucceed(t *testing.T) { if ingress, ok := resource.(*networkingv1.Ingress); ok { assert.Equal(t, "service-name", ingress.Name) assert.Equal(t, "namespace", ingress.Namespace) - assert.Equal(t, "service-name", ingress.Spec.DefaultBackend.Service.Name) assert.Len(t, ingress.Spec.Rules, 1) assert.Equal(t, "hostname", ingress.Spec.Rules[0].Host) + assert.Len(t, ingress.Spec.Rules[0].HTTP.Paths, 1) + assert.Equal(t, "service-name", ingress.Spec.Rules[0].HTTP.Paths[0].Backend.Service.Name) + assert.Equal(t, "/", ingress.Spec.Rules[0].HTTP.Paths[0].Path) + assert.NotNil(t, *ingress.Spec.Rules[0].HTTP.Paths[0].PathType) + assert.Equal(t, networkingv1.PathTypePrefix, *ingress.Spec.Rules[0].HTTP.Paths[0].PathType) } })