Skip to content

Commit 782e4ab

Browse files
Merge pull request #17080 from enj/enj/i/migrate_not_found_doraw_/1506006
Automatic merge from submit-queue. Correctly handle NotFound errors during migration This change makes it so that the migrate storage command will now reprocess the body of a failed GET request to follow the standard path of extracting a status error. This normalizes the structure of the errors the code must handle. When comparing the resource.Info to an error, the info's REST mapping is now used to extract group kind information since the associated runtime.Object is not guaranteed to have valid type meta data. This is combined with relaxed case-insensitive matching to make sure that we only fail the migrate storage command on NotFound errors that we know do not match the info. When a NotFound error occurs, the migrate command now correctly reports that it did not change the resource. Previously it reported that it had successfully migrated the resource, which is not true since it is impossible to migrate a resource that does not exist. Bug 1506006 Signed-off-by: Monis Khan <[email protected]> --- Add timestamps to migration command's reporting This change adds glog style timestamps to the reporting output of the migration tracker. This will aid in debugging migration errors by making it easier to correlate client errors with master logs. Signed-off-by: Monis Khan <[email protected]> --- /assign @smarterclayton /kind bug xref https://bugzilla.redhat.com/show_bug.cgi?id=1506006 @sdodson @jupierce
2 parents 3ea2451 + a5b902e commit 782e4ab

File tree

3 files changed

+373
-10
lines changed

3 files changed

+373
-10
lines changed

pkg/oc/admin/migrate/migrator.go

+23-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"io"
66
"strings"
7+
"time"
78

89
"github.com/golang/glog"
910
"github.com/spf13/cobra"
@@ -49,6 +50,11 @@ func AlwaysRequiresMigration(_ *resource.Info) (Reporter, error) {
4950
return ReporterBool(true), nil
5051
}
5152

53+
// timeStampNow returns the current time in the same format as glog
54+
func timeStampNow() string {
55+
return time.Now().Format("0102 15:04:05.000000")
56+
}
57+
5258
// NotChanged is a Reporter returned by operations that are guaranteed to be read-only
5359
var NotChanged = ReporterBool(false)
5460

@@ -397,9 +403,9 @@ func (t *migrateTracker) report(prefix string, info *resource.Info, err error) {
397403
ns = "-n " + ns
398404
}
399405
if err != nil {
400-
fmt.Fprintf(t.out, "%-10s %s %s/%s: %v\n", prefix, ns, info.Mapping.Resource, info.Name, err)
406+
fmt.Fprintf(t.out, "E%s %-10s %s %s/%s: %v\n", timeStampNow(), prefix, ns, info.Mapping.Resource, info.Name, err)
401407
} else {
402-
fmt.Fprintf(t.out, "%-10s %s %s/%s\n", prefix, ns, info.Mapping.Resource, info.Name)
408+
fmt.Fprintf(t.out, "I%s %-10s %s %s/%s\n", timeStampNow(), prefix, ns, info.Mapping.Resource, info.Name)
403409
}
404410
}
405411

@@ -484,11 +490,13 @@ func canRetry(err error) bool {
484490
// All other errors are left in their natural state - they will not be retried unless
485491
// they define a Temporary() method that returns true.
486492
func DefaultRetriable(info *resource.Info, err error) error {
487-
// tolerate the deletion of resources during migration
488-
if err == nil || isNotFoundForInfo(info, err) {
489-
return nil
490-
}
491493
switch {
494+
case err == nil:
495+
return nil
496+
case isNotFoundForInfo(info, err):
497+
// tolerate the deletion of resources during migration
498+
// report unchanged since we did not actually migrate this object
499+
return ErrUnchanged
492500
case errors.IsMethodNotSupported(err):
493501
return ErrNotRetriable{err}
494502
case errors.IsConflict(err):
@@ -498,8 +506,9 @@ func DefaultRetriable(info *resource.Info, err error) error {
498506
return ErrRetriable{err}
499507
case errors.IsServerTimeout(err):
500508
return ErrRetriable{err}
509+
default:
510+
return err
501511
}
502-
return err
503512
}
504513

505514
// isNotFoundForInfo returns true iff the error is a not found for the specific info object.
@@ -515,6 +524,11 @@ func isNotFoundForInfo(info *resource.Info, err error) bool {
515524
if details == nil {
516525
return false
517526
}
518-
gvk := info.Object.GetObjectKind().GroupVersionKind()
519-
return details.Name == info.Name && details.Kind == gvk.Kind && (details.Group == "" || details.Group == gvk.Group)
527+
// get schema.GroupKind from the mapping since the actual object may not have type meta filled out
528+
gk := info.Mapping.GroupVersionKind.GroupKind()
529+
// based on case-insensitive string comparisons, the error matches info iff
530+
// the name and kind match
531+
// the group match, but only if both the error and info specify a group
532+
return strings.EqualFold(details.Name, info.Name) && strings.EqualFold(details.Kind, gk.Kind) &&
533+
(len(details.Group) == 0 || len(gk.Group) == 0 || strings.EqualFold(details.Group, gk.Group))
520534
}

0 commit comments

Comments
 (0)