Skip to content

Commit

Permalink
Improving VHO tests in an attempt to investigate a bug (#10385)
Browse files Browse the repository at this point in the history
Co-authored-by: Nathan Fudenberg <[email protected]>
Co-authored-by: changelog-bot <changelog-bot>
  • Loading branch information
ryanrolds and nfuden authored Nov 26, 2024
1 parent 2635711 commit 538482d
Show file tree
Hide file tree
Showing 9 changed files with 358 additions and 166 deletions.
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
82 changes: 52 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,72 @@ 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", "x-baz"}),
),
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", "x-bar", "x-baz"}),
),
Body: gstruct.Ignore(),
}
)
Loading

0 comments on commit 538482d

Please sign in to comment.