This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch pr-442
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 06e295210a095195c8d60b9ea0990064649360b9
Author: Antonin Stefanutti <anto...@stefanutti.fr>
AuthorDate: Wed Mar 1 12:39:39 2023 +0100

    feat: Add path type option to ingress trait
---
 pkg/apis/camel/v1/trait/ingress.go |  6 ++++++
 pkg/trait/ingress.go               | 10 ++++------
 pkg/trait/util.go                  | 11 +++++++++++
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/pkg/apis/camel/v1/trait/ingress.go 
b/pkg/apis/camel/v1/trait/ingress.go
index 6a0ee71c6..128b36f02 100644
--- a/pkg/apis/camel/v1/trait/ingress.go
+++ b/pkg/apis/camel/v1/trait/ingress.go
@@ -17,6 +17,8 @@ limitations under the License.
 
 package trait
 
+import networkingv1 "k8s.io/api/networking/v1"
+
 // The Ingress trait can be used to expose the service associated with the 
integration
 // to the outside world with a Kubernetes Ingress.
 //
@@ -33,6 +35,10 @@ 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 path type exposed by the ingress.
+       // One of `Exact`, `Prefix`, `ImplementationSpecific` (default to 
`Prefix`).
+       // +kubebuilder:validation:Enum=Exact;Prefix;ImplementationSpecific
+       PathType *networkingv1.PathType `property:"path-type" 
json:"pathType,omitempty"`
        // To automatically add an ingress whenever the integration uses an 
HTTP endpoint consumer.
        Auto *bool `property:"auto" json:"auto,omitempty"`
 }
diff --git a/pkg/trait/ingress.go b/pkg/trait/ingress.go
index 8f0243cfa..5635d9de1 100644
--- a/pkg/trait/ingress.go
+++ b/pkg/trait/ingress.go
@@ -24,7 +24,6 @@ import (
        corev1 "k8s.io/api/core/v1"
        networkingv1 "k8s.io/api/networking/v1"
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
-       "k8s.io/utils/pointer"
 
        v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
        traitv1 "github.com/apache/camel-k/pkg/apis/camel/v1/trait"
@@ -42,6 +41,7 @@ func newIngressTrait() Trait {
                        Annotations: map[string]string{},
                        Host:        "",
                        Path:        "/",
+                       PathType:    ptrFrom(networkingv1.PathTypePrefix),
                },
        }
 }
@@ -56,7 +56,7 @@ func (t *ingressTrait) Configure(e *Environment) (bool, 
error) {
                return false, nil
        }
 
-       if !pointer.BoolDeref(t.Enabled, true) {
+       if !ptrDerefOr(t.Enabled, true) {
                e.Integration.Status.SetCondition(
                        v1.IntegrationConditionExposureAvailable,
                        corev1.ConditionFalse,
@@ -66,7 +66,7 @@ func (t *ingressTrait) Configure(e *Environment) (bool, 
error) {
                return false, nil
        }
 
-       if pointer.BoolDeref(t.Auto, true) {
+       if ptrDerefOr(t.Auto, true) {
                if e.Resources.GetUserServiceForIntegration(e.Integration) == 
nil {
                        e.Integration.Status.SetCondition(
                                v1.IntegrationConditionExposureAvailable,
@@ -87,8 +87,6 @@ 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",
@@ -108,7 +106,7 @@ func (t *ingressTrait) Apply(e *Environment) error {
                                                        Paths: 
[]networkingv1.HTTPIngressPath{
                                                                {
                                                                        Path:   
  t.Path,
-                                                                       
PathType: &pathType,
+                                                                       
PathType: t.PathType,
                                                                        
Backend: networkingv1.IngressBackend{
                                                                                
Service: &networkingv1.IngressServiceBackend{
                                                                                
        Name: service.Name,
diff --git a/pkg/trait/util.go b/pkg/trait/util.go
index 1e7daeb8b..d34a6a080 100644
--- a/pkg/trait/util.go
+++ b/pkg/trait/util.go
@@ -42,6 +42,17 @@ import (
        "github.com/apache/camel-k/pkg/util/property"
 )
 
+func ptrFrom[T any](value T) *T {
+       return &value
+}
+
+func ptrDerefOr[T any](value *T, def T) T {
+       if value != nil {
+               return *value
+       }
+       return def
+}
+
 type Options map[string]map[string]interface{}
 
 func (u Options) Get(id string) (map[string]interface{}, bool) {

Reply via email to