Skip to content

Commit 538482d

Browse files
ryanroldsnfuden
andauthored
Improving VHO tests in an attempt to investigate a bug (#10385)
Co-authored-by: Nathan Fudenberg <[email protected]> Co-authored-by: changelog-bot <changelog-bot>
1 parent 2635711 commit 538482d

File tree

9 files changed

+358
-166
lines changed

9 files changed

+358
-166
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
changelog:
2+
- type: NON_USER_FACING
3+
description: |
4+
Strengthed VHO kubernetes/e2e tests. Addressed issue with checking for `content-length`
5+
header in response containing `transfer-encoding: chunked` header.
6+
Added to confirm previously conflicting VHO being accepted after blocker is deleted.
7+
issueLink: https://github.com/k8sgateway/k8sgateway/issues/10310
8+
resolvesIssue: false

test/kubernetes/e2e/features/virtualhost_options/testdata/setup.yaml

+24-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ spec:
1818
namespaces:
1919
from: Same
2020
---
21+
apiVersion: gateway.solo.io/v1
22+
kind: RouteOption
23+
metadata:
24+
name: header-manipulation
25+
spec:
26+
options:
27+
headerManipulation:
28+
responseHeadersToAdd:
29+
- header:
30+
key: "x-bar"
31+
value: "bar"
32+
append: false
33+
- header:
34+
key: "x-baz"
35+
value: "baz"
36+
append: false
37+
---
2138
apiVersion: gateway.networking.k8s.io/v1
2239
kind: HTTPRoute
2340
metadata:
@@ -28,7 +45,13 @@ spec:
2845
hostnames:
2946
- "example.com"
3047
rules:
31-
- backendRefs:
48+
- filters:
49+
- type: ExtensionRef
50+
extensionRef:
51+
group: gateway.solo.io
52+
kind: RouteOption
53+
name: header-manipulation
54+
backendRefs:
3255
- name: example-svc
3356
port: 8080
3457
---
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: gateway.solo.io/v1
22
kind: VirtualHostOption
33
metadata:
4-
name: extra-vho-merge
4+
name: remove-x-baz-merge
55
spec:
66
targetRefs:
77
- group: gateway.networking.k8s.io
@@ -10,5 +10,5 @@ spec:
1010
options:
1111
headerManipulation:
1212
responseHeadersToRemove:
13-
- "content-type"
13+
- "x-baz"
1414
includeAttemptCountInResponse: true
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: gateway.solo.io/v1
22
kind: VirtualHostOption
33
metadata:
4-
name: remove-content-type
4+
name: remove-x-bar-header
55
spec:
66
targetRefs:
77
- group: gateway.networking.k8s.io
@@ -10,4 +10,4 @@ spec:
1010
options:
1111
headerManipulation:
1212
responseHeadersToRemove:
13-
- "content-type"
13+
- "x-bar"
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: gateway.solo.io/v1
22
kind: VirtualHostOption
33
metadata:
4-
name: remove-content-length
4+
name: remove-x-baz-header
55
spec:
66
targetRefs:
77
- group: gateway.networking.k8s.io
@@ -10,4 +10,4 @@ spec:
1010
options:
1111
headerManipulation:
1212
responseHeadersToRemove:
13-
- "content-length"
13+
- "x-baz"
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: gateway.solo.io/v1
22
kind: VirtualHostOption
33
metadata:
4-
name: add-foo-header
4+
name: add-x-foo-header
55
spec:
66
targetRefs:
77
- group: gateway.networking.k8s.io
@@ -12,5 +12,5 @@ spec:
1212
headerManipulation:
1313
responseHeadersToAdd:
1414
- header:
15-
key: foo
16-
value: bar
15+
key: x-foo
16+
value: foo

test/kubernetes/e2e/features/virtualhost_options/types.go

+52-30
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ var (
1919
filepath.Join(util.MustGetThisDir(), "testdata", "setup.yaml"),
2020
e2edefaults.CurlPodManifest,
2121
}
22-
basicVhOManifest = filepath.Join(util.MustGetThisDir(), "testdata", "basic-vho.yaml")
23-
sectionNameVhOManifest = filepath.Join(util.MustGetThisDir(), "testdata", "section-name-vho.yaml")
24-
extraVhOManifest = filepath.Join(util.MustGetThisDir(), "testdata", "extra-vho.yaml")
25-
badVhOManifest = filepath.Join(util.MustGetThisDir(), "testdata", "webhook-reject-bad-vho.yaml")
26-
extraVhOMergeManifest = filepath.Join(util.MustGetThisDir(), "testdata", "extra-vho-merge.yaml")
22+
23+
manifestVhoRemoveXBar = filepath.Join(util.MustGetThisDir(), "testdata", "vho-remove-x-bar.yaml")
24+
manifestVhoSectionAddXFoo = filepath.Join(util.MustGetThisDir(), "testdata", "vho-section-add-x-foo.yaml")
25+
manifestVhoRemoveXBaz = filepath.Join(util.MustGetThisDir(), "testdata", "vho-remove-x-baz.yaml")
26+
manifestVhoWebhookReject = filepath.Join(util.MustGetThisDir(), "testdata", "vho-webhook-reject.yaml")
27+
manifestVhoMergeRemoveXBaz = filepath.Join(util.MustGetThisDir(), "testdata", "vho-merge-remove-x-baz.yaml")
2728

2829
// When we apply the setup file, we expect resources to be created with this metadata
2930
glooProxyObjectMeta = metav1.ObjectMeta{
@@ -50,51 +51,72 @@ var (
5051
},
5152
}
5253

53-
// VirtualHostOption resource to be created
54-
basicVirtualHostOptionMeta = metav1.ObjectMeta{
55-
Name: "remove-content-length",
54+
// VHO to add a x-foo header
55+
vhoRemoveXBar = metav1.ObjectMeta{
56+
Name: "remove-x-bar-header",
5657
Namespace: "default",
5758
}
58-
// Extra VirtualHostOption resource to be created
59-
extraVirtualHostOptionMeta = metav1.ObjectMeta{
60-
Name: "remove-content-type",
59+
// VHO to remove a x-baz header
60+
vhoRemoveXBaz = metav1.ObjectMeta{
61+
Name: "remove-x-baz-header",
6162
Namespace: "default",
6263
}
63-
// Extra VirtualHostOption resource to be created to test merging of options
64-
extraMergeVirtualHostOptionMeta = metav1.ObjectMeta{
65-
Name: "extra-vho-merge",
64+
// VHO to remove a x-baz header
65+
vhoMergeRemoveXBaz = metav1.ObjectMeta{
66+
Name: "remove-x-baz-merge",
6667
Namespace: "default",
6768
}
68-
// SectionName VirtualHostOption resource to be created
69-
sectionNameVirtualHostOptionMeta = metav1.ObjectMeta{
70-
Name: "add-foo-header",
69+
// VHO to add a x-foo header in a section
70+
vhoSectionAddXFoo = metav1.ObjectMeta{
71+
Name: "add-x-foo-header",
7172
Namespace: "default",
7273
}
73-
// Bad VirtualHostOption resource to be created
74-
badVirtualHostOptionMeta = metav1.ObjectMeta{
74+
// VHO that should be rejected by the validating webhook
75+
vhoWebhookReject = metav1.ObjectMeta{
7576
Name: "bad-retries",
7677
Namespace: "default",
7778
}
7879

79-
expectedResponseWithoutContentLength = &matchers.HttpResponse{
80+
// Expects a 200 response with x-bar and x-baz headers
81+
defaultResponse = &matchers.HttpResponse{
82+
StatusCode: http.StatusOK,
83+
Custom: gomega.And(
84+
gomega.Not(matchers.ContainHeaderKeys([]string{"x-foo"})),
85+
matchers.ContainHeaderKeys([]string{"x-bar", "x-baz"}),
86+
),
87+
Body: gstruct.Ignore(),
88+
}
89+
90+
// Expects default response with no x-bar header
91+
expectedResponseWithoutXBar = &matchers.HttpResponse{
8092
StatusCode: http.StatusOK,
81-
Custom: gomega.Not(matchers.ContainHeaderKeys([]string{"content-length"})),
82-
Body: gstruct.Ignore(),
93+
Custom: gomega.And(
94+
gomega.Not(matchers.ContainHeaderKeys([]string{"x-bar"})),
95+
matchers.ContainHeaderKeys([]string{"x-baz"}),
96+
),
97+
Body: gstruct.Ignore(),
8398
}
8499

85-
expectedResponseWithoutContentType = &matchers.HttpResponse{
100+
// Expects default response with no x-baz header
101+
expectedResponseWithoutXBaz = &matchers.HttpResponse{
86102
StatusCode: http.StatusOK,
87-
Custom: gomega.Not(matchers.ContainHeaderKeys([]string{"content-type"})),
88-
Body: gstruct.Ignore(),
103+
Custom: gomega.And(
104+
matchers.ContainHeaderKeys([]string{"x-bar"}),
105+
gomega.Not(matchers.ContainHeaderKeys([]string{"x-baz"})),
106+
),
107+
Body: gstruct.Ignore(),
89108
}
90109

91-
expectedResponseWithFooHeader = &matchers.HttpResponse{
110+
// Expects default response with x-foo header
111+
expectedResponseWithXFoo = &matchers.HttpResponse{
92112
StatusCode: http.StatusOK,
93113
Headers: map[string]interface{}{
94-
"foo": gomega.Equal("bar"),
114+
"x-foo": gomega.Equal("foo"),
95115
},
96-
// Make sure the content-length isn't being removed as a function of the unwanted VHO
97-
Custom: matchers.ContainHeaderKeys([]string{"content-length"}),
98-
Body: gstruct.Ignore(),
116+
// Make sure the x-bar isn't being removed as a function of the unwanted VHO
117+
Custom: gomega.And(
118+
matchers.ContainHeaderKeys([]string{"x-foo", "x-bar", "x-baz"}),
119+
),
120+
Body: gstruct.Ignore(),
99121
}
100122
)

0 commit comments

Comments
 (0)