Skip to content

Commit

Permalink
feat: added pathType to ingress (#2066)
Browse files Browse the repository at this point in the history
* feat: added pathType to ingress

Signed-off-by: Giau. Tran Minh <[email protected]>

* fix: update bundle

Signed-off-by: Giau. Tran Minh <[email protected]>

* fix: run make format

Signed-off-by: Giau. Tran Minh <[email protected]>

Signed-off-by: Giau. Tran Minh <[email protected]>
  • Loading branch information
giautm authored Sep 19, 2022
1 parent 8903e35 commit cc61547
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 7 deletions.
4 changes: 4 additions & 0 deletions apis/v1/jaeger_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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"`
Expand Down
2 changes: 2 additions & 0 deletions bundle/manifests/jaegertracing.io_jaegers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6701,6 +6701,8 @@ spec:
options:
type: object
x-kubernetes-preserve-unknown-fields: true
pathType:
type: string
resources:
nullable: true
properties:
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/jaegertracing.io_jaegers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6699,6 +6699,8 @@ spec:
options:
type: object
x-kubernetes-preserve-unknown-fields: true
pathType:
type: string
resources:
nullable: true
properties:
Expand Down
7 changes: 7 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -23780,6 +23780,13 @@ Resource Types:
<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>pathType</b></td>
<td>string</td>
<td>
<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#jaegerspecingressresources">resources</a></b></td>
<td>object</td>
Expand Down
13 changes: 13 additions & 0 deletions examples/ingress-with-host-pathType.yaml
Original file line number Diff line number Diff line change
@@ -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.
17 changes: 10 additions & 7 deletions pkg/ingress/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
},
Expand Down
25 changes: 25 additions & 0 deletions pkg/ingress/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/types"

networkingv1 "k8s.io/api/networking/v1"

v1 "github.com/jaegertracing/jaeger-operator/apis/v1"
)

Expand Down Expand Up @@ -140,6 +142,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)
}
Expand Down

0 comments on commit cc61547

Please sign in to comment.