Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving VHO tests in an attempt to investigate a bug #10385

Merged
merged 25 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b3771ca
Improving tests in an attempt to better expose the underlying bug
ryanrolds Nov 21, 2024
80fb3e2
Comments and renamed a function
ryanrolds Nov 21, 2024
f675dde
Test adjustments
ryanrolds Nov 21, 2024
2788f08
Added changelog
ryanrolds Nov 21, 2024
442e488
Moved changelog
ryanrolds Nov 21, 2024
d07708f
Fixing issue with test failure
ryanrolds Nov 22, 2024
c4a1aac
Merge branch 'main' into rolds/cleanup_vhost_opts_suite
ryanrolds Nov 22, 2024
87f1c4c
Adjusting how I'm applying a resource that is expected to fail
ryanrolds Nov 22, 2024
7dd22dd
Merge branch 'rolds/cleanup_vhost_opts_suite' of ssh://github.com/sol…
ryanrolds Nov 22, 2024
f985e4b
Merge branch 'main' into rolds/cleanup_vhost_opts_suite
ryanrolds Nov 22, 2024
cf6ad8c
Merge branch 'main' into rolds/cleanup_vhost_opts_suite
ryanrolds Nov 22, 2024
e8d06e2
Trying to address issue with rejection test
ryanrolds Nov 22, 2024
f063979
Merge branch 'rolds/cleanup_vhost_opts_suite' of ssh://github.com/sol…
ryanrolds Nov 22, 2024
c70d642
Fixed issue with checking wrong resource is deleted
ryanrolds Nov 22, 2024
46745ee
Merge branch 'main' into rolds/cleanup_vhost_opts_suite
ryanrolds Nov 22, 2024
7b072bc
Merge branch 'main' into rolds/cleanup_vhost_opts_suite
nfuden Nov 25, 2024
1cef969
Merge branch 'main' into rolds/cleanup_vhost_opts_suite
ryanrolds Nov 25, 2024
a9e3343
Adding changelog file to new location
Nov 25, 2024
a22f7d6
Deleting changelog file from old location
Nov 25, 2024
7d6a543
Merge branch 'main' into rolds/cleanup_vhost_opts_suite
ryanrolds Nov 25, 2024
9f78bc7
Merge branch 'main' into rolds/cleanup_vhost_opts_suite
ryanrolds Nov 26, 2024
7d8598b
Merge branch 'main' into rolds/cleanup_vhost_opts_suite
ryanrolds Nov 26, 2024
2b93f93
Merge branch 'main' into rolds/cleanup_vhost_opts_suite
ryanrolds Nov 26, 2024
fb62a25
Merged assertions
ryanrolds Nov 26, 2024
2549794
Merge branch 'main' into rolds/cleanup_vhost_opts_suite
ryanrolds Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog/v1.18.0-rc3/vho-test-hardening.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
changelog:
- type: NON_USER_FACING
description: |
Strengthed VHO kubernetes/e2e tests. Addressed issue with checking for `content-length`
header in response containing `transfer-encoding: chunked` header.
Added to confirm previously conflicting VHO being accepted after blocker is deleted.
issueLink: https://github.com/k8sgateway/k8sgateway/issues/10310
resolvesIssue: false
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ spec:
namespaces:
from: Same
---
apiVersion: gateway.solo.io/v1
kind: RouteOption
metadata:
name: header-manipulation
spec:
options:
headerManipulation:
responseHeadersToAdd:
- header:
key: "x-bar"
value: "bar"
append: false
- header:
key: "x-baz"
value: "baz"
append: false
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
Expand All @@ -28,7 +45,13 @@ spec:
hostnames:
- "example.com"
rules:
- backendRefs:
- filters:
- type: ExtensionRef
extensionRef:
group: gateway.solo.io
kind: RouteOption
name: header-manipulation
backendRefs:
- name: example-svc
port: 8080
---
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: gateway.solo.io/v1
kind: VirtualHostOption
metadata:
name: extra-vho-merge
name: remove-x-baz-merge
spec:
targetRefs:
- group: gateway.networking.k8s.io
Expand All @@ -10,5 +10,5 @@ spec:
options:
headerManipulation:
responseHeadersToRemove:
- "content-type"
- "x-baz"
includeAttemptCountInResponse: true
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: gateway.solo.io/v1
kind: VirtualHostOption
metadata:
name: remove-content-type
name: remove-x-bar-header
spec:
targetRefs:
- group: gateway.networking.k8s.io
Expand All @@ -10,4 +10,4 @@ spec:
options:
headerManipulation:
responseHeadersToRemove:
- "content-type"
- "x-bar"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: gateway.solo.io/v1
kind: VirtualHostOption
metadata:
name: remove-content-length
name: remove-x-baz-header
spec:
targetRefs:
- group: gateway.networking.k8s.io
Expand All @@ -10,4 +10,4 @@ spec:
options:
headerManipulation:
responseHeadersToRemove:
- "content-length"
- "x-baz"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: gateway.solo.io/v1
kind: VirtualHostOption
metadata:
name: add-foo-header
name: add-x-foo-header
spec:
targetRefs:
- group: gateway.networking.k8s.io
Expand All @@ -12,5 +12,5 @@ spec:
headerManipulation:
responseHeadersToAdd:
- header:
key: foo
value: bar
key: x-foo
value: foo
85 changes: 55 additions & 30 deletions test/kubernetes/e2e/features/virtualhost_options/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ var (
filepath.Join(util.MustGetThisDir(), "testdata", "setup.yaml"),
e2edefaults.CurlPodManifest,
}
basicVhOManifest = filepath.Join(util.MustGetThisDir(), "testdata", "basic-vho.yaml")
sectionNameVhOManifest = filepath.Join(util.MustGetThisDir(), "testdata", "section-name-vho.yaml")
extraVhOManifest = filepath.Join(util.MustGetThisDir(), "testdata", "extra-vho.yaml")
badVhOManifest = filepath.Join(util.MustGetThisDir(), "testdata", "webhook-reject-bad-vho.yaml")
extraVhOMergeManifest = filepath.Join(util.MustGetThisDir(), "testdata", "extra-vho-merge.yaml")

