Skip to content

Commit f1c4438

Browse files
committed
test(workbenches): add test to verify auth container resource customization
1 parent d0e8c94 commit f1c4438

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

tests/workbenches/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ def default_notebook(
5555
namespace = request.param["namespace"]
5656
name = request.param["name"]
5757

58+
# Optional OAuth annotations
59+
oauth_annotations = request.param.get("oauth_annotations", {})
60+
5861
# Set new Route url
5962
route_name = "odh-dashboard" if py_config.get("distribution") == "upstream" else "rhods-dashboard"
6063
route = Route(client=admin_client, name=route_name, namespace=py_config["applications_namespace"])
@@ -97,6 +100,8 @@ def default_notebook(
97100
"opendatahub.io/accelerator-name": "",
98101
"opendatahub.io/service-mesh": "false",
99102
"notebooks.opendatahub.io/last-image-selection": minimal_image,
103+
# Add any additional annotations if provided
104+
**oauth_annotations,
100105
},
101106
"labels": {
102107
Labels.Openshift.APP: name,

tests/workbenches/notebook-controller/test_spawning.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,88 @@ def test_create_simple_notebook(
4444
)
4545
notebook_pod.wait()
4646
notebook_pod.wait_for_condition(condition=Pod.Condition.READY, status=Pod.Condition.Status.TRUE)
47+
48+
@pytest.mark.smoke
49+
@pytest.mark.parametrize(
50+
"unprivileged_model_namespace,users_persistent_volume_claim,default_notebook",
51+
[
52+
pytest.param(
53+
{
54+
"name": "test-oauth-notebook",
55+
"add-dashboard-label": True,
56+
},
57+
{"name": "test-oauth-notebook"},
58+
{
59+
"namespace": "test-oauth-notebook",
60+
"name": "test-oauth-notebook",
61+
"oauth_annotations": {
62+
"notebooks.opendatahub.io/auth-sidecar-cpu-request": "200m",
63+
"notebooks.opendatahub.io/auth-sidecar-memory-request": "128Mi",
64+
"notebooks.opendatahub.io/auth-sidecar-cpu-limit": "500m",
65+
"notebooks.opendatahub.io/auth-sidecar-memory-limit": "256Mi",
66+
},
67+
},
68+
)
69+
],
70+
indirect=True,
71+
)
72+
def test_oauth_container_resource_customization(
73+
self,
74+
unprivileged_client: DynamicClient,
75+
unprivileged_model_namespace: Namespace,
76+
users_persistent_volume_claim: PersistentVolumeClaim,
77+
default_notebook: Notebook,
78+
):
79+
"""
80+
Test that OAuth container resource requests and limits can be customized using annotations.
81+
82+
This test verifies that when a Notebook CR is created with custom OAuth container resource
83+
annotations, the spawned pod has the OAuth container with the specified resource values.
84+
"""
85+
notebook_pod = Pod(
86+
client=unprivileged_client,
87+
namespace=default_notebook.namespace,
88+
name=f"{default_notebook.name}-0",
89+
)
90+
notebook_pod.wait()
91+
notebook_pod.wait_for_condition(condition=Pod.Condition.READY, status=Pod.Condition.Status.TRUE)
92+
93+
# Verify OAuth container has the expected resource values
94+
oauth_container = self._get_oauth_container(pod=notebook_pod)
95+
assert oauth_container, "OAuth proxy container not found in the pod"
96+
97+
# Check CPU request
98+
assert oauth_container.resources.requests["cpu"] == "200m", (
99+
f"Expected CPU request '200m', got '{oauth_container.resources.requests['cpu']}'"
100+
)
101+
102+
# Check memory request
103+
assert oauth_container.resources.requests["memory"] == "128Mi", (
104+
f"Expected memory request '128Mi', got '{oauth_container.resources.requests['memory']}'"
105+
)
106+
107+
# Check CPU limit
108+
assert oauth_container.resources.limits["cpu"] == "500m", (
109+
f"Expected CPU limit '500m', got '{oauth_container.resources.limits['cpu']}'"
110+
)
111+
112+
# Check memory limit
113+
assert oauth_container.resources.limits["memory"] == "256Mi", (
114+
f"Expected memory limit '256Mi', got '{oauth_container.resources.limits['memory']}'"
115+
)
116+
117+
def _get_oauth_container(self, pod: Pod):
118+
"""
119+
Find and return the OAuth proxy container from the pod spec.
120+
121+
Args:
122+
pod: The pod instance to search
123+
124+
Returns:
125+
The OAuth container if found, None otherwise
126+
"""
127+
containers = pod.instance.spec.containers
128+
for container in containers:
129+
if container.name == "oauth-proxy":
130+
return container
131+
return None

0 commit comments

Comments
 (0)