Skip to content

Commit

Permalink
feat(kuma-cp): top-level MeshHTTPRoute targetRef for MeshTimeout (#7016)
Browse files Browse the repository at this point in the history
Signed-off-by: ilya.lobkov@konghq.com <ilya.lobkov@konghq.com>
  • Loading branch information
lobkovilya authored Jun 14, 2023
1 parent 6952bb4 commit 8c1727c
Show file tree
Hide file tree
Showing 25 changed files with 717 additions and 53 deletions.
33 changes: 33 additions & 0 deletions pkg/plugins/policies/core/matchers/dataplane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,39 @@ var _ = Describe("MatchedPolicies", func() {
generateTableEntries(filepath.Join("testdata", "matchedpolicies", "fromrules")),
)

DescribeTable("should return ToRules",
func(given testCase) {
// given DPP resource
dpp := readDPP(given.dppFile)

// given policies
resources, resTypes := readPolicies(given.policiesFile)

// we're expecting all policies in the file to have the same type or to be mixed with MeshHTTPRoutes
Expect(resTypes).To(Or(HaveLen(1), HaveLen(2)))

var resType core_model.ResourceType
switch {
case len(resTypes) == 1:
resType = resTypes[0]
case len(resTypes) == 2 && resTypes[1] == v1alpha1.MeshHTTPRouteType:
resType = resTypes[0]
case len(resTypes) == 2 && resTypes[0] == v1alpha1.MeshHTTPRouteType:
resType = resTypes[1]
}

// when
policies, err := matchers.MatchedPolicies(resType, dpp, resources)
Expect(err).ToNot(HaveOccurred())

// then
bytes, err := yaml.Marshal(policies.ToRules)
Expect(err).ToNot(HaveOccurred())
Expect(bytes).To(test_matchers.MatchGoldenYAML(given.goldenFile))
},
generateTableEntries(filepath.Join("testdata", "matchedpolicies", "torules")),
)

DescribeTable("should match MeshGateways",
func(given testCase) {
dpp := readDPP(given.dppFile)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type: Dataplane
mesh: mesh-1
name: dp-1
networking:
address: 1.1.1.1
inbound:
- port: 8080
tags:
kuma.io/service: web
version: v1
team: mesh
- port: 8081
tags:
kuma.io/service: web-api
version: v1
team: mesh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
items:
- creationTime: "0001-01-01T00:00:00Z"
mesh: mesh-1
modificationTime: "0001-01-01T00:00:00Z"
name: mtp-1
spec:
targetRef:
kind: MeshHTTPRoute
name: http-route-1
to:
- default:
http:
requestTimeout: 3s
targetRef:
kind: Mesh
type: MeshTimeout
next: null
total: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# mtp-1 should select DPP because it targets MeshHTTPRoute that selects the DPP
type: MeshTimeout
mesh: mesh-1
name: mtp-1
spec:
targetRef:
kind: MeshHTTPRoute
name: http-route-1
to:
- targetRef:
kind: Mesh
default:
http:
requestTimeout: 3s
---
type: MeshHTTPRoute
mesh: mesh-1
name: http-route-1
spec:
targetRef:
kind: MeshService
name: web-api
to:
- targetRef:
kind: MeshService
name: test-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type: Dataplane
mesh: mesh-1
name: dp-1
networking:
address: 1.1.1.1
inbound:
- port: 8080
tags:
kuma.io/service: web
version: v1
team: mesh
- port: 8081
tags:
kuma.io/service: web-api
version: v1
team: mesh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Rules:
- Conf:
http:
requestTimeout: 3s
Origin:
- creationTime: "0001-01-01T00:00:00Z"
mesh: mesh-1
modificationTime: "0001-01-01T00:00:00Z"
name: mtp-1
type: MeshTimeout
Subset:
- Key: __rule-matches-hash__
Not: false
Value: OTqJZOueoDIMeYnpSETLYoaD2htefPQ7CcHHRBgrODk=
- Key: kuma.io/service
Not: false
Value: another-test-server
- Conf:
http:
requestTimeout: 3s
Origin:
- creationTime: "0001-01-01T00:00:00Z"
mesh: mesh-1
modificationTime: "0001-01-01T00:00:00Z"
name: mtp-1
type: MeshTimeout
Subset:
- Key: __rule-matches-hash__
Not: false
Value: JNNc6//C3P17nUsOJm5f4kqG+U3v8pXhS0od9C3+oss=
- Key: kuma.io/service
Not: false
Value: test-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
type: MeshHTTPRoute
mesh: mesh-1
name: http-route-1
spec:
targetRef:
kind: MeshService
name: web-api
to:
- targetRef:
kind: MeshService
name: test-server
rules:
- matches:
- path:
type: Exact
value: /
default: {}
- targetRef:
kind: MeshService
name: another-test-server
rules:
- matches:
- path:
type: PathPrefix
value: /v1
- method: POST
default: {}
---
# mtp-1 should select DPP because it targets MeshHTTPRoute that selects the DPP
type: MeshTimeout
mesh: mesh-1
name: mtp-1
spec:
targetRef:
kind: MeshHTTPRoute
name: http-route-1
to:
- targetRef:
kind: Mesh
default:
http:
requestTimeout: 3s

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type: Dataplane
mesh: mesh-1
name: dp-1
networking:
address: 1.1.1.1
inbound:
- port: 8080
tags:
kuma.io/service: web
version: v1
team: mesh
- port: 8081
tags:
kuma.io/service: web-api
version: v1
team: mesh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Rules:
- Conf:
http:
requestTimeout: 1s
Origin:
- creationTime: "0001-01-01T00:00:00Z"
mesh: mesh-1
modificationTime: "0001-01-01T00:00:00Z"
name: mtp-1
type: MeshTimeout
Subset:
- Key: __rule-matches-hash__
Not: false
Value: OTqJZOueoDIMeYnpSETLYoaD2htefPQ7CcHHRBgrODk=
- Key: kuma.io/service
Not: false
Value: another-test-server
- Conf:
http:
requestTimeout: 3s
Origin:
- creationTime: "0001-01-01T00:00:00Z"
mesh: mesh-1
modificationTime: "0001-01-01T00:00:00Z"
name: mtp-1
type: MeshTimeout
- creationTime: "0001-01-01T00:00:00Z"
mesh: mesh-1
modificationTime: "0001-01-01T00:00:00Z"
name: mtp-2
type: MeshTimeout
Subset:
- Key: __rule-matches-hash__
Not: false
Value: JNNc6//C3P17nUsOJm5f4kqG+U3v8pXhS0od9C3+oss=
- Key: kuma.io/service
Not: false
Value: test-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
type: MeshHTTPRoute
mesh: mesh-1
name: http-route-1
spec:
targetRef:
kind: MeshService
name: web-api
to:
- targetRef:
kind: MeshService
name: test-server
rules:
- matches:
- path:
type: Exact
value: /
default: {}
- targetRef:
kind: MeshService
name: another-test-server
rules:
- matches:
- path:
type: PathPrefix
value: /v1
- method: POST
default: {}
---
type: MeshHTTPRoute
mesh: mesh-1
name: http-route-2
spec:
targetRef:
kind: MeshService
name: web-api
to:
- targetRef:
kind: MeshService
name: test-server
rules:
- matches:
- path:
type: Exact
value: /
default: {}
---
# mtp-1 should select DPP because it targets MeshHTTPRoute that selects the DPP
type: MeshTimeout
mesh: mesh-1
name: mtp-1
spec:
targetRef:
kind: MeshHTTPRoute
name: http-route-1
to:
- targetRef:
kind: Mesh
default:
http:
requestTimeout: 1s
---
type: MeshTimeout
mesh: mesh-1
name: mtp-2
spec:
targetRef:
kind: MeshHTTPRoute
name: http-route-2
to:
- targetRef:
kind: Mesh
default:
http:
requestTimeout: 3s
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type: Dataplane
mesh: mesh-1
name: dp-1
networking:
address: 1.1.1.1
inbound:
- port: 8080
tags:
kuma.io/service: web
version: v1
team: mesh
- port: 8081
tags:
kuma.io/service: web-api
version: v1
team: mesh
Loading

0 comments on commit 8c1727c

Please sign in to comment.