diff --git a/docs/content/logging-and-monitoring/prometheus.md b/docs/content/logging-and-monitoring/prometheus.md index e43c19fa8a..2f0f4b0cd9 100644 --- a/docs/content/logging-and-monitoring/prometheus.md +++ b/docs/content/logging-and-monitoring/prometheus.md @@ -49,6 +49,7 @@ The Ingress Controller exports the following metrics: * `controller_ingress_resources_total`. Number of handled Ingress resources. This metric includes the label type, that groups the Ingress resources by their type (regular, [minion or master](/nginx-ingress-controller/configuration/ingress-resources/cross-namespace-configuration)). **Note**: The metric doesn't count minions without a master. * `controller_virtualserver_resources_total`. Number of handled VirtualServer resources. * `controller_virtualserverroute_resources_total`. Number of handled VirtualServerRoute resources. **Note**: The metric counts only VirtualServerRoutes that have a reference from a VirtualServer. + * `controller_transportserver_resources_total`. Number of handled TransportServer resources. This metric includes the label type, that groups the TransportServer resources by their type (passthrough, tcp or udp). * Workqueue metrics. **Note**: the workqueue is a queue used by the Ingress Controller to process changes to the relevant resources in the cluster like Ingress resources. The Ingress Controller uses only one queue. The metrics for that queue will have the label `name="taskQueue"` * `workqueue_depth`. Current depth of the workqueue. * `workqueue_queue_duration_second`. How long in seconds an item stays in the workqueue before being requested. diff --git a/internal/k8s/configuration.go b/internal/k8s/configuration.go index a387c4828e..d4102bde95 100644 --- a/internal/k8s/configuration.go +++ b/internal/k8s/configuration.go @@ -312,6 +312,13 @@ func compareObjectMetasWithAnnotations(meta1 *metav1.ObjectMeta, meta2 *metav1.O return compareObjectMetas(meta1, meta2) && reflect.DeepEqual(meta1.Annotations, meta2.Annotations) } +// TransportServerMetrics holds metrics about TransportServer resources +type TransportServerMetrics struct { + TotalTLSPassthrough int + TotalTCP int + TotalUDP int +} + // Configuration represents the configuration of the Ingress Controller - a collection of configuration objects // (Ingresses, VirtualServers, VirtualServerRoutes) ready to be transformed into NGINX config. // It holds the latest valid state of those objects. @@ -1442,6 +1449,30 @@ func (c *Configuration) buildVirtualServerRoutes(vs *conf_v1.VirtualServer) ([]* return vsrs, warnings } +// GetTransportServerMetrics returns metrics about TransportServers +func (c *Configuration) GetTransportServerMetrics() *TransportServerMetrics { + var metrics TransportServerMetrics + + if c.isTLSPassthroughEnabled { + for _, resource := range c.hosts { + _, ok := resource.(*TransportServerConfiguration) + if ok { + metrics.TotalTLSPassthrough++ + } + } + } + + for _, tsConfig := range c.listeners { + if tsConfig.TransportServer.Spec.Listener.Protocol == "TCP" { + metrics.TotalTCP++ + } else { + metrics.TotalUDP++ + } + } + + return &metrics +} + func getSortedIngressKeys(m map[string]*networking.Ingress) []string { var keys []string diff --git a/internal/k8s/configuration_test.go b/internal/k8s/configuration_test.go index 3beaf172ed..4e2723a479 100644 --- a/internal/k8s/configuration_test.go +++ b/internal/k8s/configuration_test.go @@ -3256,6 +3256,104 @@ func TestGetResources(t *testing.T) { } } +func TestGetTransportServerMetrics(t *testing.T) { + tsPass := createTestTLSPassthroughTransportServer("transportserver", "abc.example.com") + tsTCP := createTestTransportServer("transportserver-tcp", "tcp-7777", "TCP") + tsUDP := createTestTransportServer("transportserver-udp", "udp-7777", "UDP") + + tests := []struct { + tses []*conf_v1alpha1.TransportServer + expected *TransportServerMetrics + msg string + }{ + { + tses: nil, + expected: &TransportServerMetrics{ + TotalTLSPassthrough: 0, + TotalTCP: 0, + TotalUDP: 0, + }, + msg: "no TransportServers", + }, + { + tses: []*conf_v1alpha1.TransportServer{ + tsPass, + }, + expected: &TransportServerMetrics{ + TotalTLSPassthrough: 1, + TotalTCP: 0, + TotalUDP: 0, + }, + msg: "one TLSPassthrough TransportServer", + }, + { + tses: []*conf_v1alpha1.TransportServer{ + tsTCP, + }, + expected: &TransportServerMetrics{ + TotalTLSPassthrough: 0, + TotalTCP: 1, + TotalUDP: 0, + }, + msg: "one TCP TransportServer", + }, + { + tses: []*conf_v1alpha1.TransportServer{ + tsUDP, + }, + expected: &TransportServerMetrics{ + TotalTLSPassthrough: 0, + TotalTCP: 0, + TotalUDP: 1, + }, + msg: "one UDP TransportServer", + }, + { + tses: []*conf_v1alpha1.TransportServer{ + tsPass, tsTCP, tsUDP, + }, + expected: &TransportServerMetrics{ + TotalTLSPassthrough: 1, + TotalTCP: 1, + TotalUDP: 1, + }, + msg: "TLSPasstrough, TCP and UDP TransportServers", + }, + } + + listeners := []conf_v1alpha1.Listener{ + { + Name: "tcp-7777", + Port: 7777, + Protocol: "TCP", + }, + { + Name: "udp-7777", + Port: 7777, + Protocol: "UDP", + }, + } + gc := createTestGlobalConfiguration(listeners) + + for _, test := range tests { + configuration := createTestConfiguration() + + _, _, err := configuration.AddOrUpdateGlobalConfiguration(gc) + if err != nil { + t.Fatalf("AddOrUpdateGlobalConfiguration() returned unexpected error %v", err) + } + + for _, ts := range test.tses { + configuration.AddOrUpdateTransportServer(ts) + } + + result := configuration.GetTransportServerMetrics() + if diff := cmp.Diff(test.expected, result); diff != "" { + t.Errorf("GetTransportServerMetrics() returned unexpected result for the case of %s (-want +got):\n%s", test.msg, diff) + } + } +} + func TestIsEqualForIngressConfigurationes(t *testing.T) { regularIng := createTestIngress("regular-ingress", "foo.example.com") diff --git a/internal/k8s/controller.go b/internal/k8s/controller.go index 58abf624e5..15a8c5d6ba 100644 --- a/internal/k8s/controller.go +++ b/internal/k8s/controller.go @@ -315,7 +315,6 @@ func NewLoadBalancerController(input NewLoadBalancerControllerInput) *LoadBalanc lbc.secretStore = secrets.NewLocalSecretStore(lbc.configurator) - lbc.updateIngressMetrics() return lbc } @@ -712,6 +711,7 @@ func (lbc *LoadBalancerController) sync(task task) { case ingress: lbc.syncIngress(task) lbc.updateIngressMetrics() + lbc.updateTransportServerMetrics() case configMap: lbc.syncConfigMap(task) case endpoints: @@ -723,13 +723,16 @@ func (lbc *LoadBalancerController) sync(task task) { case virtualserver: lbc.syncVirtualServer(task) lbc.updateVirtualServerMetrics() + lbc.updateTransportServerMetrics() case virtualServerRoute: lbc.syncVirtualServerRoute(task) lbc.updateVirtualServerMetrics() case globalConfiguration: lbc.syncGlobalConfiguration(task) + lbc.updateTransportServerMetrics() case transportserver: lbc.syncTransportServer(task) + lbc.updateTransportServerMetrics() case policy: lbc.syncPolicy(task) case appProtectPolicy: @@ -1638,6 +1641,15 @@ func (lbc *LoadBalancerController) updateVirtualServerMetrics() { lbc.metricsCollector.SetVirtualServerRoutes(vsrCount) } +func (lbc *LoadBalancerController) updateTransportServerMetrics() { + if !lbc.areCustomResourcesEnabled { + return + } + + metrics := lbc.configuration.GetTransportServerMetrics() + lbc.metricsCollector.SetTransportServers(metrics.TotalTLSPassthrough, metrics.TotalTCP, metrics.TotalUDP) +} + func (lbc *LoadBalancerController) syncService(task task) { key := task.Key glog.V(3).Infof("Syncing service %v", key) diff --git a/internal/metrics/collectors/controller.go b/internal/metrics/collectors/controller.go index b66a1995dc..5c89aab4e0 100644 --- a/internal/metrics/collectors/controller.go +++ b/internal/metrics/collectors/controller.go @@ -9,6 +9,7 @@ type ControllerCollector interface { SetIngresses(ingressType string, count int) SetVirtualServers(count int) SetVirtualServerRoutes(count int) + SetTransportServers(tlsPassthroughCount, tcpCount, udpCount int) Register(registry *prometheus.Registry) error } @@ -18,6 +19,7 @@ type ControllerMetricsCollector struct { ingressesTotal *prometheus.GaugeVec virtualServersTotal prometheus.Gauge virtualServerRoutesTotal prometheus.Gauge + transportServersTotal *prometheus.GaugeVec } // NewControllerMetricsCollector creates a new ControllerMetricsCollector @@ -32,34 +34,58 @@ func NewControllerMetricsCollector(crdsEnabled bool, constLabels map[string]stri labelNamesController, ) - if !crdsEnabled { - return &ControllerMetricsCollector{ingressesTotal: ingResTotal} + var vsResTotal, vsrResTotal prometheus.Gauge + var tsResTotal *prometheus.GaugeVec + + if crdsEnabled { + vsResTotal = prometheus.NewGauge( + prometheus.GaugeOpts{ + Name: "virtualserver_resources_total", + Namespace: metricsNamespace, + Help: "Number of handled VirtualServer resources", + ConstLabels: constLabels, + }, + ) + + vsrResTotal = prometheus.NewGauge( + prometheus.GaugeOpts{ + Name: "virtualserverroute_resources_total", + Namespace: metricsNamespace, + Help: "Number of handled VirtualServerRoute resources", + ConstLabels: constLabels, + }, + ) + + tsResTotal = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "transportserver_resources_total", + Namespace: metricsNamespace, + Help: "Number of handled TransportServer resources", + ConstLabels: constLabels, + }, + labelNamesController, + ) } - vsResTotal := prometheus.NewGauge( - prometheus.GaugeOpts{ - Name: "virtualserver_resources_total", - Namespace: metricsNamespace, - Help: "Number of handled VirtualServer resources", - ConstLabels: constLabels, - }, - ) - - vsrResTotal := prometheus.NewGauge( - prometheus.GaugeOpts{ - Name: "virtualserverroute_resources_total", - Namespace: metricsNamespace, - Help: "Number of handled VirtualServerRoute resources", - ConstLabels: constLabels, - }, - ) - - return &ControllerMetricsCollector{ - crdsEnabled: true, + c := &ControllerMetricsCollector{ + crdsEnabled: crdsEnabled, ingressesTotal: ingResTotal, virtualServersTotal: vsResTotal, virtualServerRoutesTotal: vsrResTotal, + transportServersTotal: tsResTotal, + } + + // if we don't set to 0 metrics with the label type, the metrics will not be created initially + + c.SetIngresses("regular", 0) + c.SetIngresses("master", 0) + c.SetIngresses("minion", 0) + + if crdsEnabled { + c.SetTransportServers(0, 0, 0) } + + return c } // SetIngresses sets the value of the ingress resources gauge for a given type @@ -77,12 +103,20 @@ func (cc *ControllerMetricsCollector) SetVirtualServerRoutes(count int) { cc.virtualServerRoutesTotal.Set(float64(count)) } +// SetTransportServers sets the value of the TransportServer resources gauge +func (cc *ControllerMetricsCollector) SetTransportServers(tlsPassthroughCount, tcpCount, udpCount int) { + cc.transportServersTotal.WithLabelValues("passthrough").Set(float64(tlsPassthroughCount)) + cc.transportServersTotal.WithLabelValues("tcp").Set(float64(tcpCount)) + cc.transportServersTotal.WithLabelValues("udp").Set(float64(udpCount)) +} + // Describe implements prometheus.Collector interface Describe method func (cc *ControllerMetricsCollector) Describe(ch chan<- *prometheus.Desc) { cc.ingressesTotal.Describe(ch) if cc.crdsEnabled { cc.virtualServersTotal.Describe(ch) cc.virtualServerRoutesTotal.Describe(ch) + cc.transportServersTotal.Describe(ch) } } @@ -92,6 +126,7 @@ func (cc *ControllerMetricsCollector) Collect(ch chan<- prometheus.Metric) { if cc.crdsEnabled { cc.virtualServersTotal.Collect(ch) cc.virtualServerRoutesTotal.Collect(ch) + cc.transportServersTotal.Collect(ch) } } @@ -119,3 +154,6 @@ func (cc *ControllerFakeCollector) SetVirtualServers(count int) {} // SetVirtualServerRoutes implements a fake SetVirtualServerRoutes func (cc *ControllerFakeCollector) SetVirtualServerRoutes(count int) {} + +// SetTransportServers implements a fake SetTransportServers +func (cc *ControllerFakeCollector) SetTransportServers(int, int, int) {} diff --git a/tests/data/prometheus/transport-server/global-configuration.yaml b/tests/data/prometheus/transport-server/global-configuration.yaml new file mode 100644 index 0000000000..434f885421 --- /dev/null +++ b/tests/data/prometheus/transport-server/global-configuration.yaml @@ -0,0 +1,12 @@ +apiVersion: k8s.nginx.org/v1alpha1 +kind: GlobalConfiguration +metadata: + name: nginx-configuration +spec: + listeners: + - name: tcp-server + port: 3333 + protocol: TCP + - name: udp-server + port: 3333 + protocol: UDP diff --git a/tests/data/prometheus/transport-server/passthrough.yaml b/tests/data/prometheus/transport-server/passthrough.yaml new file mode 100644 index 0000000000..467c71a9d4 --- /dev/null +++ b/tests/data/prometheus/transport-server/passthrough.yaml @@ -0,0 +1,15 @@ +apiVersion: k8s.nginx.org/v1alpha1 +kind: TransportServer +metadata: + name: passthrough +spec: + listener: + name: tls-passthrough + protocol: TLS_PASSTHROUGH + host: app.example.com + upstreams: + - name: secure-app + service: secure-app + port: 8443 + action: + pass: secure-app \ No newline at end of file diff --git a/tests/data/prometheus/transport-server/tcp.yaml b/tests/data/prometheus/transport-server/tcp.yaml new file mode 100644 index 0000000000..73d78a6e3a --- /dev/null +++ b/tests/data/prometheus/transport-server/tcp.yaml @@ -0,0 +1,14 @@ +apiVersion: k8s.nginx.org/v1alpha1 +kind: TransportServer +metadata: + name: tcp +spec: + listener: + name: tcp-server + protocol: TCP + upstreams: + - name: tcp-app + service: tcp-service + port: 3333 + action: + pass: tcp-app diff --git a/tests/data/prometheus/transport-server/udp.yaml b/tests/data/prometheus/transport-server/udp.yaml new file mode 100644 index 0000000000..cad9cfd31b --- /dev/null +++ b/tests/data/prometheus/transport-server/udp.yaml @@ -0,0 +1,14 @@ +apiVersion: k8s.nginx.org/v1alpha1 +kind: TransportServer +metadata: + name: udp +spec: + listener: + name: udp-server + protocol: UDP + upstreams: + - name: udp-app + service: udp-service + port: 3333 + action: + pass: udp-app diff --git a/tests/suite/custom_resources_utils.py b/tests/suite/custom_resources_utils.py index 70ba041527..4c3aabf0ed 100644 --- a/tests/suite/custom_resources_utils.py +++ b/tests/suite/custom_resources_utils.py @@ -226,7 +226,7 @@ def delete_resource(custom_objects: CustomObjectsApi, resource, namespace, plura print(f"Resource '{kind}' was removed with name '{name}'") -def patch_ts( +def patch_ts_from_yaml( custom_objects: CustomObjectsApi, name, yaml_manifest, namespace ) -> None: """ @@ -251,6 +251,22 @@ def patch_custom_resource_v1alpha1(custom_objects: CustomObjectsApi, name, yaml_ logging.exception(f"Failed with exception while patching custom resource: {name}") raise +def patch_ts(custom_objects: CustomObjectsApi, namespace, body) -> None: + """ + Patch a TransportServer + """ + name = body['metadata']['name'] + + print(f"Update a Resource: {name}") + + try: + custom_objects.patch_namespaced_custom_object( + "k8s.nginx.org", "v1alpha1", namespace, "transportservers", name, body + ) + except ApiException: + logging.exception(f"Failed with exception while patching custom resource: {name}") + raise + def generate_item_with_upstream_options(yaml_manifest, options) -> dict: """ diff --git a/tests/suite/test_prometheus_metrics.py b/tests/suite/test_prometheus_metrics.py index a86be8c425..12be90abe7 100644 --- a/tests/suite/test_prometheus_metrics.py +++ b/tests/suite/test_prometheus_metrics.py @@ -3,6 +3,13 @@ from kubernetes.client import V1ContainerPort +from suite.custom_resources_utils import ( + create_ts_from_yaml, + patch_ts_from_yaml, + patch_ts, delete_ts, + create_gc_from_yaml, + delete_gc, +) from suite.resources_utils import ( ensure_connection_to_public_endpoint, create_items_from_yaml, @@ -82,6 +89,7 @@ def fin(): return IngressSetup(req_url, ingress_host) + @pytest.mark.ingresses @pytest.mark.smoke class TestPrometheusExporter: @@ -200,3 +208,100 @@ def test_https_metrics( resp_content = resp.content.decode("utf-8") for item in expected_metrics: assert item in resp_content + + +@pytest.fixture(scope="class") +def ts_setup(request, kube_apis, crd_ingress_controller): + global_config_file = f"{TEST_DATA}/prometheus/transport-server/global-configuration.yaml" + + gc_resource = create_gc_from_yaml(kube_apis.custom_objects, global_config_file, "nginx-ingress") + + def fin(): + delete_gc(kube_apis.custom_objects, gc_resource, "nginx-ingress") + + request.addfinalizer(fin) + + +def assert_ts_total_metric(ingress_controller_endpoint, ts_type, value): + req_url = f"http://{ingress_controller_endpoint.public_ip}:{ingress_controller_endpoint.metrics_port}/metrics" + resp = requests.get(req_url) + resp_content = resp.content.decode("utf-8") + + assert resp.status_code == 200, f"Expected 200 code for /metrics but got {resp.status_code}" + assert f'nginx_ingress_controller_transportserver_resources_total{{class="nginx",type="{ts_type}"}} {value}' in resp_content + + +@pytest.mark.ts +@pytest.mark.parametrize( + "crd_ingress_controller", + [ + pytest.param( + { + "type": "complete", + "extra_args": + [ + "-global-configuration=nginx-ingress/nginx-configuration", + "-enable-tls-passthrough", + "-enable-prometheus-metrics" + ] + }, + ) + ], + indirect=True, +) +class TestTransportServerMetrics: + @pytest.mark.parametrize("ts", [ + (f"{TEST_DATA}/prometheus/transport-server/passthrough.yaml", "passthrough"), + (f"{TEST_DATA}/prometheus/transport-server/tcp.yaml", "tcp"), + (f"{TEST_DATA}/prometheus/transport-server/udp.yaml", "udp") + ]) + def test_total_metrics( + self, + crd_ingress_controller, + ts_setup, + ingress_controller_endpoint, + kube_apis, + test_namespace, + ts + ): + """ + Tests nginx_ingress_controller_transportserver_resources_total metric for a given TransportServer type. + """ + ts_file = ts[0] + ts_type = ts[1] + + # initially, the number of TransportServers is 0 + + assert_ts_total_metric(ingress_controller_endpoint, ts_type, 0) + + # create a TS and check the metric is 1 + + ts_resource = create_ts_from_yaml(kube_apis.custom_objects, ts_file, test_namespace) + wait_before_test() + + assert_ts_total_metric(ingress_controller_endpoint, ts_type, 1) + + # make the TS invalid and check the metric is 0 + + ts_resource["spec"]["listener"]["protocol"] = "invalid" + + patch_ts(kube_apis.custom_objects, test_namespace, ts_resource) + wait_before_test() + + assert_ts_total_metric(ingress_controller_endpoint, ts_type, 0) + + # restore the TS and check the metric is 1 + + patch_ts_from_yaml( + kube_apis.custom_objects, ts_resource["metadata"]["name"], ts_file, test_namespace + ) + wait_before_test() + + assert_ts_total_metric(ingress_controller_endpoint, ts_type, 1) + + # delete the TS and check the metric is 0 + + delete_ts(kube_apis.custom_objects, ts_resource, test_namespace) + wait_before_test() + + assert_ts_total_metric(ingress_controller_endpoint, ts_type, 0) \ No newline at end of file diff --git a/tests/suite/test_transport_server.py b/tests/suite/test_transport_server.py index 8e7b4aa510..564b97adb9 100644 --- a/tests/suite/test_transport_server.py +++ b/tests/suite/test_transport_server.py @@ -5,7 +5,7 @@ get_ts_nginx_template_conf, ) from suite.custom_resources_utils import ( - patch_ts, + patch_ts_from_yaml, ) from settings import TEST_DATA @@ -36,7 +36,7 @@ def test_snippets( Test snippets are present in conf when enabled """ patch_src = f"{TEST_DATA}/transport-server/transport-server-snippets.yaml" - patch_ts( + patch_ts_from_yaml( kube_apis.custom_objects, transport_server_setup.name, patch_src, @@ -54,7 +54,7 @@ def test_snippets( print(conf) std_src = f"{TEST_DATA}/transport-server-status/standard/transport-server.yaml" - patch_ts( + patch_ts_from_yaml( kube_apis.custom_objects, transport_server_setup.name, std_src, @@ -73,7 +73,7 @@ def test_configurble_timeout_directives( Test session and upstream configurable timeouts are present in conf """ patch_src = f"{TEST_DATA}/transport-server/transport-server-configurable-timeouts.yaml" - patch_ts( + patch_ts_from_yaml( kube_apis.custom_objects, transport_server_setup.name, patch_src, @@ -91,7 +91,7 @@ def test_configurble_timeout_directives( print(conf) std_src = f"{TEST_DATA}/transport-server-status/standard/transport-server.yaml" - patch_ts( + patch_ts_from_yaml( kube_apis.custom_objects, transport_server_setup.name, std_src, diff --git a/tests/suite/test_transport_server_status.py b/tests/suite/test_transport_server_status.py index f75794941e..ece3527a1f 100644 --- a/tests/suite/test_transport_server_status.py +++ b/tests/suite/test_transport_server_status.py @@ -3,7 +3,7 @@ from suite.resources_utils import wait_before_test from suite.custom_resources_utils import ( read_ts, - patch_ts, + patch_ts_from_yaml, ) from settings import TEST_DATA @@ -33,7 +33,7 @@ def restore_ts(self, kube_apis, transport_server_setup) -> None: Function to revert a TransportServer resource to a valid state. """ patch_src = f"{TEST_DATA}/transport-server-status/standard/transport-server.yaml" - patch_ts( + patch_ts_from_yaml( kube_apis.custom_objects, transport_server_setup.name, patch_src, @@ -65,7 +65,7 @@ def test_status_warning( Test TransportServer status with a missing listener. """ patch_src = f"{TEST_DATA}/transport-server-status/rejected-warning.yaml" - patch_ts( + patch_ts_from_yaml( kube_apis.custom_objects, transport_server_setup.name, patch_src, @@ -91,7 +91,7 @@ def test_status_invalid( Test TransportServer status with an invalid protocol. """ patch_src = f"{TEST_DATA}/transport-server-status/rejected-invalid.yaml" - patch_ts( + patch_ts_from_yaml( kube_apis.custom_objects, transport_server_setup.name, patch_src, diff --git a/tests/suite/test_transport_server_tcp_load_balance.py b/tests/suite/test_transport_server_tcp_load_balance.py index b705013cb1..f9d0d02e84 100644 --- a/tests/suite/test_transport_server_tcp_load_balance.py +++ b/tests/suite/test_transport_server_tcp_load_balance.py @@ -13,7 +13,7 @@ wait_for_event_increment, ) from suite.custom_resources_utils import ( - patch_ts, + patch_ts_from_yaml, read_ts, delete_ts, create_ts_from_yaml, @@ -46,7 +46,7 @@ def restore_ts(self, kube_apis, transport_server_setup) -> None: Function to revert a TransportServer resource to a valid state. """ patch_src = f"{TEST_DATA}/transport-server-tcp-load-balance/standard/transport-server.yaml" - patch_ts( + patch_ts_from_yaml( kube_apis.custom_objects, transport_server_setup.name, patch_src, @@ -236,7 +236,7 @@ def test_tcp_request_load_balanced_wrong_port( """ patch_src = f"{TEST_DATA}/transport-server-tcp-load-balance/wrong-port-transport-server.yaml" - patch_ts( + patch_ts_from_yaml( kube_apis.custom_objects, transport_server_setup.name, patch_src, @@ -267,7 +267,7 @@ def test_tcp_request_load_balanced_missing_service( """ patch_src = f"{TEST_DATA}/transport-server-tcp-load-balance/missing-service-transport-server.yaml" - patch_ts( + patch_ts_from_yaml( kube_apis.custom_objects, transport_server_setup.name, patch_src, @@ -310,7 +310,7 @@ def test_tcp_request_max_connections( # step 1 - set max connections to 2 with 1 replica patch_src = f"{TEST_DATA}/transport-server-tcp-load-balance/max-connections-transport-server.yaml" - patch_ts( + patch_ts_from_yaml( kube_apis.custom_objects, transport_server_setup.name, patch_src, @@ -358,7 +358,7 @@ def test_tcp_request_max_connections( # step 4 - revert to config with no max connections patch_src = f"{TEST_DATA}/transport-server-tcp-load-balance/standard/transport-server.yaml" - patch_ts( + patch_ts_from_yaml( kube_apis.custom_objects, transport_server_setup.name, patch_src, @@ -386,7 +386,7 @@ def test_tcp_request_load_balanced_method( # Step 1 - set the load balancing method. patch_src = f"{TEST_DATA}/transport-server-tcp-load-balance/method-transport-server.yaml" - patch_ts( + patch_ts_from_yaml( kube_apis.custom_objects, transport_server_setup.name, patch_src, @@ -474,7 +474,7 @@ def test_tcp_passing_healthcheck_with_match( # Step 1 - configure a passing health check patch_src = f"{TEST_DATA}/transport-server-tcp-load-balance/passing-hc-transport-server.yaml" - patch_ts( + patch_ts_from_yaml( kube_apis.custom_objects, transport_server_setup.name, patch_src, @@ -539,7 +539,7 @@ def test_tcp_failing_healthcheck_with_match( # Step 1 - configure a failing health check patch_src = f"{TEST_DATA}/transport-server-tcp-load-balance/failing-hc-transport-server.yaml" - patch_ts( + patch_ts_from_yaml( kube_apis.custom_objects, transport_server_setup.name, patch_src, diff --git a/tests/suite/test_transport_server_udp_load_balance.py b/tests/suite/test_transport_server_udp_load_balance.py index 35b0a8ee17..fde48e6583 100644 --- a/tests/suite/test_transport_server_udp_load_balance.py +++ b/tests/suite/test_transport_server_udp_load_balance.py @@ -10,7 +10,7 @@ wait_for_event_increment, ) from suite.custom_resources_utils import ( - patch_ts, + patch_ts_from_yaml, read_ts, delete_ts, create_ts_from_yaml, @@ -43,7 +43,7 @@ def restore_ts(self, kube_apis, transport_server_setup) -> None: Function to revert a TransportServer resource to a valid state. """ patch_src = f"{TEST_DATA}/transport-server-udp-load-balance/standard/transport-server.yaml" - patch_ts( + patch_ts_from_yaml( kube_apis.custom_objects, transport_server_setup.name, patch_src, @@ -223,7 +223,7 @@ def test_udp_request_fails( self, kube_apis, crd_ingress_controller, transport_server_setup, file ): patch_src = f"{TEST_DATA}/transport-server-udp-load-balance/{file}" - patch_ts( + patch_ts_from_yaml( kube_apis.custom_objects, transport_server_setup.name, patch_src, @@ -263,7 +263,7 @@ def test_udp_passing_healthcheck_with_match( # Step 1 - configure a passing health check patch_src = f"{TEST_DATA}/transport-server-udp-load-balance/passing-hc-transport-server.yaml" - patch_ts( + patch_ts_from_yaml( kube_apis.custom_objects, transport_server_setup.name, patch_src, @@ -331,7 +331,7 @@ def test_udp_failing_healthcheck_with_match( # Step 1 - configure a failing health check patch_src = f"{TEST_DATA}/transport-server-udp-load-balance/failing-hc-transport-server.yaml" - patch_ts( + patch_ts_from_yaml( kube_apis.custom_objects, transport_server_setup.name, patch_src,