filepath

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Package filepath provides filepath storage related utilities.

Index

Constants

This section is empty.

Variables

View Source
var ErrFileNotExists = fmt.Errorf("file doesn't exist")

ErrFileNotExists means the file doesn't actually exist.

View Source
var ErrNamespaceNotExists = errors.New("namespace does not exist")

ErrNamespaceNotExists means the directory for the namespace doesn't actually exist.

View Source
var VersionError = errors.New("incorrect object version")

Functions

func NewFilepathREST

func NewFilepathREST(
	fs FS,
	ws *WatchSet,
	strategy Strategy,
	groupResource schema.GroupResource,
	codec runtime.Codec,
	rootpath string,
	newFunc func() runtime.Object,
	newListFunc func() runtime.Object,
) rest.Storage

NewFilepathREST instantiates a new REST storage.

func NewJSONFilepathStorageProvider

func NewJSONFilepathStorageProvider(obj resource.Object, rootPath string, fs FS, watchSet *WatchSet, strategy Strategy) builderrest.ResourceHandlerProvider

NewJSONFilepathStorageProvider use local host path as persistent layer storage:

  • For namespaced-scoped resources: the resource will be written under the root-path in the following structure:

    -- (root-path) --- /namespace1/ --- resource1 | | | --- resource2 | --- /namespace2/ --- resource3

  • For cluster-scoped resources, there will be no mid-layer folders for namespaces:

    -- (root-path) --- resource1 | --- resource2 | --- resource3

Args:

fs: An abstraction over the filesystem, so that the JSON can be stored in memory or on-disk. watchSet: Storage for watchers to be notified of this resource type. Each type should have its own

WatchSet, but subresources (like the status subresource) should share a WatchSet with their parent.

Types

type FS

type FS interface {
	Remove(filepath string) error
	Exists(filepath string) bool
	EnsureDir(dirname string) error
	Write(encoder runtime.Encoder, filepath string, obj runtime.Object, storageVersion uint64) error
	Read(decoder runtime.Decoder, path string, newFunc func() runtime.Object) (runtime.Object, error)
	VisitDir(dirname string, newFunc func() runtime.Object, codec runtime.Decoder, visitFunc func(string, runtime.Object) error) (uint64, error)
}

A filesystem interface so we can sub out filesystem-based storage with memory-based storage.

type MemoryFS

type MemoryFS struct {
	// contains filtered or unexported fields
}

An in-memory structure that pretends to be a filesystem, and supports all the storage interfaces that RealFS needs.

func NewMemoryFS

func NewMemoryFS() *MemoryFS

func (*MemoryFS) EnsureDir

func (fs *MemoryFS) EnsureDir(dirname string) error

Create the directory if it does not exist.

func (*MemoryFS) Exists

func (fs *MemoryFS) Exists(p string) bool

Check if the filepath exists.

func (*MemoryFS) Read

func (fs *MemoryFS) Read(decoder runtime.Decoder, p string, newFunc func() runtime.Object) (runtime.Object, error)

Read a copy of the object from our in-memory filesystem.

func (*MemoryFS) Remove

func (fs *MemoryFS) Remove(p string) error

Remove the filepath.

func (*MemoryFS) VisitDir

func (fs *MemoryFS) VisitDir(dirname string, newFunc func() runtime.Object, codec runtime.Decoder, visitFunc func(string, runtime.Object) error) (uint64, error)

Walk the directory, reading all objects in it. Return the ResourceVersion of when we did the read.

func (*MemoryFS) Write

func (fs *MemoryFS) Write(encoder runtime.Encoder, p string, obj runtime.Object, storageVersion uint64) error

Write a copy of the object to our in-memory filesystem.

type RealFS

type RealFS struct {
	// contains filtered or unexported fields
}

func NewRealFS added in v0.10.1

func NewRealFS() *RealFS

func (*RealFS) EnsureDir

func (fs *RealFS) EnsureDir(dirname string) error

func (*RealFS) Exists

func (fs *RealFS) Exists(filepath string) bool

func (*RealFS) Read

func (fs *RealFS) Read(decoder runtime.Decoder, path string, newFunc func() runtime.Object) (runtime.Object, error)

func (*RealFS) Remove

func (fs *RealFS) Remove(filepath string) error

func (*RealFS) VisitDir

func (fs *RealFS) VisitDir(dirname string, newFunc func() runtime.Object, codec runtime.Decoder, visitFunc func(string, runtime.Object) error) (uint64, error)

func (*RealFS) Write

func (fs *RealFS) Write(encoder runtime.Encoder, filepath string, obj runtime.Object, storageVersion uint64) error

type WatchSet added in v0.2.4

type WatchSet struct {
	// contains filtered or unexported fields
}

Keeps track of which watches need to be notified

func NewWatchSet added in v0.2.4

func NewWatchSet() *WatchSet

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL