diff --git a/pkg/registry/file/storage.go b/pkg/registry/file/storage.go index c3bd34b3c..328c504f7 100644 --- a/pkg/registry/file/storage.go +++ b/pkg/registry/file/storage.go @@ -193,7 +193,7 @@ func (s *StorageImpl) writeFiles(key string, obj runtime.Object, metaOut runtime return nil } -// Create adds a new object at a key even when it already exists. 'ttl' is time-to-live +// Create adds a new object at a key unless it already exists. 'ttl' is time-to-live // in seconds (and is ignored). If no error is returned and out is not nil, out will be // set to the read value from database. func (s *StorageImpl) Create(ctx context.Context, key string, obj, metaOut runtime.Object, _ uint64) error { @@ -204,6 +204,10 @@ func (s *StorageImpl) Create(ctx context.Context, key string, obj, metaOut runti s.locks.Lock(key) defer s.locks.Unlock(key) spanLock.End() + // check if object already exists + if _, err := s.appFs.Stat(makePayloadPath(filepath.Join(s.root, key))); err == nil { + return storage.NewKeyExistsError(key, 0) + } // resourceVersion should not be set on create if version, err := s.versioner.ObjectResourceVersion(obj); err == nil && version != 0 { msg := "resourceVersion should not be set on objects to be created"