From 2e7f37353cb21d9cd8572b029d138fdce7846d9b Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 22 Mar 2023 13:31:48 +0100 Subject: [PATCH] test/integration: avoid errors in fake PC controller during shutdown Once the context is canceled, the controller can stop processing events. Without this change it prints errors when the apiserver is already down. --- test/integration/util/util.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/integration/util/util.go b/test/integration/util/util.go index 359459e6846..4a0451d326d 100644 --- a/test/integration/util/util.go +++ b/test/integration/util/util.go @@ -127,7 +127,13 @@ func StartFakePVController(ctx context.Context, clientSet clientset.Interface, i claimRef := obj.Spec.ClaimRef pvc, err := clientSet.CoreV1().PersistentVolumeClaims(claimRef.Namespace).Get(ctx, claimRef.Name, metav1.GetOptions{}) if err != nil { - klog.Errorf("error while getting %v/%v: %v", claimRef.Namespace, claimRef.Name, err) + // Note that the error can be anything, because components like + // apiserver are also shutting down at the same time, but this + // check is conservative and only ignores the "context canceled" + // error while shutting down. + if ctx.Err() == nil || !errors.Is(err, context.Canceled) { + klog.Errorf("error while getting %v/%v: %v", claimRef.Namespace, claimRef.Name, err) + } return } @@ -136,7 +142,10 @@ func StartFakePVController(ctx context.Context, clientSet clientset.Interface, i metav1.SetMetaDataAnnotation(&pvc.ObjectMeta, pvutil.AnnBindCompleted, "yes") _, err := clientSet.CoreV1().PersistentVolumeClaims(claimRef.Namespace).Update(ctx, pvc, metav1.UpdateOptions{}) if err != nil { - klog.Errorf("error while updating %v/%v: %v", claimRef.Namespace, claimRef.Name, err) + if ctx.Err() == nil || !errors.Is(err, context.Canceled) { + // Shutting down, no need to record this. + klog.Errorf("error while updating %v/%v: %v", claimRef.Namespace, claimRef.Name, err) + } return } }