create creates a resource in the catalog. It will error if a resource with the same name already exists. If a soft-deleted resource exists with the same name, it will be overwritten (no longer deleted). The passed resource should only have its spec populated. The meta and state fields will be popula
(name *runtimev1.ResourceName, refs []*runtimev1.ResourceName, owner *runtimev1.ResourceName, paths []string, hidden bool, r *runtimev1.Resource)
| 218 | // If a soft-deleted resource exists with the same name, it will be overwritten (no longer deleted). |
| 219 | // The passed resource should only have its spec populated. The meta and state fields will be populated by this function. |
| 220 | func (c *catalogCache) create(name *runtimev1.ResourceName, refs []*runtimev1.ResourceName, owner *runtimev1.ResourceName, paths []string, hidden bool, r *runtimev1.Resource) error { |
| 221 | existing, _ := c.get(name, true, false) |
| 222 | if existing != nil { |
| 223 | if existing.Meta.DeletedOn == nil { |
| 224 | return drivers.ErrResourceAlreadyExists |
| 225 | } |
| 226 | c.unlink(existing) // If creating a resource that's currently soft-deleted, it'll be like the previous delete never happened. |
| 227 | } |
| 228 | r.Meta = &runtimev1.ResourceMeta{ |
| 229 | Name: name, |
| 230 | Refs: refs, |
| 231 | Owner: owner, |
| 232 | FilePaths: paths, |
| 233 | Hidden: hidden, |
| 234 | Version: 1, |
| 235 | SpecVersion: 1, |
| 236 | StateVersion: 1, |
| 237 | CreatedOn: timestamppb.Now(), |
| 238 | SpecUpdatedOn: timestamppb.Now(), |
| 239 | StateUpdatedOn: timestamppb.Now(), |
| 240 | ReconcileStatus: runtimev1.ReconcileStatus_RECONCILE_STATUS_IDLE, |
| 241 | } |
| 242 | if existing != nil { |
| 243 | r.Meta.Version = existing.Meta.Version + 1 |
| 244 | r.Meta.SpecVersion = existing.Meta.SpecVersion + 1 |
| 245 | } |
| 246 | err := c.ctrl.reconciler(name.Kind).AssignSpec(r, r) // Self-assign spec through reconciler to ensure spec and kind have matching types |
| 247 | if err != nil { |
| 248 | return err |
| 249 | } |
| 250 | err = c.ctrl.reconciler(name.Kind).ResetState(r) |
| 251 | if err != nil { |
| 252 | return err |
| 253 | } |
| 254 | c.link(r) |
| 255 | c.dirty[nameStr(r.Meta.Name)] = r.Meta.Name |
| 256 | c.addEvent(name, r, runtimev1.ResourceEvent_RESOURCE_EVENT_WRITE) |
| 257 | return nil |
| 258 | } |
| 259 | |
| 260 | // rename renames a resource in the catalog and sets the r.Meta.RenamedFrom field. |
| 261 | func (c *catalogCache) rename(name, newName *runtimev1.ResourceName) error { |
nothing calls this directly
no test coverage detected