@@ -134,6 +134,11 @@ func TestNewQuotaManagerSingleton(t *testing.T) {
134134 }
135135}
136136
137+ // nsPod returns a pod in ns that no scoped quota matches by its fields alone.
138+ func nsPod (ns string ) * corev1.Pod {
139+ return & corev1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "fit" , Namespace : ns }}
140+ }
141+
137142func TestFitQuota (t * testing.T ) {
138143 initTest ()
139144 qm := NewQuotaManager ()
@@ -148,24 +153,24 @@ func TestFitQuota(t *testing.T) {
148153 }
149154
150155 // Should fit
151- if ! qm .FitQuota ( ns , 500 , 100 , deviceName ) {
152- t .Error ("FitQuota should return true when within limits" )
156+ if ! qm .FitQuotaForPod ( nsPod ( ns ) , 500 , 100 , deviceName ) {
157+ t .Error ("FitQuotaForPod should return true when within limits" )
153158 }
154159 // Should not fit memory
155- if qm .FitQuota ( ns , 1500 , 100 , deviceName ) {
156- t .Error ("FitQuota should return false when memory exceeds limit" )
160+ if qm .FitQuotaForPod ( nsPod ( ns ) , 1500 , 100 , deviceName ) {
161+ t .Error ("FitQuotaForPod should return false when memory exceeds limit" )
157162 }
158163 // Should not fit core
159- if qm .FitQuota ( ns , 500 , 300 , deviceName ) {
160- t .Error ("FitQuota should return false when core exceeds limit" )
164+ if qm .FitQuotaForPod ( nsPod ( ns ) , 500 , 300 , deviceName ) {
165+ t .Error ("FitQuotaForPod should return false when core exceeds limit" )
161166 }
162167 // Should fit if namespace not present
163- if ! qm .FitQuota ( "otherns" , 1500 , 100 , deviceName ) {
164- t .Error ("FitQuota should return true if namespace not present" )
168+ if ! qm .FitQuotaForPod ( nsPod ( "otherns" ) , 1500 , 100 , deviceName ) {
169+ t .Error ("FitQuotaForPod should return true if namespace not present" )
165170 }
166171 // Should fit if device not present
167- if ! qm .FitQuota ( ns , 1000 , 100 , "unknown-device" ) {
168- t .Error ("FitQuota should return true if device not present" )
172+ if ! qm .FitQuotaForPod ( nsPod ( ns ) , 1000 , 100 , "unknown-device" ) {
173+ t .Error ("FitQuotaForPod should return true if device not present" )
169174 }
170175}
171176
@@ -184,8 +189,8 @@ func TestFitQuotaExplicitZeroBlocks(t *testing.T) {
184189 qm .AddQuota (rq )
185190
186191 // The explicit zero must block any positive request, not be read as "unlimited".
187- if qm .FitQuota ( ns , 500 , 0 , "NVIDIA" ) {
188- t .Error (`FitQuota admitted a 500 request under limits.nvidia.com/gpumem: "0"; an explicit zero quota must block` )
192+ if qm .FitQuotaForPod ( nsPod ( ns ) , 500 , 0 , "NVIDIA" ) {
193+ t .Error (`FitQuotaForPod admitted a 500 request under limits.nvidia.com/gpumem: "0"; an explicit zero quota must block` )
189194 }
190195}
191196
@@ -207,12 +212,12 @@ func TestFitQuotaUsesScaledLimit(t *testing.T) {
207212
208213 // 100 units are 25600 MiB, and requests arrive already scaled
209214 // Should fit at the scaled limit
210- if ! qm .FitQuota ( ns , 25600 , 0 , "MLU" ) {
211- t .Error ("FitQuota should return true when memory equals the scaled limit" )
215+ if ! qm .FitQuotaForPod ( nsPod ( ns ) , 25600 , 0 , "MLU" ) {
216+ t .Error ("FitQuotaForPod should return true when memory equals the scaled limit" )
212217 }
213218 // Should not fit above the scaled limit
214- if qm .FitQuota ( ns , 25601 , 0 , "MLU" ) {
215- t .Error ("FitQuota should return false when memory exceeds the scaled limit" )
219+ if qm .FitQuotaForPod ( nsPod ( ns ) , 25601 , 0 , "MLU" ) {
220+ t .Error ("FitQuotaForPod should return false when memory exceeds the scaled limit" )
216221 }
217222}
218223
@@ -469,7 +474,7 @@ func TestDelQuotaNonLimitsKey(t *testing.T) {
469474}
470475
471476// A ResourceQuota update must never leave the limits zeroed, even briefly.
472- // FitQuota reads a zero limit as no limit, so a check landing mid-update would
477+ // FitQuotaForPod reads a zero limit as no limit, so a check landing mid-update would
473478// be waved through. The kube quota controller rewrites status.used on every pod
474479// event, so updates arrive exactly when pods are being scheduled.
475480func TestUpdateQuotaKeepsLimitEnforced (t * testing.T ) {
@@ -507,7 +512,7 @@ func TestUpdateQuotaKeepsLimitEnforced(t *testing.T) {
507512
508513 wg .Go (func () {
509514 for range 50000 {
510- if qm .FitQuota ( ns , 1 , 0 , "NVIDIA" ) {
515+ if qm .FitQuotaForPod ( nsPod ( ns ) , 1 , 0 , "NVIDIA" ) {
511516 atomic .AddInt64 (& wrongAdmits , 1 )
512517 }
513518 }
0 commit comments