diff --git a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc index c92a62aec0..17e098ec41 100644 --- a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc +++ b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc @@ -7326,11 +7326,11 @@ string To configure the host exposed by the ingress. |`path` + -string +[]string | -To configure the path exposed by the ingress (default `/`). +To configure the paths exposed by the ingress (default `/`). |`pathType` + *https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#pathtype-v1-networking[Kubernetes networking/v1.PathType]* diff --git a/helm/camel-k/crds/camel-k-crds.yaml b/helm/camel-k/crds/camel-k-crds.yaml index f2dde79ccb..105adc8210 100644 --- a/helm/camel-k/crds/camel-k-crds.yaml +++ b/helm/camel-k/crds/camel-k-crds.yaml @@ -4467,9 +4467,11 @@ spec: See https://kubernetes.io/docs/concepts/services-networking/ingress/ type: string path: - description: To configure the path exposed by the ingress + description: To configure the paths exposed by the ingress (default `/`). - type: string + items: + type: string + type: array pathType: description: |- To configure the path type exposed by the ingress. @@ -6656,9 +6658,11 @@ spec: See https://kubernetes.io/docs/concepts/services-networking/ingress/ type: string path: - description: To configure the path exposed by the ingress + description: To configure the paths exposed by the ingress (default `/`). - type: string + items: + type: string + type: array pathType: description: |- To configure the path type exposed by the ingress. @@ -8748,9 +8752,11 @@ spec: See https://kubernetes.io/docs/concepts/services-networking/ingress/ type: string path: - description: To configure the path exposed by the ingress + description: To configure the paths exposed by the ingress (default `/`). - type: string + items: + type: string + type: array pathType: description: |- To configure the path type exposed by the ingress. @@ -10816,9 +10822,11 @@ spec: See https://kubernetes.io/docs/concepts/services-networking/ingress/ type: string path: - description: To configure the path exposed by the ingress + description: To configure the paths exposed by the ingress (default `/`). - type: string + items: + type: string + type: array pathType: description: |- To configure the path type exposed by the ingress. @@ -19265,9 +19273,11 @@ spec: See https://kubernetes.io/docs/concepts/services-networking/ingress/ type: string path: - description: To configure the path exposed by the ingress + description: To configure the paths exposed by the ingress (default `/`). - type: string + items: + type: string + type: array pathType: description: |- To configure the path type exposed by the ingress. @@ -21260,9 +21270,11 @@ spec: See https://kubernetes.io/docs/concepts/services-networking/ingress/ type: string path: - description: To configure the path exposed by the ingress + description: To configure the paths exposed by the ingress (default `/`). - type: string + items: + type: string + type: array pathType: description: |- To configure the path type exposed by the ingress. @@ -31086,9 +31098,11 @@ spec: See https://kubernetes.io/docs/concepts/services-networking/ingress/ type: string path: - description: To configure the path exposed by the ingress + description: To configure the paths exposed by the ingress (default `/`). - type: string + items: + type: string + type: array pathType: description: |- To configure the path type exposed by the ingress. diff --git a/pkg/apis/camel/v1/trait/ingress.go b/pkg/apis/camel/v1/trait/ingress.go index 7cd1653116..02d1966747 100644 --- a/pkg/apis/camel/v1/trait/ingress.go +++ b/pkg/apis/camel/v1/trait/ingress.go @@ -36,8 +36,8 @@ type IngressTrait struct { Annotations map[string]string `property:"annotations" json:"annotations,omitempty"` // To configure the host exposed by the ingress. Host string `property:"host" json:"host,omitempty"` - // To configure the path exposed by the ingress (default `/`). - Path string `property:"path" json:"path,omitempty"` + // To configure the paths exposed by the ingress (default `/`). + Path []string `property:"path" json:"path,omitempty"` // To configure the path type exposed by the ingress. // One of `Exact`, `Prefix`, `ImplementationSpecific` (default to `Prefix`). // +kubebuilder:validation:Enum=Exact;Prefix;ImplementationSpecific diff --git a/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml b/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml index fb199688e6..f89da8200a 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml @@ -1237,9 +1237,11 @@ spec: See https://kubernetes.io/docs/concepts/services-networking/ingress/ type: string path: - description: To configure the path exposed by the ingress + description: To configure the paths exposed by the ingress (default `/`). - type: string + items: + type: string + type: array pathType: description: |- To configure the path type exposed by the ingress. @@ -3426,9 +3428,11 @@ spec: See https://kubernetes.io/docs/concepts/services-networking/ingress/ type: string path: - description: To configure the path exposed by the ingress + description: To configure the paths exposed by the ingress (default `/`). - type: string + items: + type: string + type: array pathType: description: |- To configure the path type exposed by the ingress. diff --git a/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml b/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml index 79425e7751..7437a28c48 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml @@ -1106,9 +1106,11 @@ spec: See https://kubernetes.io/docs/concepts/services-networking/ingress/ type: string path: - description: To configure the path exposed by the ingress + description: To configure the paths exposed by the ingress (default `/`). - type: string + items: + type: string + type: array pathType: description: |- To configure the path type exposed by the ingress. @@ -3174,9 +3176,11 @@ spec: See https://kubernetes.io/docs/concepts/services-networking/ingress/ type: string path: - description: To configure the path exposed by the ingress + description: To configure the paths exposed by the ingress (default `/`). - type: string + items: + type: string + type: array pathType: description: |- To configure the path type exposed by the ingress. diff --git a/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml b/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml index 2169dc54f7..09021e3db9 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml @@ -7466,9 +7466,11 @@ spec: See https://kubernetes.io/docs/concepts/services-networking/ingress/ type: string path: - description: To configure the path exposed by the ingress + description: To configure the paths exposed by the ingress (default `/`). - type: string + items: + type: string + type: array pathType: description: |- To configure the path type exposed by the ingress. @@ -9461,9 +9463,11 @@ spec: See https://kubernetes.io/docs/concepts/services-networking/ingress/ type: string path: - description: To configure the path exposed by the ingress + description: To configure the paths exposed by the ingress (default `/`). - type: string + items: + type: string + type: array pathType: description: |- To configure the path type exposed by the ingress. diff --git a/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml b/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml index 16d1270da6..97bcf026c9 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml @@ -7531,9 +7531,11 @@ spec: See https://kubernetes.io/docs/concepts/services-networking/ingress/ type: string path: - description: To configure the path exposed by the ingress + description: To configure the paths exposed by the ingress (default `/`). - type: string + items: + type: string + type: array pathType: description: |- To configure the path type exposed by the ingress. diff --git a/pkg/trait/ingress.go b/pkg/trait/ingress.go index d78a6248e6..2a34288dda 100644 --- a/pkg/trait/ingress.go +++ b/pkg/trait/ingress.go @@ -101,26 +101,14 @@ func (t *ingressTrait) Apply(e *Environment) error { Host: t.Host, IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ - Paths: []networkingv1.HTTPIngressPath{ - { - Path: t.getPath(), - PathType: t.getPathType(), - Backend: networkingv1.IngressBackend{ - Service: &networkingv1.IngressServiceBackend{ - Name: service.Name, - Port: networkingv1.ServiceBackendPort{ - Name: "http", - }, - }, - }, - }, - }, + Paths: t.getPaths(service), }, }, }, }, }, } + if t.IngressClassName != "" { ingress.Spec.IngressClassName = &t.IngressClassName } @@ -148,12 +136,32 @@ func (t *ingressTrait) Apply(e *Environment) error { return nil } -func (t *ingressTrait) getPath() string { - if t.Path == "" { - return defaultPath +func (t *ingressTrait) getPaths(service *corev1.Service) []networkingv1.HTTPIngressPath { + createIngressPath := func(path string) networkingv1.HTTPIngressPath { + return networkingv1.HTTPIngressPath{ + Path: path, + PathType: t.getPathType(), + Backend: networkingv1.IngressBackend{ + Service: &networkingv1.IngressServiceBackend{ + Name: service.Name, + Port: networkingv1.ServiceBackendPort{ + Name: "http", + }, + }, + }, + } + } + + paths := []networkingv1.HTTPIngressPath{} + if len(t.Path) == 0 { + paths = append(paths, createIngressPath(defaultPath)) + } else { + for _, p := range t.Path { + paths = append(paths, createIngressPath(p)) + } } - return t.Path + return paths } func (t *ingressTrait) getPathType() *networkingv1.PathType { diff --git a/pkg/trait/ingress_test.go b/pkg/trait/ingress_test.go index 6635bd1249..c4aa9017ed 100644 --- a/pkg/trait/ingress_test.go +++ b/pkg/trait/ingress_test.go @@ -129,6 +129,36 @@ func TestApplyIngressTraitDoesSucceed(t *testing.T) { assert.Equal(t, "service-name(hostname) -> service-name(http)", conditions[0].Message) } +func TestApplyIngressTraitWithPathsDoesSucceed(t *testing.T) { + ingressTrait, environment := createNominalIngressTest() + ingressTrait.Path = []string{"/ding", "/dong"} + + err := ingressTrait.Apply(environment) + + require.NoError(t, err) + assert.Len(t, environment.Integration.Status.Conditions, 1) + + assert.Len(t, environment.Resources.Items(), 2) + environment.Resources.Visit(func(resource runtime.Object) { + if ingress, ok := resource.(*networkingv1.Ingress); ok { + assert.Equal(t, "service-name", ingress.Name) + assert.Equal(t, "namespace", ingress.Namespace) + 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, 2) + assert.Equal(t, "/ding", ingress.Spec.Rules[0].HTTP.Paths[0].Path) + assert.Equal(t, "/dong", ingress.Spec.Rules[0].HTTP.Paths[1].Path) + assert.Equal(t, "service-name", ingress.Spec.Rules[0].HTTP.Paths[0].Backend.Service.Name) + assert.NotNil(t, *ingress.Spec.Rules[0].HTTP.Paths[0].PathType) + assert.Equal(t, networkingv1.PathTypePrefix, *ingress.Spec.Rules[0].HTTP.Paths[0].PathType) + } + }) + + conditions := environment.Integration.Status.Conditions + assert.Len(t, conditions, 1) + assert.Equal(t, "service-name(hostname) -> service-name(http)", conditions[0].Message) +} + func TestApplyIngressTraitWithIngressClassNameDoesSucceed(t *testing.T) { ingressTrait, environment := createNominalIngressTestWithIngressClassName("someIngressClass")