manifestVhoRemoveXBar = filepath.Join(util.MustGetThisDir(), "testdata", "vho-remove-x-bar.yaml")
manifestVhoSectionAddXFoo = filepath.Join(util.MustGetThisDir(), "testdata", "vho-section-add-x-foo.yaml")
manifestVhoRemoveXBaz = filepath.Join(util.MustGetThisDir(), "testdata", "vho-remove-x-baz.yaml")
manifestVhoWebhookReject = filepath.Join(util.MustGetThisDir(), "testdata", "vho-webhook-reject.yaml")
manifestVhoMergeRemoveXBaz = filepath.Join(util.MustGetThisDir(), "testdata", "vho-merge-remove-x-baz.yaml")

// When we apply the setup file, we expect resources to be created with this metadata
glooProxyObjectMeta = metav1.ObjectMeta{
Expand All @@ -50,51 +51,75 @@ var (
},
}

// VirtualHostOption resource to be created
basicVirtualHostOptionMeta = metav1.ObjectMeta{
Name: "remove-content-length",
// VHO to add a x-foo header
vhoRemoveXBar = metav1.ObjectMeta{
Name: "remove-x-bar-header",
Namespace: "default",
}
// Extra VirtualHostOption resource to be created
extraVirtualHostOptionMeta = metav1.ObjectMeta{
Name: "remove-content-type",
// VHO to remove a x-baz header
vhoRemoveXBaz = metav1.ObjectMeta{
Name: "remove-x-baz-header",
Namespace: "default",
}
// Extra VirtualHostOption resource to be created to test merging of options
extraMergeVirtualHostOptionMeta = metav1.ObjectMeta{
Name: "extra-vho-merge",
// VHO to remove a x-baz header
vhoMergeRemoveXBaz = metav1.ObjectMeta{
Name: "remove-x-baz-merge",
Namespace: "default",
}
// SectionName VirtualHostOption resource to be created
sectionNameVirtualHostOptionMeta = metav1.ObjectMeta{
Name: "add-foo-header",
// VHO to add a x-foo header in a section
vhoSectionAddXFoo = metav1.ObjectMeta{
Name: "add-x-foo-header",
Namespace: "default",
}
// Bad VirtualHostOption resource to be created
badVirtualHostOptionMeta = metav1.ObjectMeta{
// VHO that should be rejected by the validating webhook
vhoWebhookReject = metav1.ObjectMeta{
Name: "bad-retries",
Namespace: "default",
}

expectedResponseWithoutContentLength = &matchers.HttpResponse{
// Expects a 200 response with x-bar and x-baz headers
defaultResponse = &matchers.HttpResponse{
StatusCode: http.StatusOK,
Custom: gomega.And(
gomega.Not(matchers.ContainHeaderKeys([]string{"x-foo"})),
matchers.ContainHeaderKeys([]string{"x-bar"}),
matchers.ContainHeaderKeys([]string{"x-baz"}),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Since the ContainHeaderKeys matcher supports a list, any reason we don't combine these into a single assertion?

),
Body: gstruct.Ignore(),
}

// Expects default response with no x-bar header
expectedResponseWithoutXBar = &matchers.HttpResponse{
StatusCode: http.StatusOK,
Custom: gomega.Not(matchers.ContainHeaderKeys([]string{"content-length"})),
Body: gstruct.Ignore(),
Custom: gomega.And(
gomega.Not(matchers.ContainHeaderKeys([]string{"x-bar"})),
matchers.ContainHeaderKeys([]string{"x-baz"}),
),
Body: gstruct.Ignore(),
}

expectedResponseWithoutContentType = &matchers.HttpResponse{
// Expects default response with no x-baz header
expectedResponseWithoutXBaz = &matchers.HttpResponse{
StatusCode: http.StatusOK,
Custom: gomega.Not(matchers.ContainHeaderKeys([]string{"content-type"})),
Body: gstruct.Ignore(),
Custom: gomega.And(
matchers.ContainHeaderKeys([]string{"x-bar"}),
gomega.Not(matchers.ContainHeaderKeys([]string{"x-baz"})),
),
Body: gstruct.Ignore(),
}

expectedResponseWithFooHeader = &matchers.HttpResponse{
// Expects default response with x-foo header
expectedResponseWithXFoo = &matchers.HttpResponse{
StatusCode: http.StatusOK,
Headers: map[string]interface{}{
"foo": gomega.Equal("bar"),
"x-foo": gomega.Equal("foo"),
},
// Make sure the content-length isn't being removed as a function of the unwanted VHO
Custom: matchers.ContainHeaderKeys([]string{"content-length"}),
Body: gstruct.Ignore(),
// Make sure the x-bar isn't being removed as a function of the unwanted VHO
Custom: gomega.And(
matchers.ContainHeaderKeys([]string{"x-foo"}),
matchers.ContainHeaderKeys([]string{"x-bar"}),
matchers.ContainHeaderKeys([]string{"x-baz"}),
),
Body: gstruct.Ignore(),
}
)
Loading
Loading