Skip to content

Commit

Permalink
feat(trait): add support for multiple ingress paths (#5996)
Browse files Browse the repository at this point in the history
* add support for multiple ingress paths

* allow path related ingress fields to co-exist

* add a depreciation warning for ingress.path

* ensure depreciation warning shows in operator log

* add test for the new depreciation condition
  • Loading branch information
cfitzw authored Jan 8, 2025
1 parent 6b3a2f3 commit 15a4efe
Show file tree
Hide file tree
Showing 9 changed files with 252 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
Expand Up @@ -7338,6 +7338,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]*
Expand Down
70 changes: 58 additions & 12 deletions helm/camel-k/crds/camel-k-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4481,9 +4481,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.
Expand Down Expand Up @@ -6677,9 +6683,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.
Expand Down Expand Up @@ -8776,9 +8788,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.
Expand Down Expand Up @@ -10851,9 +10869,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.
Expand Down Expand Up @@ -19307,9 +19331,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.
Expand Down Expand Up @@ -21309,9 +21339,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.
Expand Down Expand Up @@ -31145,6 +31181,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.
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/camel/v1/trait/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1244,9 +1244,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.
Expand Down Expand Up @@ -3440,9 +3446,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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1113,9 +1113,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.
Expand Down Expand Up @@ -3188,9 +3194,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.
Expand Down
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
Expand Up @@ -7473,9 +7473,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.
Expand Down Expand Up @@ -9475,9 +9481,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.
Expand Down
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
Expand Up @@ -7538,9 +7538,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.
Expand Down
62 changes: 44 additions & 18 deletions pkg/trait/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ func (t *ingressTrait) Configure(e *Environment) (bool, *TraitCondition, error)
if e.Integration == nil {
return false, nil, nil
}

if !e.IntegrationInRunningPhases() {
return false, nil, nil
}

if !ptr.Deref(t.Enabled, true) {
return false, NewIntegrationCondition(
"Ingress",
Expand All @@ -76,6 +78,20 @@ func (t *ingressTrait) Configure(e *Environment) (bool, *TraitCondition, error)
}
}

if t.Path != "" {
m := "The path parameter is deprecated and may be removed in a future release. Use the paths parameter instead."
t.L.Info(m)
condition := NewIntegrationCondition(
"Ingress",
v1.IntegrationConditionTraitInfo,
corev1.ConditionTrue,
TraitConfigurationReason,
m,
)

return true, condition, nil
}

return true, nil, nil
}

Expand All @@ -101,20 +117,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),
},
},
},
Expand Down Expand Up @@ -148,12 +151,35 @@ 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))
}
for _, p := range t.Paths {
paths = append(paths, createIngressPath(p))
}
}

return t.Path
return paths
}

func (t *ingressTrait) getPathType() *networkingv1.PathType {
Expand Down
Loading

0 comments on commit 15a4efe

Please sign in to comment.