Skip to content

Commit 4dc956c

Browse files
committed
UPSTREAM: <carry>: pkg/migrator: Log some errors on V(2)
Some errors that can happen when writing resources back during migration are not particularly significant, yet they can cause a lot or log spam. This change marks some errors coming from the try function to be logged on V(2) so that there are not that many log messages. These include: * conflict * not found * UID precondition failed (effectively a conflict)
1 parent 0f8a4eb commit 4dc956c

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

pkg/migrator/core.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3333
"k8s.io/client-go/dynamic"
3434
"k8s.io/klog/v2"
35-
3635
"sigs.k8s.io/kube-storage-version-migrator/pkg/migrator/metrics"
3736
)
3837

@@ -209,19 +208,11 @@ func (m *migrator) migrateOneItem(ctx context.Context, item *unstructured.Unstru
209208
return nil
210209
}
211210
if canRetry(err) {
212-
seconds, delay := errors.SuggestsClientDelay(err)
213-
switch {
214-
case delay && len(namespace) > 0:
215-
klog.Warningf("migration of %s, in the %s namespace, will be retried after a %ds delay: %v", name, namespace, seconds, err)
216-
time.Sleep(time.Duration(seconds) * time.Second)
217-
case delay:
218-
klog.Warningf("migration of %s will be retried after a %ds delay: %v", name, seconds, err)
219-
time.Sleep(time.Duration(seconds) * time.Second)
220-
case !delay && len(namespace) > 0:
221-
klog.Warningf("migration of %s, in the %s namespace, will be retried: %v", name, namespace, err)
222-
default:
223-
klog.Warningf("migration of %s will be retried: %v", name, err)
224-
}
211+
delaySeconds, _ := errors.SuggestsClientDelay(err)
212+
delay := time.Duration(delaySeconds) * time.Second
213+
klog.V(logLevelForTryError(err)).InfoS("Retrying migration",
214+
"object", klog.KRef(namespace, name), "delay", delay, "err", err)
215+
time.Sleep(delay)
225216
continue
226217
}
227218
// error is not retriable
@@ -244,7 +235,7 @@ func (m *migrator) try(ctx context.Context, namespace, name string, item *unstru
244235
if err == nil {
245236
return false, nil
246237
}
247-
return errors.IsConflict(err), err
238+
return isConflictError(err), err
248239

249240
// TODO: The oc admin uses a defer function to do bandwidth limiting
250241
// after doing all operations. The rate limiter is marked as an alpha

pkg/migrator/errors.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"k8s.io/apimachinery/pkg/api/errors"
2323
"k8s.io/apimachinery/pkg/util/net"
24+
"k8s.io/klog/v2"
2425
)
2526

2627
// ErrRetriable is a wrapper for an error that a migrator may use to indicate the
@@ -52,6 +53,18 @@ func isConnectionRefusedError(err error) bool {
5253
return strings.Contains(err.Error(), "connection refused")
5354
}
5455

56+
// isUIDPreconditionError checks whether the error contains "Precondition failed: UID in precondition".
57+
// This error message is typically present when the resource is deleted before it can be written back.
58+
func isUIDPreconditionError(err error) bool {
59+
return strings.Contains(err.Error(), "Precondition failed: UID in precondition")
60+
}
61+
62+
// isConflictError checks whether the given error is a conflict error.
63+
// This is true when errors.IsConflict or isUIDPreconditionError returns true.
64+
func isConflictError(err error) bool {
65+
return errors.IsConflict(err) || isUIDPreconditionError(err)
66+
}
67+
5568
// interpret adds retry information to the provided error. And it might change
5669
// the error to nil.
5770
func interpret(err error) error {
@@ -63,7 +76,7 @@ func interpret(err error) error {
6376
return nil
6477
case errors.IsMethodNotSupported(err):
6578
return ErrNotRetriable{err}
66-
case errors.IsConflict(err):
79+
case isConflictError(err):
6780
return ErrRetriable{err}
6881
case errors.IsServerTimeout(err):
6982
return ErrRetriable{err}
@@ -91,3 +104,12 @@ func canRetry(err error) bool {
91104
}
92105
return true
93106
}
107+
108+
func logLevelForTryError(err error) klog.Level {
109+
switch {
110+
case errors.IsNotFound(err), isConflictError(err):
111+
return 2
112+
default:
113+
return 0
114+
}
115+
}

0 commit comments

Comments
 (0)