UpdateName renames a resource and updates annotations, and enqueues it for reconciliation. If called from outside the resource's reconciler and the resource is currently reconciling, the current reconciler will be cancelled first.
(ctx context.Context, name, newName, owner *runtimev1.ResourceName, paths []string)
| 565 | // UpdateName renames a resource and updates annotations, and enqueues it for reconciliation. |
| 566 | // If called from outside the resource's reconciler and the resource is currently reconciling, the current reconciler will be cancelled first. |
| 567 | func (c *Controller) UpdateName(ctx context.Context, name, newName, owner *runtimev1.ResourceName, paths []string) error { |
| 568 | if err := c.checkRunning(); err != nil { |
| 569 | return err |
| 570 | } |
| 571 | if ctx.Err() != nil { |
| 572 | return ctx.Err() |
| 573 | } |
| 574 | c.lock(ctx, false) |
| 575 | defer c.unlock(ctx, false) |
| 576 | |
| 577 | if !c.isReconcilerForResource(ctx, name) { |
| 578 | c.cancelIfRunning(name) |
| 579 | c.enqueue(name) |
| 580 | } |
| 581 | |
| 582 | // Check resource exists (otherwise, DAG lookup may panic) |
| 583 | r, err := c.catalog.get(name, false, false) |
| 584 | if err != nil { |
| 585 | return err |
| 586 | } |
| 587 | |
| 588 | // All resources pointing to the old name need to be reconciled (they'll pointing to a void resource after this) |
| 589 | if !c.catalog.isCyclic(name) { |
| 590 | ns := c.catalog.dag.Children(name) |
| 591 | for _, n := range ns { |
| 592 | c.enqueue(n) |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | err = c.safeRename(name, newName) |
| 597 | if err != nil { |
| 598 | return err |
| 599 | } |
| 600 | c.enqueue(newName) |
| 601 | |
| 602 | err = c.catalog.updateMeta(newName, r.Meta.Refs, owner, paths) |
| 603 | if err != nil { |
| 604 | return err |
| 605 | } |
| 606 | |
| 607 | // We updated a name, so it may have broken previous cyclic references |
| 608 | ns := c.catalog.retryCyclicRefs() |
| 609 | for _, n := range ns { |
| 610 | c.enqueue(n) |
| 611 | } |
| 612 | |
| 613 | return nil |
| 614 | } |
| 615 | |
| 616 | // UpdateSpec updates a resource's spec and enqueues it for reconciliation. |
| 617 | // If called from outside the resource's reconciler and the resource is currently reconciling, the current reconciler will be cancelled first. |
no test coverage detected