MCPcopy Create free account
hub / github.com/rilldata/rill / create

Method create

runtime/catalog_cache.go:220–258  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
220func (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.
261func (c *catalogCache) rename(name, newName *runtimev1.ResourceName) error {

Callers

nothing calls this directly

Calls 8

getMethod · 0.95
unlinkMethod · 0.95
linkMethod · 0.95
addEventMethod · 0.95
nameStrFunction · 0.85
reconcilerMethod · 0.80
AssignSpecMethod · 0.65
ResetStateMethod · 0.65

Tested by

no test coverage detected