Skip to content

Commit 6a07e76

Browse files
committed
CRD migration: continue migrating storage version / cleaning up managedFields after failure
1 parent afc36d4 commit 6a07e76

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

controllers/crdmigrator/crd_migrator.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ func (r *CRDMigrator) reconcileStorageVersionMigration(ctx context.Context, crd
374374
Kind: crd.Spec.Names.Kind,
375375
}
376376

377+
errs := []error{}
377378
for _, obj := range customResourceObjects {
378379
e := objectEntry{
379380
Kind: gvk.Kind,
@@ -406,12 +407,17 @@ func (r *CRDMigrator) reconcileStorageVersionMigration(ctx context.Context, crd
406407
// If we got a NotFound error, the object no longer exists so no need to update it.
407408
// If we got a Conflict error, another client wrote the object already so no need to update it.
408409
if err != nil && !apierrors.IsNotFound(err) && !apierrors.IsConflict(err) {
409-
return errors.Wrapf(err, "failed to migrate storage version of %s %s", gvk.Kind, klog.KObj(u))
410+
errs = append(errs, errors.Wrap(err, klog.KObj(u).String()))
411+
continue
410412
}
411413

412414
r.storageVersionMigrationCache.Add(e)
413415
}
414416

417+
if len(errs) > 0 {
418+
return errors.Wrapf(kerrors.NewAggregate(errs), "failed to migrate storage version of %s objects", gvk.Kind)
419+
}
420+
415421
return nil
416422
}
417423

@@ -431,6 +437,7 @@ func (r *CRDMigrator) reconcileCleanupManagedFields(ctx context.Context, crd *ap
431437
}
432438
}
433439

440+
errs := []error{}
434441
for _, obj := range customResourceObjects {
435442
if len(obj.GetManagedFields()) == 0 {
436443
continue
@@ -512,10 +519,15 @@ func (r *CRDMigrator) reconcileCleanupManagedFields(ctx context.Context, crd *ap
512519
// Note: We always have to return the conflict error directly (instead of an aggregate) so retry on conflict works.
513520
return err
514521
}); err != nil {
515-
return errors.Wrapf(kerrors.NewAggregate([]error{err, getErr}), "failed to cleanup managedFields of %s %s", crd.Spec.Names.Kind, klog.KObj(obj))
522+
errs = append(errs, errors.Wrap(kerrors.NewAggregate([]error{err, getErr}), klog.KObj(obj).String()))
523+
continue
516524
}
517525
}
518526

527+
if len(errs) > 0 {
528+
return errors.Wrapf(kerrors.NewAggregate(errs), "failed to cleanup managedFields of %s objects", crd.Spec.Names.Kind)
529+
}
530+
519531
return nil
520532
}
521533

0 commit comments

Comments
 (0)