Skip to content

Commit ddc5f02

Browse files
mwaykolepre-commit-ci[bot]dbasunag
authored
replacing patch way to ResourceEditor (#519)
* run pre-commit for fixng check Signed-off-by: Milind Waykole <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Milind Waykole <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Debarati Basu-Nag <[email protected]>
1 parent 69dc0d3 commit ddc5f02

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

tests/model_serving/model_server/keda/test_isvc_keda_scaling_cpu.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
from ocp_resources.resource import ResourceEditor
23
from simple_logger.logger import get_logger
34
from typing import Any, Generator
45
from kubernetes.dynamic import DynamicClient
@@ -72,19 +73,28 @@ def test_ovms_keda_scaling_verify_scaledobject(
7273
"""Test KEDA ScaledObject configuration and run inference multiple times to trigger scaling."""
7374

7475
if is_jira_open(jira_id="RHOAIENG-31386", admin_client=admin_client):
75-
patch_operations = [
76-
{
77-
"op": "add",
78-
"path": "/spec/predictor/autoScaling/metrics/0/external/authenticationRef",
79-
"value": {"authModes": "bearer", "authenticationRef": {"name": "inference-prometheus-auth"}},
76+
isvc_dict = stressed_ovms_keda_inference_service.instance.to_dict()
77+
metrics = isvc_dict.get("spec", {}).get("predictor", {}).get("autoScaling", {}).get("metrics", [])
78+
79+
if metrics and isinstance(metrics[0], dict) and metrics[0].get("external") is not None:
80+
metrics[0].setdefault("external", {})["authenticationRef"] = {
81+
"authModes": "bearer",
82+
"authenticationRef": {"name": "inference-prometheus-auth"},
8083
}
81-
]
82-
admin_client.resources.get(api_version="v1beta1", kind="InferenceService").patch(
83-
name=stressed_ovms_keda_inference_service.name,
84-
namespace=stressed_ovms_keda_inference_service.namespace,
85-
body=patch_operations,
86-
content_type="application/json-patch+json",
87-
)
84+
85+
ResourceEditor(
86+
patches={
87+
stressed_ovms_keda_inference_service: {
88+
"spec": {
89+
"predictor": {
90+
"autoScaling": {
91+
"metrics": metrics,
92+
}
93+
}
94+
}
95+
}
96+
}
97+
).update()
8898

8999
verify_keda_scaledobject(
90100
client=unprivileged_client,

0 commit comments

Comments
 (0)