@@ -2183,27 +2183,88 @@ func TestBuildInferencePoolStatuses(t *testing.T) {
21832183 Message : "Inference pool references a valid ExtensionRef." ,
21842184 }
21852185
2186+ referencedGateways := map [types.NamespacedName ]* graph.Gateway {
2187+ {Namespace : "test" , Name : "gateway-1" }: {
2188+ Source : & v1.Gateway {
2189+ ObjectMeta : metav1.ObjectMeta {
2190+ Name : "gateway-1" ,
2191+ Namespace : "test" ,
2192+ },
2193+ },
2194+ Valid : true ,
2195+ },
2196+ {Namespace : "test" , Name : "gateway-2" }: {
2197+ Source : & v1.Gateway {
2198+ ObjectMeta : metav1.ObjectMeta {
2199+ Name : "gateway-2" ,
2200+ Namespace : "test" ,
2201+ },
2202+ },
2203+ Valid : true ,
2204+ },
2205+ }
2206+
2207+ validInferencePool := & inference.InferencePool {
2208+ ObjectMeta : metav1.ObjectMeta {
2209+ Name : "valid-inference-pool" ,
2210+ Namespace : "test" ,
2211+ Generation : 1 ,
2212+ },
2213+ }
2214+
2215+ validInferencePoolWithInvalidExtensionRef := & inference.InferencePool {
2216+ ObjectMeta : metav1.ObjectMeta {
2217+ Name : "valid-inference-pool" ,
2218+ Namespace : "test" ,
2219+ Generation : 1 ,
2220+ },
2221+ Spec : inference.InferencePoolSpec {
2222+ EndpointPickerRef : inference.EndpointPickerRef {
2223+ Name : inference .ObjectName ("invalid-extension-ref" ),
2224+ },
2225+ },
2226+ }
2227+
2228+ validInferencePoolWithStatus := & inference.InferencePool {
2229+ ObjectMeta : metav1.ObjectMeta {
2230+ Name : "valid-inference-pool-with-status" ,
2231+ Namespace : "test" ,
2232+ Generation : 1 ,
2233+ },
2234+ Status : inference.InferencePoolStatus {
2235+ Parents : []inference.ParentStatus {
2236+ {
2237+ Conditions : []metav1.Condition {
2238+ validAcceptedCondition ,
2239+ validResolvedRefsCondition ,
2240+ },
2241+ ParentRef : inference.ParentReference {
2242+ Namespace : inference .Namespace ("test" ),
2243+ Name : "gateway-1" ,
2244+ Kind : kinds .Gateway ,
2245+ Group : helpers .GetPointer (inference .Group (group )),
2246+ },
2247+ },
2248+ },
2249+ },
2250+ }
2251+
21862252 tests := []struct {
2187- inferencePool map [types.NamespacedName ]* graph.ReferencedInferencePool
2188- expectedPoolWithStatus map [types.NamespacedName ]inference.InferencePoolStatus
2189- name string
2190- expectedReqs int
2253+ referencedInferencePool map [types.NamespacedName ]* graph.ReferencedInferencePool
2254+ expectedPoolWithStatus map [types.NamespacedName ]inference.InferencePoolStatus
2255+ name string
2256+ clusterInferencePools inference.InferencePoolList
2257+ expectedReqs int
21912258 }{
21922259 {
21932260 name : "no referenced inferencePools" ,
21942261 expectedReqs : 0 ,
21952262 },
21962263 {
21972264 name : "an inference pool has valid status for multiple gateways" ,
2198- inferencePool : map [types.NamespacedName ]* graph.ReferencedInferencePool {
2265+ referencedInferencePool : map [types.NamespacedName ]* graph.ReferencedInferencePool {
21992266 {Namespace : "test" , Name : "valid-inference-pool" }: {
2200- Source : & inference.InferencePool {
2201- ObjectMeta : metav1.ObjectMeta {
2202- Name : "valid-inference-pool" ,
2203- Namespace : "test" ,
2204- Generation : 1 ,
2205- },
2206- },
2267+ Source : validInferencePool ,
22072268 Gateways : []* v1.Gateway {
22082269 {
22092270 ObjectMeta : metav1.ObjectMeta {
@@ -2220,6 +2281,11 @@ func TestBuildInferencePoolStatuses(t *testing.T) {
22202281 },
22212282 },
22222283 },
2284+ clusterInferencePools : inference.InferencePoolList {
2285+ Items : []inference.InferencePool {
2286+ * validInferencePool ,
2287+ },
2288+ },
22232289 expectedReqs : 1 ,
22242290 expectedPoolWithStatus : map [types.NamespacedName ]inference.InferencePoolStatus {
22252291 {Namespace : "test" , Name : "valid-inference-pool" }: {
@@ -2254,20 +2320,9 @@ func TestBuildInferencePoolStatuses(t *testing.T) {
22542320 },
22552321 {
22562322 name : "an inference pool has accepted valid status and is referenced by invalid extension ref" ,
2257- inferencePool : map [types.NamespacedName ]* graph.ReferencedInferencePool {
2323+ referencedInferencePool : map [types.NamespacedName ]* graph.ReferencedInferencePool {
22582324 {Namespace : "test" , Name : "valid-inference-pool" }: {
2259- Source : & inference.InferencePool {
2260- ObjectMeta : metav1.ObjectMeta {
2261- Name : "valid-inference-pool" ,
2262- Namespace : "test" ,
2263- Generation : 1 ,
2264- },
2265- Spec : inference.InferencePoolSpec {
2266- EndpointPickerRef : inference.EndpointPickerRef {
2267- Name : inference .ObjectName ("invalid-extension-ref" ),
2268- },
2269- },
2270- },
2325+ Source : validInferencePoolWithInvalidExtensionRef ,
22712326 Gateways : []* v1.Gateway {
22722327 {
22732328 ObjectMeta : metav1.ObjectMeta {
@@ -2281,6 +2336,11 @@ func TestBuildInferencePoolStatuses(t *testing.T) {
22812336 },
22822337 },
22832338 },
2339+ clusterInferencePools : inference.InferencePoolList {
2340+ Items : []inference.InferencePool {
2341+ * validInferencePoolWithInvalidExtensionRef ,
2342+ },
2343+ },
22842344 expectedReqs : 1 ,
22852345 expectedPoolWithStatus : map [types.NamespacedName ]inference.InferencePoolStatus {
22862346 {Namespace : "test" , Name : "valid-inference-pool" }: {
@@ -2310,15 +2370,9 @@ func TestBuildInferencePoolStatuses(t *testing.T) {
23102370 },
23112371 {
23122372 name : "an inference pool is referencing an invalid route and is referenced by invalid extension ref" ,
2313- inferencePool : map [types.NamespacedName ]* graph.ReferencedInferencePool {
2373+ referencedInferencePool : map [types.NamespacedName ]* graph.ReferencedInferencePool {
23142374 {Namespace : "test" , Name : "valid-inference-pool" }: {
2315- Source : & inference.InferencePool {
2316- ObjectMeta : metav1.ObjectMeta {
2317- Name : "valid-inference-pool" ,
2318- Namespace : "test" ,
2319- Generation : 1 ,
2320- },
2321- },
2375+ Source : validInferencePool ,
23222376 Gateways : []* v1.Gateway {
23232377 {
23242378 ObjectMeta : metav1.ObjectMeta {
@@ -2333,6 +2387,11 @@ func TestBuildInferencePoolStatuses(t *testing.T) {
23332387 },
23342388 },
23352389 },
2390+ clusterInferencePools : inference.InferencePoolList {
2391+ Items : []inference.InferencePool {
2392+ * validInferencePool ,
2393+ },
2394+ },
23362395 expectedReqs : 1 ,
23372396 expectedPoolWithStatus : map [types.NamespacedName ]inference.InferencePoolStatus {
23382397 {Namespace : "test" , Name : "valid-inference-pool" }: {
@@ -2367,6 +2426,21 @@ func TestBuildInferencePoolStatuses(t *testing.T) {
23672426 },
23682427 },
23692428 },
2429+ {
2430+ name : "inference pool status gets removed if no longer referenced" ,
2431+ referencedInferencePool : map [types.NamespacedName ]* graph.ReferencedInferencePool {},
2432+ clusterInferencePools : inference.InferencePoolList {
2433+ Items : []inference.InferencePool {
2434+ * validInferencePoolWithStatus ,
2435+ },
2436+ },
2437+ expectedReqs : 1 ,
2438+ expectedPoolWithStatus : map [types.NamespacedName ]inference.InferencePoolStatus {
2439+ {Namespace : "test" , Name : "valid-inference-pool-with-status" }: {
2440+ Parents : nil ,
2441+ },
2442+ },
2443+ },
23702444 }
23712445
23722446 for _ , test := range tests {
@@ -2375,13 +2449,18 @@ func TestBuildInferencePoolStatuses(t *testing.T) {
23752449 g := NewWithT (t )
23762450
23772451 k8sClient := createK8sClientFor (& inference.InferencePool {})
2378- for _ , ip := range test .inferencePool {
2379- err := k8sClient .Create (context .Background (), ip . Source )
2452+ for _ , ip := range test .clusterInferencePools . Items {
2453+ err := k8sClient .Create (context .Background (), & ip )
23802454 g .Expect (err ).ToNot (HaveOccurred ())
23812455 }
23822456
23832457 updater := NewUpdater (k8sClient , logr .Discard ())
2384- reqs := PrepareInferencePoolRequests (test .inferencePool , transitionTime )
2458+ reqs := PrepareInferencePoolRequests (
2459+ test .referencedInferencePool ,
2460+ & test .clusterInferencePools ,
2461+ referencedGateways ,
2462+ transitionTime ,
2463+ )
23852464 g .Expect (reqs ).To (HaveLen (test .expectedReqs ))
23862465 updater .Update (context .Background (), reqs ... )
23872466
0 commit comments