-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Harden against disruptive loss of apiserver #58
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ import ( | |
"sync" | ||
"time" | ||
|
||
"github.com/kubernetes-sigs/kube-storage-version-migrator/pkg/migrator/metrics" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/api/meta" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
@@ -31,6 +30,9 @@ import ( | |
utilerrors "k8s.io/apimachinery/pkg/util/errors" | ||
utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
"k8s.io/client-go/dynamic" | ||
"k8s.io/klog" | ||
|
||
"github.com/kubernetes-sigs/kube-storage-version-migrator/pkg/migrator/metrics" | ||
) | ||
|
||
var metadataAccessor = meta.NewAccessor() | ||
|
@@ -93,6 +95,10 @@ func (m *migrator) Run() error { | |
Continue: continueToken, | ||
}, | ||
) | ||
if errors.IsNotFound(listError) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should happen only if the resource is deleted, e.g., the CRD is deleted when the migrator is migrating the CR. This should not be counted as a migration failure. I suggest that we log the error, but return nil. (The current code isn't handling this correctly either.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If someone creates a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. Can put this in a comment? |
||
// Fail this migration, we don't want to get stuck on a migration for a resource that does not exist. | ||
return fmt.Errorf("failed to list resources: %v", listError) | ||
} | ||
if listError != nil && !errors.IsResourceExpired(listError) { | ||
if canRetry(listError) { | ||
if seconds, delay := errors.SuggestsClientDelay(listError); delay { | ||
|
@@ -201,8 +207,18 @@ func (m *migrator) migrateOneItem(item *unstructured.Unstructured) error { | |
return nil | ||
} | ||
if canRetry(err) { | ||
if seconds, delay := errors.SuggestsClientDelay(err); delay { | ||
seconds, delay := errors.SuggestsClientDelay(err) | ||
switch { | ||
case delay && len(namespace) > 0: | ||
klog.Warningf("migration of %s, in the %s namespace, will be retried after a %ds delay: %v", name, namespace, seconds, err) | ||
time.Sleep(time.Duration(seconds) * time.Second) | ||
case delay: | ||
klog.Warningf("migration of %s will be retried after a %ds delay: %v", name, seconds, err) | ||
time.Sleep(time.Duration(seconds) * time.Second) | ||
case !delay && len(namespace) > 0: | ||
klog.Warningf("migration of %s, in the %s namespace, will be retried: %v", name, namespace, err) | ||
default: | ||
klog.Warningf("migration of %s will be retried: %v", name, err) | ||
} | ||
continue | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Can you move this log line to before line 127? I feel that's easier to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done