11package controllers_test
22
33import (
4- "context"
54 "encoding/json"
65 "fmt"
76 "io"
@@ -111,9 +110,9 @@ func TestStorageConfiguration(t *testing.T) {
111110
112111 // arrange
113112 instance := tt .buildInstance (namespace .Name )
114- require .NoError (t , k8sClient .Create (context . Background (), instance ))
113+ require .NoError (t , k8sClient .Create (t . Context (), instance ))
115114 t .Cleanup (func () {
116- if err := k8sClient .Delete (context . Background (), instance ); err != nil && ! apierrors .IsNotFound (err ) {
115+ if err := k8sClient .Delete (t . Context (), instance ); err != nil && ! apierrors .IsNotFound (err ) {
117116 t .Logf ("Failed to delete LlamaStackDistribution instance %s/%s: %v" , instance .Namespace , instance .Name , err )
118117 }
119118 })
@@ -179,15 +178,15 @@ server:
179178 port: 8321` ,
180179 },
181180 }
182- require .NoError (t , k8sClient .Create (context . Background (), configMap ))
181+ require .NoError (t , k8sClient .Create (t . Context (), configMap ))
183182
184183 // Create a LlamaStackDistribution that references the ConfigMap
185184 instance := NewDistributionBuilder ().
186185 WithName ("test-configmap-reference" ).
187186 WithNamespace (namespace .Name ).
188187 WithUserConfig (configMap .Name ).
189188 Build ()
190- require .NoError (t , k8sClient .Create (context . Background (), instance ))
189+ require .NoError (t , k8sClient .Create (t . Context (), instance ))
191190
192191 // Reconcile to create initial deployment
193192 ReconcileDistribution (t , instance , false )
@@ -204,7 +203,7 @@ server:
204203 require .NotEmpty (t , initialHash , "ConfigMap hash should not be empty" )
205204
206205 // Update the ConfigMap data
207- require .NoError (t , k8sClient .Get (context . Background (),
206+ require .NoError (t , k8sClient .Get (t . Context (),
208207 types.NamespacedName {Name : configMap .Name , Namespace : configMap .Namespace }, configMap ))
209208
210209 configMap .Data ["run.yaml" ] = `version: '2'
@@ -223,7 +222,7 @@ models:
223222 model_type: llm
224223server:
225224 port: 8321`
226- require .NoError (t , k8sClient .Update (context . Background (), configMap ))
225+ require .NoError (t , k8sClient .Update (t . Context (), configMap ))
227226
228227 // Wait a moment for the watch to trigger
229228 time .Sleep (2 * time .Second )
@@ -250,7 +249,7 @@ server:
250249 "some-key" : "some-value" ,
251250 },
252251 }
253- require .NoError (t , k8sClient .Create (context . Background (), unrelatedConfigMap ))
252+ require .NoError (t , k8sClient .Create (t . Context (), unrelatedConfigMap ))
254253
255254 // Note: In test environment, field indexer might not be set up properly,
256255 // so we skip the isConfigMapReferenced checks which rely on field indexing
@@ -284,7 +283,7 @@ func TestReconcile(t *testing.T) {
284283 WithDistribution ("starter" ).
285284 WithPort (instancePort ).
286285 Build ()
287- require .NoError (t , k8sClient .Create (context . Background (), instance ))
286+ require .NoError (t , k8sClient .Create (t . Context (), instance ))
288287
289288 // --- act ---
290289 ReconcileDistribution (t , instance , true )
@@ -399,7 +398,7 @@ func TestLlamaStackProviderAndVersionInfo(t *testing.T) {
399398 WithName ("test-status-instance" ).
400399 WithNamespace (namespace .Name ).
401400 Build ()
402- require .NoError (t , k8sClient .Create (context . Background (), instance ))
401+ require .NoError (t , k8sClient .Create (t . Context (), instance ))
403402
404403 testClusterInfo := & cluster.ClusterInfo {
405404 DistributionImages : map [string ]string {
@@ -417,7 +416,7 @@ func TestLlamaStackProviderAndVersionInfo(t *testing.T) {
417416
418417 // act (part 1)
419418 // run the first reconciliation to create the initial resources like the deployment
420- _ , err := reconciler .Reconcile (context . Background (), ctrl.Request {
419+ _ , err := reconciler .Reconcile (t . Context (), ctrl.Request {
421420 NamespacedName : types.NamespacedName {Name : instance .Name , Namespace : instance .Namespace },
422421 })
423422 require .NoError (t , err )
@@ -430,11 +429,11 @@ func TestLlamaStackProviderAndVersionInfo(t *testing.T) {
430429
431430 deployment .Status .ReadyReplicas = 1
432431 deployment .Status .Replicas = 1
433- require .NoError (t , k8sClient .Status ().Update (context . Background (), deployment ))
432+ require .NoError (t , k8sClient .Status ().Update (t . Context (), deployment ))
434433
435434 // act (part 2)
436435 // run the second reconciliation to trigger the status update logic
437- _ , err = reconciler .Reconcile (context . Background (), ctrl.Request {
436+ _ , err = reconciler .Reconcile (t . Context (), ctrl.Request {
438437 NamespacedName : types.NamespacedName {Name : instance .Name , Namespace : instance .Namespace },
439438 })
440439 require .NoError (t , err )
@@ -492,8 +491,8 @@ func TestNetworkPolicyConfiguration(t *testing.T) {
492491 WithNamespace (namespace .Name ).
493492 WithDistribution ("starter" ).
494493 Build ()
495- require .NoError (t , k8sClient .Create (context . Background (), instance ))
496- t .Cleanup (func () { _ = k8sClient .Delete (context . Background (), instance ) })
494+ require .NoError (t , k8sClient .Create (t . Context (), instance ))
495+ t .Cleanup (func () { _ = k8sClient .Delete (t . Context (), instance ) })
497496
498497 // preconditions for this scenario
499498 tt .setup (t , instance )
0 commit comments