Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for multiple ingress paths
Browse files Browse the repository at this point in the history
cfitzw committed Dec 16, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 8c26c79 commit 8d2f4f5
Showing 9 changed files with 211 additions and 44 deletions.
8 changes: 8 additions & 0 deletions docs/modules/ROOT/partials/apis/camel-k-crds.adoc
Original file line number Diff line number Diff line change
@@ -7331,6 +7331,14 @@ string
To configure the path exposed by the ingress (default `/`).
Deprecated: In favor of `paths` - left for backward compatibility.
|`paths` +
[]string
|
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]*
70 changes: 58 additions & 12 deletions helm/camel-k/crds/camel-k-crds.yaml
Original file line number Diff line number Diff line change
@@ -4467,9 +4467,15 @@ spec:
See https://kubernetes.io/docs/concepts/services-networking/ingress/
type: string
path:
description: To configure the path exposed by the ingress
(default `/`).
description: |-
To configure the path exposed by the ingress (default `/`).
Deprecated: In favor of `paths` - left for backward compatibility.
type: string
paths:
description: To configure the paths exposed by the ingress (default `['/']`).
items:
type: string
type: array
pathType:
description: |-
To configure the path type exposed by the ingress.
@@ -6656,9 +6662,15 @@ spec:
See https://kubernetes.io/docs/concepts/services-networking/ingress/
type: string
path:
description: To configure the path exposed by the ingress
(default `/`).
description: |-
To configure the path exposed by the ingress (default `/`).
Deprecated: In favor of `paths` - left for backward compatibility.
type: string
paths:
description: To configure the paths exposed by the ingress (default `['/']`).
items:
type: string
type: array
pathType:
description: |-
To configure the path type exposed by the ingress.
@@ -8748,9 +8760,15 @@ spec:
See https://kubernetes.io/docs/concepts/services-networking/ingress/
type: string
path:
description: To configure the path exposed by the ingress
(default `/`).
description: |-
To configure the path exposed by the ingress (default `/`).
Deprecated: In favor of `paths` - left for backward compatibility.
type: string
paths:
description: To configure the paths exposed by the ingress (default `['/']`).
items:
type: string
type: array
pathType:
description: |-
To configure the path type exposed by the ingress.
@@ -10816,9 +10834,15 @@ spec:
See https://kubernetes.io/docs/concepts/services-networking/ingress/
type: string
path:
description: To configure the path exposed by the ingress
(default `/`).
description: |-
To configure the path exposed by the ingress (default `/`).
Deprecated: In favor of `paths` - left for backward compatibility.
type: string
paths:
description: To configure the paths exposed by the ingress (default `['/']`).
items:
type: string
type: array
pathType:
description: |-
To configure the path type exposed by the ingress.
@@ -19265,9 +19289,15 @@ spec:
See https://kubernetes.io/docs/concepts/services-networking/ingress/
type: string
path:
description: To configure the path exposed by the ingress
(default `/`).
description: |-
To configure the path exposed by the ingress (default `/`).
Deprecated: In favor of `paths` - left for backward compatibility.
type: string
paths:
description: To configure the paths exposed by the ingress (default `['/']`).
items:
type: string
type: array
pathType:
description: |-
To configure the path type exposed by the ingress.
@@ -21260,9 +21290,15 @@ spec:
See https://kubernetes.io/docs/concepts/services-networking/ingress/
type: string
path:
description: To configure the path exposed by the ingress
(default `/`).
description: |-
To configure the path exposed by the ingress (default `/`).
Deprecated: In favor of `paths` - left for backward compatibility.
type: string
paths:
description: To configure the paths exposed by the ingress (default `['/']`).
items:
type: string
type: array
pathType:
description: |-
To configure the path type exposed by the ingress.
@@ -31089,6 +31125,16 @@ spec:
description: To configure the path exposed by the ingress
(default `/`).
type: string
path:
description: |-
To configure the path exposed by the ingress (default `/`).
Deprecated: In favor of `paths` - left for backward compatibility.
type: string
paths:
description: To configure the paths exposed by the ingress (default `['/']`).
items:
type: string
type: array
pathType:
description: |-
To configure the path type exposed by the ingress.
3 changes: 3 additions & 0 deletions pkg/apis/camel/v1/trait/ingress.go
Original file line number Diff line number Diff line change
@@ -38,6 +38,9 @@ type IngressTrait struct {
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 `['/']`).
// Deprecated: In favor of `paths` - left for backward compatibility.
Paths []string `property:"paths" json:"paths,omitempty"`
// To configure the path type exposed by the ingress.
// One of `Exact`, `Prefix`, `ImplementationSpecific` (default to `Prefix`).
// +kubebuilder:validation:Enum=Exact;Prefix;ImplementationSpecific
Original file line number Diff line number Diff line change
@@ -1237,9 +1237,15 @@ spec:
See https://kubernetes.io/docs/concepts/services-networking/ingress/
type: string
path:
description: To configure the path exposed by the ingress
(default `/`).
description: |-
To configure the path exposed by the ingress (default `/`).
Deprecated: In favor of `paths` - left for backward compatibility.
type: string
paths:
description: To configure the paths exposed by the ingress (default `['/']`).
items:
type: string
type: array
pathType:
description: |-
To configure the path type exposed by the ingress.
@@ -3426,9 +3432,15 @@ spec:
See https://kubernetes.io/docs/concepts/services-networking/ingress/
type: string
path:
description: To configure the path exposed by the ingress
(default `/`).
description: |-
To configure the path exposed by the ingress (default `/`).
Deprecated: In favor of `paths` - left for backward compatibility.
type: string
paths:
description: To configure the paths exposed by the ingress (default `['/']`).
items:
type: string
type: array
pathType:
description: |-
To configure the path type exposed by the ingress.
Original file line number Diff line number Diff line change
@@ -1106,9 +1106,15 @@ spec:
See https://kubernetes.io/docs/concepts/services-networking/ingress/
type: string
path:
description: To configure the path exposed by the ingress
(default `/`).
description: |-
To configure the path exposed by the ingress (default `/`).
Deprecated: In favor of `paths` - left for backward compatibility.
type: string
paths:
description: To configure the paths exposed by the ingress (default `['/']`).
items:
type: string
type: array
pathType:
description: |-
To configure the path type exposed by the ingress.
@@ -3174,9 +3180,15 @@ spec:
See https://kubernetes.io/docs/concepts/services-networking/ingress/
type: string
path:
description: To configure the path exposed by the ingress
(default `/`).
description: |-
To configure the path exposed by the ingress (default `/`).
Deprecated: In favor of `paths` - left for backward compatibility.
type: string
paths:
description: To configure the paths exposed by the ingress (default `['/']`).
items:
type: string
type: array
pathType:
description: |-
To configure the path type exposed by the ingress.
20 changes: 16 additions & 4 deletions pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml
Original file line number Diff line number Diff line change
@@ -7466,9 +7466,15 @@ spec:
See https://kubernetes.io/docs/concepts/services-networking/ingress/
type: string
path:
description: To configure the path exposed by the ingress
(default `/`).
description: |-
To configure the path exposed by the ingress (default `/`).
Deprecated: In favor of `paths` - left for backward compatibility.
type: string
paths:
description: To configure the paths exposed by the ingress (default `['/']`).
items:
type: string
type: array
pathType:
description: |-
To configure the path type exposed by the ingress.
@@ -9461,9 +9467,15 @@ spec:
See https://kubernetes.io/docs/concepts/services-networking/ingress/
type: string
path:
description: To configure the path exposed by the ingress
(default `/`).
description: |-
To configure the path exposed by the ingress (default `/`).
Deprecated: In favor of `paths` - left for backward compatibility.
type: string
paths:
description: To configure the paths exposed by the ingress (default `['/']`).
items:
type: string
type: array
pathType:
description: |-
To configure the path type exposed by the ingress.
10 changes: 8 additions & 2 deletions pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml
Original file line number Diff line number Diff line change
@@ -7531,9 +7531,15 @@ spec:
See https://kubernetes.io/docs/concepts/services-networking/ingress/
type: string
path:
description: To configure the path exposed by the ingress
(default `/`).
description: |-
To configure the path exposed by the ingress (default `/`).
Deprecated: In favor of `paths` - left for backward compatibility.
type: string
paths:
description: To configure the paths exposed by the ingress (default `['/']`).
items:
type: string
type: array
pathType:
description: |-
To configure the path type exposed by the ingress.
45 changes: 27 additions & 18 deletions pkg/trait/ingress.go
Original file line number Diff line number Diff line change
@@ -101,20 +101,7 @@ 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),
},
},
},
@@ -148,12 +135,34 @@ 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 t.Path == "" && len(t.Paths) == 0 {
paths = append(paths, createIngressPath(defaultPath))
} else if t.Path != "" {
paths = append(paths, createIngressPath(t.Path))
} else {
for _, p := range t.Paths {
paths = append(paths, createIngressPath(p))
}
}

return t.Path
return paths
}

func (t *ingressTrait) getPathType() *networkingv1.PathType {
59 changes: 59 additions & 0 deletions pkg/trait/ingress_test.go
Original file line number Diff line number Diff line change
@@ -129,6 +129,65 @@ func TestApplyIngressTraitDoesSucceed(t *testing.T) {
assert.Equal(t, "service-name(hostname) -> service-name(http)", conditions[0].Message)
}

func TestApplyIngressTraitWithPathDoesSucceed(t *testing.T) {
ingressTrait, environment := createNominalIngressTest()
ingressTrait.Path = string("/path")

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, 1)
assert.Equal(t, "/path", ingress.Spec.Rules[0].HTTP.Paths[0].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 TestApplyIngressTraitWithPathsDoesSucceed(t *testing.T) {
ingressTrait, environment := createNominalIngressTest()
ingressTrait.Paths = []string{"/path-a", "/path-b"}

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, "/path-a", ingress.Spec.Rules[0].HTTP.Paths[0].Path)
assert.Equal(t, "/path-b", 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")

0 comments on commit 8d2f4f5

Please sign in to comment.