Skip to content

Commit

Permalink
fix: always use available context
Browse files Browse the repository at this point in the history
  • Loading branch information
paullaffitte authored and Nicolasgouze committed Jun 28, 2024
1 parent 7b6b0c1 commit cbbfa60
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions api/core/v1/pod_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ func (a *ImageRewriter) isImageRewritable(container *corev1.Container) error {
func (p *PodInitializer) Start(ctx context.Context) error {
setupLog := ctrl.Log.WithName("setup.pods")
pods := corev1.PodList{}
err := p.Client.List(context.TODO(), &pods)
err := p.Client.List(ctx, &pods)
if err != nil {
return err
}

for _, pod := range pods.Items {
setupLog.Info("patching " + pod.Namespace + "/" + pod.Name)
err := p.Client.Patch(context.Background(), &pod, client.RawPatch(types.JSONPatchType, []byte("[]")))
err := p.Client.Patch(ctx, &pod, client.RawPatch(types.JSONPatchType, []byte("[]")))
if err != nil && !apierrors.IsNotFound(err) {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/kuik/cachedimage_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (r *CachedImageReconciler) Reconcile(ctx context.Context, req ctrl.Request)

// Set owner reference
owner := &kuikv1alpha1.Repository{}
if err := r.Get(context.Background(), client.ObjectKeyFromObject(&repository), owner); err != nil {
if err := r.Get(ctx, client.ObjectKeyFromObject(&repository), owner); err != nil {
return ctrl.Result{}, err
}
if err := controllerutil.SetOwnerReference(owner, &cachedImage, r.Scheme); err != nil {
Expand Down Expand Up @@ -202,7 +202,7 @@ func (r *CachedImageReconciler) Reconcile(ctx context.Context, req ctrl.Request)
if forceUpdate {
delete(cachedImage.Annotations, cachedImageAnnotationForceUpdateName)
}
err = r.Patch(context.Background(), &cachedImage, patch)
err = r.Patch(ctx, &cachedImage, patch)
if err != nil {
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -452,7 +452,7 @@ func (r *CachedImageReconciler) updatePodCount(ctx context.Context, cachedImage
Count: len(pods),
}

err = r.Status().Update(context.Background(), cachedImage)
err = r.Status().Update(ctx, cachedImage)
if err != nil {
if statusErr, ok := err.(*errors.StatusError); ok && statusErr.Status().Code == http.StatusConflict {
requeue = true
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/kuik/repository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (r *RepositoryReconciler) repositoryWithDeletingCachedImages(ctx context.Co
cachedImage := obj.(*kuikv1alpha1.CachedImage)
var currentCachedImage kuikv1alpha1.CachedImage
// wait for the CachedImage to be really deleted
if err := r.Get(context.Background(), client.ObjectKeyFromObject(cachedImage), &currentCachedImage); err == nil || !apierrors.IsNotFound(err) {
if err := r.Get(ctx, client.ObjectKeyFromObject(cachedImage), &currentCachedImage); err == nil || !apierrors.IsNotFound(err) {
return nil
}

Expand Down

0 comments on commit cbbfa60

Please sign in to comment.