schema

package
v3.18.1 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ErrConflictingSchemaType = "ErrConflictingSchema"
View Source
const ErrNilMutator = util.Error("attempted to add nil mutator")

ErrNilMutator reports that a method which expected an actual Mutator was a nil pointer.

View Source
const ErrNotFound = util.Error("path not found")
View Source
const Set = parser.NodeType("Set")

Set represents a list populated by unique values.

View Source
const String = parser.NodeType("String")

String represents a string element.

View Source
const Unknown = parser.NodeType("Unknown")

Unknown represents a path element we do not know the type of. Elements of type unknown do not conflict with path elements of known types.

Variables

This section is empty.

Functions

func NewErrConflictingSchema

func NewErrConflictingSchema(ids IDSet) error

Types

type DB

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

DB is a database that caches all the implied schemas. Returns an error when upserting a mutator which conflicts with the existing ones.

Mutators implicitly define a part of the schema of the object they intend to mutate. For example, modifying `spec.containers[name: foo].image` implies that: - spec is an object - containers is a list - image exists, but no type information

If another mutator on the same GVK declares that it modifies `spec.containers.image`, then we know we have a contradiction as that path implies containers is an object.

Conflicting schemas are stored within DB. HasConflicts returns true for the IDs of Mutators with conflicting schemas until Remove() is called on the Mutators which conflict with the ID.

func New

func New() *DB

New returns a new schema database.

func (*DB) GetConflicts

func (db *DB) GetConflicts(id types.ID) IDSet

func (*DB) HasConflicts

func (db *DB) HasConflicts(id types.ID) bool

HasConflicts returns true if the Mutator of the passed ID has been upserted in DB and has conflicts with another Mutator. Returns false if the Mutator does not exist.

func (*DB) Remove

func (db *DB) Remove(id types.ID)

Remove removes the mutator with the given id from the db.

func (*DB) Upsert

func (db *DB) Upsert(mutator MutatorWithSchema) error

Upsert inserts or updates the given mutator. Returns an error if the implicit schema in mutator conflicts with any mutators previously added.

Schema conflicts are only detected using mutator.Path() - DB does not check that assigned types are compatible. For example, one Mutator might assign a string to a path and another might assign a list.

type ErrConflictingSchema

type ErrConflictingSchema struct {
	Conflicts IDSet
}

ErrConflictingSchema reports that adding a Mutator to the DB resulted in conflicting implicit schemas.

func (ErrConflictingSchema) Error

func (e ErrConflictingSchema) Error() string

func (ErrConflictingSchema) Is

func (e ErrConflictingSchema) Is(other error) bool

type IDSet

type IDSet map[types.ID]bool

func (IDSet) String

func (c IDSet) String() string

func (IDSet) ToList

func (c IDSet) ToList() []types.ID

type MutatorWithSchema

type MutatorWithSchema interface {
	types.Mutator

	// SchemaBindings returns the set of GVKs this Mutator applies to.
	SchemaBindings() []schema.GroupVersionKind

	// TerminalType specifies the inferred type of the last node in a path
	TerminalType() parser.NodeType
}

MutatorWithSchema is a mutator exposing the implied schema of the target object.

Jump to

Keyboard shortcuts

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