-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add support for wildcard hostname in VirutalServer #2939
Changes from 32 commits
12e74ff
6b738f8
fa2fd08
e66e5da
554292e
8e0ae97
92882bf
1ada9c1
c137caa
99422d7
04f78dc
fa37731
caee7d4
4f96e56
3dd09b0
6c72b3c
bc405c5
0b8d855
d84683b
36c3461
ef31cb3
d26c69f
3b5abb8
acf1821
5a92f83
908782a
a2cb143
0844f32
8cd30af
321856b
b25d676
29a19b9
56aaca2
9d06ca5
c301b4e
0b80f9b
9660ffe
7905670
3ae9c3b
cecc195
a01e7e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ spec: | |
{{% table %}} | ||
|Field | Description | Type | Required | | ||
| ---| ---| ---| --- | | ||
|``host`` | The host (domain name) of the server. Must be a valid subdomain as defined in RFC 1123, such as ``my-app`` or ``hello.example.com``. Wildcard domains like ``*.example.com`` are not allowed. The ``host`` value needs to be unique among all Ingress and VirtualServer resources. See also [Handling Host and Listener Collisions](/nginx-ingress-controller/configuration/handling-host-and-listener-collisions). | ``string`` | Yes | | ||
|``host`` | The host (domain name) of the server. Must be a valid subdomain as defined in RFC 1123, such as ``my-app`` or ``hello.example.com``. When using a wildcard domain like ``*.example.com`` the domain must be contained in double quotes. The ``host`` value needs to be unique among all Ingress and VirtualServer resources. See also [Handling Host and Listener Collisions](/nginx-ingress-controller/configuration/handling-host-and-listener-collisions). | ``string`` | Yes | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I'll check if that's possible or not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't allow two VS resources to be deployed with the same wildcard hostname. Output below is what I got when I tried this:
|
||
|``tls`` | The TLS termination configuration. | [tls](#virtualservertls) | No | | ||
|``externalDNS`` | The externalDNS configuration for a VirtualServer. | [externalDNS](#virtualserverexternaldns) | No | | ||
|``dos`` | A reference to a DosProtectedResource, setting this enables DOS protection of the VirtualServer. | ``string`` | No | | ||
|
@@ -249,7 +249,7 @@ Note that each subroute must have a `path` that starts with the same prefix (her | |
{{% table %}} | ||
|Field | Description | Type | Required | | ||
| ---| ---| ---| --- | | ||
|``host`` | The host (domain name) of the server. Must be a valid subdomain as defined in RFC 1123, such as ``my-app`` or ``hello.example.com``. Wildcard domains like ``*.example.com`` are not allowed. Must be the same as the ``host`` of the VirtualServer that references this resource. | ``string`` | Yes | | ||
|``host`` | The host (domain name) of the server. Must be a valid subdomain as defined in RFC 1123, such as ``my-app`` or ``hello.example.com``. When using a wildcard domain like ``*.example.com`` the domain must be contained in double quotes. Must be the same as the ``host`` of the VirtualServer that references this resource. | ``string`` | Yes | | ||
|``upstreams`` | A list of upstreams. | [[]upstream](#upstream) | No | | ||
|``subroutes`` | A list of subroutes. | [[]subroute](#virtualserverroutesubroute) | No | | ||
|``ingressClassName`` | Specifies which Ingress Controller must handle the VirtualServerRoute resource. Must be the same as the ``ingressClassName`` of the VirtualServer that references this resource. | ``string``_ | No | | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,15 +92,19 @@ func (vsv *VirtualServerValidator) validateVirtualServerSpec(spec *v1.VirtualSer | |
return allErrs | ||
} | ||
|
||
const wildcardHost = "*." | ||
|
||
func validateHost(host string, fieldPath *field.Path) field.ErrorList { | ||
allErrs := field.ErrorList{} | ||
|
||
if host == "" { | ||
return append(allErrs, field.Required(fieldPath, "")) | ||
} | ||
|
||
for _, msg := range validation.IsDNS1123Subdomain(host) { | ||
allErrs = append(allErrs, field.Invalid(fieldPath, host, msg)) | ||
if !strings.HasPrefix(host, wildcardHost) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also validate the wildcard host - we can use see here for reference |
||
for _, msg := range validation.IsDNS1123Subdomain(host) { | ||
allErrs = append(allErrs, field.Invalid(fieldPath, host, msg)) | ||
} | ||
} | ||
|
||
return allErrs | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
apiVersion: k8s.nginx.org/v1 | ||
kind: VirtualServer | ||
metadata: | ||
name: virtual-server-wildcard | ||
spec: | ||
host: "*.example.com" | ||
upstreams: | ||
- name: backend2 | ||
service: backend2-svc | ||
port: 80 | ||
- name: backend1 | ||
service: backend1-svc | ||
port: 80 | ||
routes: | ||
- path: "/backend1" | ||
action: | ||
pass: backend1 | ||
- path: "/backend2" | ||
action: | ||
pass: backend2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import pytest | ||
from settings import TEST_DATA | ||
from suite.custom_assertions import wait_and_assert_status_code | ||
from suite.custom_resources_utils import read_custom_resource | ||
from suite.resources_utils import wait_before_test | ||
from suite.vs_vsr_resources_utils import create_virtual_server_from_yaml, delete_virtual_server | ||
|
||
|
||
@pytest.mark.vs | ||
@pytest.mark.parametrize( | ||
"crd_ingress_controller, virtual_server_setup", | ||
[ | ||
( | ||
{"type": "complete", "extra_args": [f"-enable-custom-resources"]}, | ||
{"example": "virtual-server", "app_type": "simple"}, | ||
) | ||
], | ||
indirect=True, | ||
) | ||
class TestVirtualServerWildcard: | ||
def test_vs_status(self, kube_apis, crd_ingress_controller, virtual_server_setup): | ||
|
||
wait_and_assert_status_code(200, virtual_server_setup.backend_1_url, virtual_server_setup.vs_host) | ||
wait_and_assert_status_code(200, virtual_server_setup.backend_2_url, virtual_server_setup.vs_host) | ||
wait_and_assert_status_code(404, virtual_server_setup.backend_1_url, "test.example.com") | ||
wait_and_assert_status_code(404, virtual_server_setup.backend_2_url, "test.example.com") | ||
|
||
# create virtual server with wildcard hostname | ||
manifest_vs_wc = f"{TEST_DATA}/virtual-server-wildcard/virtual-server-wildcard.yaml" | ||
vs_wc_name = create_virtual_server_from_yaml( | ||
kube_apis.custom_objects, manifest_vs_wc, virtual_server_setup.namespace | ||
) | ||
wait_before_test() | ||
response = read_custom_resource( | ||
kube_apis.custom_objects, | ||
virtual_server_setup.namespace, | ||
"virtualservers", | ||
vs_wc_name, | ||
) | ||
while not response["status"]: | ||
response = read_custom_resource( | ||
kube_apis.custom_objects, | ||
virtual_server_setup.namespace, | ||
"virtualservers", | ||
vs_wc_name, | ||
) | ||
|
||
assert response["status"]["reason"] == "AddedOrUpdated" and response["status"]["state"] == "Valid" | ||
wait_and_assert_status_code(200, virtual_server_setup.backend_1_url, "test.example.com") | ||
wait_and_assert_status_code(200, virtual_server_setup.backend_2_url, "test.example.com") | ||
wait_and_assert_status_code(404, virtual_server_setup.backend_1_url, "test.xexample.com") | ||
wait_and_assert_status_code(404, virtual_server_setup.backend_2_url, "test.xexample.com") | ||
|
||
delete_virtual_server(kube_apis.custom_objects, vs_wc_name, virtual_server_setup.namespace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor one but these 2 annotations can be appended to old list instead of replacing them