-
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.
Add test for TransportServer load balancing config
- Loading branch information
Showing
6 changed files
with
191 additions
and
6 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
35 changes: 35 additions & 0 deletions
35
tests/data/transport-server-tcp-load-balance/more-replicas.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,35 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: coredns | ||
spec: | ||
replicas: 3 | ||
selector: | ||
matchLabels: | ||
app: coredns | ||
template: | ||
metadata: | ||
labels: | ||
app: coredns | ||
spec: | ||
containers: | ||
- name: coredns | ||
image: coredns/coredns:1.6.7 | ||
args: [ "-conf", "/etc/coredns/Corefile" ] | ||
volumeMounts: | ||
- name: config-volume | ||
mountPath: /etc/coredns | ||
readOnly: true | ||
ports: | ||
- containerPort: 5353 | ||
name: dns-tcp | ||
protocol: TCP | ||
securityContext: | ||
readOnlyRootFilesystem: true | ||
volumes: | ||
- name: config-volume | ||
configMap: | ||
name: coredns | ||
items: | ||
- key: Corefile | ||
path: Corefile |
35 changes: 35 additions & 0 deletions
35
tests/data/transport-server-tcp-load-balance/standard/dns.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,35 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: coredns | ||
spec: | ||
replicas: 2 | ||
selector: | ||
matchLabels: | ||
app: coredns | ||
template: | ||
metadata: | ||
labels: | ||
app: coredns | ||
spec: | ||
containers: | ||
- name: coredns | ||
image: coredns/coredns:1.6.7 | ||
args: [ "-conf", "/etc/coredns/Corefile" ] | ||
volumeMounts: | ||
- name: config-volume | ||
mountPath: /etc/coredns | ||
readOnly: true | ||
ports: | ||
- containerPort: 5353 | ||
name: dns-tcp | ||
protocol: TCP | ||
securityContext: | ||
readOnlyRootFilesystem: true | ||
volumes: | ||
- name: config-volume | ||
configMap: | ||
name: coredns | ||
items: | ||
- key: Corefile | ||
path: Corefile |
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
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,64 @@ | ||
import pytest | ||
import re | ||
from settings import TEST_DATA | ||
from suite.resources_utils import get_ingress_nginx_template_ts_conf | ||
from suite.resources_utils import ( | ||
wait_before_test, | ||
patch_deployment_from_yaml | ||
) | ||
|
||
|
||
@pytest.mark.ts | ||
@pytest.mark.parametrize( | ||
"crd_ingress_controller, transport_server_setup", | ||
[ | ||
( | ||
{ | ||
"type": "complete", | ||
"extra_args": | ||
[ | ||
"-enable-custom-resources", | ||
"-global-configuration=nginx-ingress/nginx-configuration", | ||
"-enable-leader-election=false" | ||
] | ||
}, | ||
{"example": "transport-server-status", "app_type": "simple"}, | ||
) | ||
], | ||
indirect=True, | ||
) | ||
class TestTransportServerTcpLoadBalance: | ||
|
||
def restore_service(self, kube_apis, transport_server_setup) -> None: | ||
""" | ||
Function to revert a TransportServer resource to a valid state. | ||
""" | ||
dns_file = f"{TEST_DATA}/transport-server-tcp-load-balance/standard/dns.yaml" | ||
patch_deployment_from_yaml(kube_apis.apps_v1_api, transport_server_setup.namespace, dns_file) | ||
|
||
@pytest.mark.sean | ||
def test_number_of_replicas( | ||
self, kube_apis, crd_ingress_controller, transport_server_setup, ingress_controller_prerequisites | ||
): | ||
""" | ||
The load balancing of TCP should result in 3 servers to match the 3 replicas of a service. | ||
""" | ||
dns_file = f"{TEST_DATA}/transport-server-tcp-load-balance/more-replicas.yaml" | ||
patch_deployment_from_yaml(kube_apis.apps_v1_api, transport_server_setup.namespace, dns_file) | ||
|
||
wait_before_test() | ||
|
||
result_conf = get_ingress_nginx_template_ts_conf( | ||
kube_apis.v1, | ||
transport_server_setup.namespace, | ||
transport_server_setup.name, | ||
transport_server_setup.ingress_pod_name, | ||
ingress_controller_prerequisites.namespace | ||
) | ||
|
||
pattern = 'server.*max_fails=1 fail_timeout=10s;' | ||
num_servers = len(re.findall(pattern, result_conf)) | ||
|
||
assert num_servers is 3 | ||
|
||
self.restore_service(kube_apis, transport_server_setup) |