Skip to content

Commit 3f1c41d

Browse files
committed
Propagate existing ctx instead of context.TODO()
1 parent 211d67a commit 3f1c41d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

staging/src/k8s.io/sample-controller/controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func (c *Controller) syncHandler(ctx context.Context, objectRef cache.ObjectName
267267
deployment, err := c.deploymentsLister.Deployments(foo.Namespace).Get(deploymentName)
268268
// If the resource doesn't exist, we'll create it
269269
if errors.IsNotFound(err) {
270-
deployment, err = c.kubeclientset.AppsV1().Deployments(foo.Namespace).Create(context.TODO(), newDeployment(foo), metav1.CreateOptions{FieldManager: FieldManager})
270+
deployment, err = c.kubeclientset.AppsV1().Deployments(foo.Namespace).Create(ctx, newDeployment(foo), metav1.CreateOptions{FieldManager: FieldManager})
271271
}
272272

273273
// If an error occurs during Get/Create, we'll requeue the item so we can
@@ -290,7 +290,7 @@ func (c *Controller) syncHandler(ctx context.Context, objectRef cache.ObjectName
290290
// should update the Deployment resource.
291291
if foo.Spec.Replicas != nil && *foo.Spec.Replicas != *deployment.Spec.Replicas {
292292
logger.V(4).Info("Update deployment resource", "currentReplicas", *foo.Spec.Replicas, "desiredReplicas", *deployment.Spec.Replicas)
293-
deployment, err = c.kubeclientset.AppsV1().Deployments(foo.Namespace).Update(context.TODO(), newDeployment(foo), metav1.UpdateOptions{FieldManager: FieldManager})
293+
deployment, err = c.kubeclientset.AppsV1().Deployments(foo.Namespace).Update(ctx, newDeployment(foo), metav1.UpdateOptions{FieldManager: FieldManager})
294294
}
295295

296296
// If an error occurs during Update, we'll requeue the item so we can
@@ -302,7 +302,7 @@ func (c *Controller) syncHandler(ctx context.Context, objectRef cache.ObjectName
302302

303303
// Finally, we update the status block of the Foo resource to reflect the
304304
// current state of the world
305-
err = c.updateFooStatus(foo, deployment)
305+
err = c.updateFooStatus(ctx, foo, deployment)
306306
if err != nil {
307307
return err
308308
}
@@ -311,7 +311,7 @@ func (c *Controller) syncHandler(ctx context.Context, objectRef cache.ObjectName
311311
return nil
312312
}
313313

314-
func (c *Controller) updateFooStatus(foo *samplev1alpha1.Foo, deployment *appsv1.Deployment) error {
314+
func (c *Controller) updateFooStatus(ctx context.Context, foo *samplev1alpha1.Foo, deployment *appsv1.Deployment) error {
315315
// NEVER modify objects from the store. It's a read-only, local cache.
316316
// You can use DeepCopy() to make a deep copy of original object and modify this copy
317317
// Or create a copy manually for better performance
@@ -321,7 +321,7 @@ func (c *Controller) updateFooStatus(foo *samplev1alpha1.Foo, deployment *appsv1
321321
// we must use Update instead of UpdateStatus to update the Status block of the Foo resource.
322322
// UpdateStatus will not allow changes to the Spec of the resource,
323323
// which is ideal for ensuring nothing other than resource status has been updated.
324-
_, err := c.sampleclientset.SamplecontrollerV1alpha1().Foos(foo.Namespace).UpdateStatus(context.TODO(), fooCopy, metav1.UpdateOptions{FieldManager: FieldManager})
324+
_, err := c.sampleclientset.SamplecontrollerV1alpha1().Foos(foo.Namespace).UpdateStatus(ctx, fooCopy, metav1.UpdateOptions{FieldManager: FieldManager})
325325
return err
326326
}
327327

0 commit comments

Comments
 (0)