-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix udp/http listener validation logic (#6406)
* fix udp/http listener validation logic * lint and change field name * fix listener validation algo * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove values.yaml change * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix test * add more tests * remove commented out listener * fix test * delete comment * improve error message for duplicate ip port protocol combination --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Jakub Jarosz <[email protected]>
- Loading branch information
1 parent
1dbc8eb
commit 5e96dd2
Showing
7 changed files
with
218 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
tests/data/udp-http-listeners-together/global-configuration.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: k8s.nginx.org/v1 | ||
kind: GlobalConfiguration | ||
metadata: | ||
name: nginx-configuration | ||
namespace: nginx-ingress | ||
spec: | ||
listeners: | ||
- name: udp-listener | ||
port: 5454 | ||
protocol: UDP | ||
- name: http-listener | ||
port: 5454 | ||
protocol: HTTP |
14 changes: 14 additions & 0 deletions
14
tests/data/udp-http-listeners-together/transport-server.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: k8s.nginx.org/v1 | ||
kind: TransportServer | ||
metadata: | ||
name: transport-server | ||
spec: | ||
listener: | ||
name: udp-listener | ||
protocol: UDP | ||
upstreams: | ||
- name: dns-app | ||
service: coredns | ||
port: 5353 | ||
action: | ||
pass: dns-app |
22 changes: 22 additions & 0 deletions
22
tests/data/udp-http-listeners-together/virtual-server.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
apiVersion: k8s.nginx.org/v1 | ||
kind: VirtualServer | ||
metadata: | ||
name: virtual-server-status | ||
spec: | ||
listener: | ||
http: http-listener | ||
host: virtual-server-status.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import time | ||
|
||
import pytest | ||
from settings import TEST_DATA | ||
from suite.utils.custom_resources_utils import ( | ||
create_ts_from_yaml, | ||
delete_ts, | ||
patch_gc_from_yaml, | ||
read_custom_resource, | ||
read_ts, | ||
) | ||
from suite.utils.resources_utils import get_first_pod_name, get_ts_nginx_template_conf, wait_before_test | ||
from suite.utils.vs_vsr_resources_utils import get_vs_nginx_template_conf, patch_virtual_server_from_yaml | ||
|
||
|
||
@pytest.mark.vs | ||
@pytest.mark.ts | ||
@pytest.mark.parametrize( | ||
"crd_ingress_controller, virtual_server_setup, transport_server_setup", | ||
[ | ||
( | ||
{ | ||
"type": "complete", | ||
"extra_args": [ | ||
"-enable-custom-resources", | ||
"-global-configuration=nginx-ingress/nginx-configuration", | ||
], | ||
}, | ||
{"example": "virtual-server-status", "app_type": "simple"}, | ||
{"example": "transport-server-status", "app_type": "simple"}, | ||
) | ||
], | ||
indirect=True, | ||
) | ||
class TestUDPandHTTPListenersTogether: | ||
def test_udp_and_http_listeners_together( | ||
self, | ||
kube_apis, | ||
ingress_controller_prerequisites, | ||
crd_ingress_controller, | ||
virtual_server_setup, | ||
transport_server_setup, | ||
): | ||
|
||
wait_before_test() | ||
existing_ts = read_ts(kube_apis.custom_objects, transport_server_setup.namespace, transport_server_setup.name) | ||
delete_ts(kube_apis.custom_objects, existing_ts, transport_server_setup.namespace) | ||
|
||
global_config_file = f"{TEST_DATA}/udp-http-listeners-together/global-configuration.yaml" | ||
transport_server_file = f"{TEST_DATA}/udp-http-listeners-together/transport-server.yaml" | ||
virtual_server_file = f"{TEST_DATA}/udp-http-listeners-together/virtual-server.yaml" | ||
gc_resource_name = "nginx-configuration" | ||
gc_namespace = "nginx-ingress" | ||
|
||
patch_gc_from_yaml(kube_apis.custom_objects, gc_resource_name, global_config_file, gc_namespace) | ||
create_ts_from_yaml(kube_apis.custom_objects, transport_server_file, transport_server_setup.namespace) | ||
patch_virtual_server_from_yaml( | ||
kube_apis.custom_objects, "virtual-server-status", virtual_server_file, virtual_server_setup.namespace | ||
) | ||
wait_before_test() | ||
|
||
ic_pod_name = get_first_pod_name(kube_apis.v1, ingress_controller_prerequisites.namespace) | ||
ts_config = get_ts_nginx_template_conf( | ||
kube_apis.v1, | ||
transport_server_setup.namespace, | ||
transport_server_setup.name, | ||
ic_pod_name, | ||
ingress_controller_prerequisites.namespace, | ||
) | ||
vs_config = get_vs_nginx_template_conf( | ||
kube_apis.v1, | ||
virtual_server_setup.namespace, | ||
virtual_server_setup.vs_name, | ||
ic_pod_name, | ||
ingress_controller_prerequisites.namespace, | ||
) | ||
assert "listen 5454;" in vs_config | ||
assert "listen 5454 udp;" in ts_config | ||
|
||
for _ in range(30): | ||
transport_server_response = read_custom_resource( | ||
kube_apis.custom_objects, | ||
transport_server_setup.namespace, | ||
"transportservers", | ||
"transport-server", | ||
) | ||
if "status" in transport_server_response and transport_server_response["status"]["state"] == "Valid": | ||
break | ||
time.sleep(1) | ||
else: | ||
pytest.fail("TransportServer status did not become 'Valid' within the timeout period") | ||
|
||
for _ in range(30): | ||
virtual_server_response = read_custom_resource( | ||
kube_apis.custom_objects, | ||
virtual_server_setup.namespace, | ||
"virtualservers", | ||
"virtual-server-status", | ||
) | ||
if "status" in virtual_server_response and virtual_server_response["status"]["state"] == "Valid": | ||
break | ||
time.sleep(1) | ||
else: | ||
pytest.fail("VirtualServer status did not become 'Valid' within the timeout period") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters