@@ -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