Create creates a resource and enqueues it for reconciliation. If a resource with the same name is currently being deleted, the deletion will be cancelled.
(ctx context.Context, name *runtimev1.ResourceName, refs []*runtimev1.ResourceName, owner *runtimev1.ResourceName, paths []string, hidden bool, r *runtimev1.Resource)
| 491 | // Create creates a resource and enqueues it for reconciliation. |
| 492 | // If a resource with the same name is currently being deleted, the deletion will be cancelled. |
| 493 | func (c *Controller) Create(ctx context.Context, name *runtimev1.ResourceName, refs []*runtimev1.ResourceName, owner *runtimev1.ResourceName, paths []string, hidden bool, r *runtimev1.Resource) error { |
| 494 | if err := c.checkRunning(); err != nil { |
| 495 | return err |
| 496 | } |
| 497 | if ctx.Err() != nil { |
| 498 | return ctx.Err() |
| 499 | } |
| 500 | c.lock(ctx, false) |
| 501 | defer c.unlock(ctx, false) |
| 502 | |
| 503 | // A deleted resource with the same name may exist and be running. If so, we first cancel it. |
| 504 | requeued := false |
| 505 | if inv, ok := c.invocations[nameStr(name)]; ok && !inv.deletedSelf { |
| 506 | r, err := c.catalog.get(name, true, false) |
| 507 | if err != nil { |
| 508 | return fmt.Errorf("internal: got catalog error for reconciling resource: %w", err) |
| 509 | } |
| 510 | if r.Meta.DeletedOn == nil { |
| 511 | // If a non-deleted resource exists with the same name, we should return an error instead of cancelling. |
| 512 | return drivers.ErrResourceAlreadyExists |
| 513 | } |
| 514 | inv.cancel(true) |
| 515 | requeued = true |
| 516 | } |
| 517 | |
| 518 | err := c.catalog.create(name, refs, owner, paths, hidden, r) |
| 519 | if err != nil { |
| 520 | return err |
| 521 | } |
| 522 | |
| 523 | if !requeued { |
| 524 | c.enqueue(name) |
| 525 | } |
| 526 | return nil |
| 527 | } |
| 528 | |
| 529 | // UpdateMeta updates a resource's meta fields and enqueues it for reconciliation. |
| 530 | // If called from outside the resource's reconciler and the resource is currently reconciling, the current reconciler will be cancelled first. |