From 04123a85dd37fae60842b3cde1c2c246cc0fd10b Mon Sep 17 00:00:00 2001 From: "Giau. Tran Minh" Date: Fri, 16 Sep 2022 22:14:39 +0700 Subject: [PATCH 1/3] feat: added pathType to ingress Signed-off-by: Giau. Tran Minh --- apis/v1/jaeger_types.go | 4 ++++ .../crd/bases/jaegertracing.io_jaegers.yaml | 2 ++ docs/api.md | 7 ++++++ examples/ingress-with-host-pathType.yaml | 13 ++++++++++ pkg/ingress/query.go | 17 +++++++------ pkg/ingress/query_test.go | 24 +++++++++++++++++++ 6 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 examples/ingress-with-host-pathType.yaml diff --git a/apis/v1/jaeger_types.go b/apis/v1/jaeger_types.go index 4cfc206f7..a290197e8 100644 --- a/apis/v1/jaeger_types.go +++ b/apis/v1/jaeger_types.go @@ -4,6 +4,7 @@ import ( esv1 "github.com/openshift/elasticsearch-operator/apis/logging/v1" appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" + networkingv1 "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -322,6 +323,9 @@ type JaegerIngressSpec struct { // +listType=atomic Hosts []string `json:"hosts,omitempty"` + // +optional + PathType networkingv1.PathType `json:"pathType,omitempty"` + // +optional // +listType=atomic TLS []JaegerIngressTLSSpec `json:"tls,omitempty"` diff --git a/config/crd/bases/jaegertracing.io_jaegers.yaml b/config/crd/bases/jaegertracing.io_jaegers.yaml index c57c2c1aa..7fc6c59a0 100644 --- a/config/crd/bases/jaegertracing.io_jaegers.yaml +++ b/config/crd/bases/jaegertracing.io_jaegers.yaml @@ -6699,6 +6699,8 @@ spec: options: type: object x-kubernetes-preserve-unknown-fields: true + pathType: + type: string resources: nullable: true properties: diff --git a/docs/api.md b/docs/api.md index fa7f0237f..1e652928a 100644 --- a/docs/api.md +++ b/docs/api.md @@ -23780,6 +23780,13 @@ Resource Types:
false + + pathType + string + +
+ + false resources object diff --git a/examples/ingress-with-host-pathType.yaml b/examples/ingress-with-host-pathType.yaml new file mode 100644 index 000000000..94937d572 --- /dev/null +++ b/examples/ingress-with-host-pathType.yaml @@ -0,0 +1,13 @@ +apiVersion: jaegertracing.io/v1 +kind: Jaeger +metadata: + name: ingress-with-hosts +spec: + query: + options: + base-path: "/" + ingress: + enabled: true + pathType: Prefix + hosts: + - mesh-jaeger.xxx.com #your domain name. diff --git a/pkg/ingress/query.go b/pkg/ingress/query.go index 0f67c7f14..5767c173a 100644 --- a/pkg/ingress/query.go +++ b/pkg/ingress/query.go @@ -87,8 +87,12 @@ func (i *QueryIngress) addRulesSpec(spec *networkingv1.IngressSpec, backend *net path = queryBasePath } + pathType := networkingv1.PathTypeImplementationSpecific + if pt := i.jaeger.Spec.Ingress.PathType; pt != "" { + pathType = networkingv1.PathType(pt) + } if len(i.jaeger.Spec.Ingress.Hosts) > 0 || path != "" { - spec.Rules = append(spec.Rules, getRules(path, i.jaeger.Spec.Ingress.Hosts, backend)...) + spec.Rules = append(spec.Rules, getRules(path, &pathType, i.jaeger.Spec.Ingress.Hosts, backend)...) } else { // no hosts and no custom path -> fall back to a single service Ingress spec.DefaultBackend = backend @@ -118,26 +122,25 @@ func (i *QueryIngress) addTLSSpec(spec *networkingv1.IngressSpec) { } } -func getRules(path string, hosts []string, backend *networkingv1.IngressBackend) []networkingv1.IngressRule { +func getRules(path string, pathType *networkingv1.PathType, hosts []string, backend *networkingv1.IngressBackend) []networkingv1.IngressRule { if len(hosts) > 0 { rules := make([]networkingv1.IngressRule, len(hosts)) for i, host := range hosts { - rule := getRule(host, path, backend) + rule := getRule(host, path, pathType, backend) rules[i] = rule } return rules } - return []networkingv1.IngressRule{getRule("", path, backend)} + return []networkingv1.IngressRule{getRule("", path, pathType, backend)} } -func getRule(host string, path string, backend *networkingv1.IngressBackend) networkingv1.IngressRule { - pathType := networkingv1.PathTypeImplementationSpecific +func getRule(host string, path string, pathType *networkingv1.PathType, backend *networkingv1.IngressBackend) networkingv1.IngressRule { rule := networkingv1.IngressRule{} rule.Host = host rule.HTTP = &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ { - PathType: &pathType, + PathType: pathType, Path: path, Backend: *backend, }, diff --git a/pkg/ingress/query_test.go b/pkg/ingress/query_test.go index 2ec153843..c265ce91b 100644 --- a/pkg/ingress/query_test.go +++ b/pkg/ingress/query_test.go @@ -7,6 +7,7 @@ import ( "k8s.io/apimachinery/pkg/types" v1 "github.com/jaegertracing/jaeger-operator/apis/v1" + networkingv1 "k8s.io/api/networking/v1" ) func TestQueryIngress(t *testing.T) { @@ -140,6 +141,29 @@ func TestQueryIngressWithHosts(t *testing.T) { assert.Len(t, dep.Spec.Rules[0].HTTP.Paths, 1) assert.Empty(t, dep.Spec.Rules[0].HTTP.Paths[0].Path) + assert.Equal(t, networkingv1.PathType("ImplementationSpecific"), *dep.Spec.Rules[0].HTTP.Paths[0].PathType) + assert.Equal(t, "test-host-1", dep.Spec.Rules[0].Host) + assert.NotNil(t, dep.Spec.Rules[0].HTTP.Paths[0].Backend) +} + +func TestQueryIngressWithPathType(t *testing.T) { + enabled := true + jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestQueryIngressWithHosts"}) + jaeger.Spec.Ingress.Enabled = &enabled + jaeger.Spec.Ingress.PathType = networkingv1.PathType("Prefix") + jaeger.Spec.Ingress.Hosts = []string{"test-host-1"} + + ingress := NewQueryIngress(jaeger) + + dep := ingress.Get() + + assert.NotNil(t, dep) + assert.Nil(t, dep.Spec.DefaultBackend) + assert.Len(t, dep.Spec.Rules, 1) + + assert.Len(t, dep.Spec.Rules[0].HTTP.Paths, 1) + assert.Empty(t, dep.Spec.Rules[0].HTTP.Paths[0].Path) + assert.Equal(t, networkingv1.PathType("Prefix"), *dep.Spec.Rules[0].HTTP.Paths[0].PathType) assert.Equal(t, "test-host-1", dep.Spec.Rules[0].Host) assert.NotNil(t, dep.Spec.Rules[0].HTTP.Paths[0].Backend) } From 84c729973ee8262fc742032d801371169b25f44c Mon Sep 17 00:00:00 2001 From: "Giau. Tran Minh" Date: Fri, 16 Sep 2022 22:36:42 +0700 Subject: [PATCH 2/3] fix: update bundle Signed-off-by: Giau. Tran Minh --- bundle/manifests/jaegertracing.io_jaegers.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bundle/manifests/jaegertracing.io_jaegers.yaml b/bundle/manifests/jaegertracing.io_jaegers.yaml index 271aef87c..32fe85b45 100644 --- a/bundle/manifests/jaegertracing.io_jaegers.yaml +++ b/bundle/manifests/jaegertracing.io_jaegers.yaml @@ -6701,6 +6701,8 @@ spec: options: type: object x-kubernetes-preserve-unknown-fields: true + pathType: + type: string resources: nullable: true properties: From 86a236e23c97d03bc70f2ee079375fef355746b3 Mon Sep 17 00:00:00 2001 From: "Giau. Tran Minh" Date: Sat, 17 Sep 2022 01:10:28 +0700 Subject: [PATCH 3/3] fix: run make format Signed-off-by: Giau. Tran Minh --- pkg/ingress/query_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/ingress/query_test.go b/pkg/ingress/query_test.go index c265ce91b..0f9f62e25 100644 --- a/pkg/ingress/query_test.go +++ b/pkg/ingress/query_test.go @@ -6,8 +6,9 @@ import ( "github.com/stretchr/testify/assert" "k8s.io/apimachinery/pkg/types" - v1 "github.com/jaegertracing/jaeger-operator/apis/v1" networkingv1 "k8s.io/api/networking/v1" + + v1 "github.com/jaegertracing/jaeger-operator/apis/v1" ) func TestQueryIngress(t *testing.T) {