validation

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package validation contains validators to catch common issues before objects are persisted into the kube-apiserver.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewObjectValidationError

func NewObjectValidationError(
	objRef types.ObjectRef,
	errs ...error,
) error

NewObjectValidationError returns a new ObjectValidationError. Returns nil when no errors are given.

func NewPhaseValidationError

func NewPhaseValidationError(
	phaseName string, phaseErr error, oErrs ...ObjectValidationError,
) error

NewPhaseValidationError returns a new PhaseValidationError. Returns nil when no phase and object errors are given.

func NewRevisionValidationError

func NewRevisionValidationError(
	revisionName string, revisionNumber int64,
	phaseErrs ...PhaseValidationError,
) error

NewRevisionValidationError returns a new RevisionValidationError. Returns nil when no phase errors are given.

Types

type DryRunValidationError

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

DryRunValidationError is returned for APIStatus codes indicating an issue with the object.

func (DryRunValidationError) Error

func (e DryRunValidationError) Error() string

Error implements the error interface.

func (DryRunValidationError) Unwrap

func (e DryRunValidationError) Unwrap() error

Unwrap implements the Unwrap interface for errors.As and errors.Is.

type MustBeInNamespaceError

type MustBeInNamespaceError struct {
	ExpectedNamespace, ActualNamespace string
}

MustBeInNamespaceError is returned when an object is in the wrong namespace.

func (MustBeInNamespaceError) Error

func (e MustBeInNamespaceError) Error() string

Error implements the error interface.

type MustBeNamespaceScopedResourceError

type MustBeNamespaceScopedResourceError struct{}

MustBeNamespaceScopedResourceError is returned when a cluster-scoped resource is used in a namespaced context.

func (MustBeNamespaceScopedResourceError) Error

Error implements the error interface.

type ObjectValidationError

type ObjectValidationError struct {
	// ObjectRef references the object causing the error.
	ObjectRef types.ObjectRef
	// Errors is a list of errors ocurring in the context of the object.
	Errors []error
}

ObjectValidationError gathers multiple errors related to an object.

func (ObjectValidationError) Error

func (e ObjectValidationError) Error() string

Error implements the error interface.

func (ObjectValidationError) String

func (e ObjectValidationError) String() string

String returns a human readable report of all error messages and the context the error was encountered in, if available.

func (ObjectValidationError) Unwrap

func (e ObjectValidationError) Unwrap() []error

Unwrap implements the errors unwrap interface for errors.Is and errors.As.

type ObjectValidator

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

ObjectValidator validates objects for structural, validation or permission scope issues.

func NewClusterObjectValidator

func NewClusterObjectValidator(
	restMapper restMapper,
	writer client.Writer,
) *ObjectValidator

NewClusterObjectValidator returns an ObjectValidator for cross-cluster deployments.

func NewNamespacedObjectValidator

func NewNamespacedObjectValidator(
	restMapper restMapper,
	writer client.Writer,
) *ObjectValidator

NewNamespacedObjectValidator returns an ObjecctValidator for single-namespace deployments.

func (*ObjectValidator) Validate

func (d *ObjectValidator) Validate(
	ctx context.Context,
	obj client.Object,
	opts ...bctypes.ObjectReconcileOption,
) error

Validate validates the given object. The function returns nil, if no validation errors where found. It returns an ObjectValidationError when it was successfully able to validate the Object. It returns a different error when unable to validate the object.

type PhaseNameInvalidError

type PhaseNameInvalidError struct {
	// Name of the phase.
	PhaseName string
	// Error messages describing why the phase name is invalid.
	ErrorMessages []string
}

PhaseNameInvalidError is returned when the phase name does not validate.

func (PhaseNameInvalidError) Error

func (e PhaseNameInvalidError) Error() string

Error implements the error interface.

type PhaseObjectDuplicationError

type PhaseObjectDuplicationError struct {
	PhaseNames []string
}

PhaseObjectDuplicationError is returned when an object is present multiple times in a phase or across multiple phases.

func (PhaseObjectDuplicationError) Error

type PhaseValidationError

type PhaseValidationError struct {
	// Name of the Phase the validation error was raised for.
	PhaseName string
	// Validation error relating to the phase itself.
	PhaseError error
	// Object-scoped errors
	Objects []ObjectValidationError
}

PhaseValidationError gathers multiple validation errors from all objects within a phase.

func (PhaseValidationError) Error

func (e PhaseValidationError) Error() string

Error implements the error interface.

func (PhaseValidationError) String

func (e PhaseValidationError) String() string

String returns a human readable report of all error messages and the context the error was encountered in, if available.

func (PhaseValidationError) Unwrap

func (e PhaseValidationError) Unwrap() []error

Unwrap implements the errors unwrap interface for errors.Is and errors.As.

type PhaseValidator

type PhaseValidator struct {
	*ObjectValidator
}

PhaseValidator valiates a phase with all contained objects. Intended as a preflight check be ensure a higher success chance when rolling out the phase and prevent partial application of phases.

func NewClusterPhaseValidator

func NewClusterPhaseValidator(
	restMapper restMapper,
	writer client.Writer,
) *PhaseValidator

NewClusterPhaseValidator returns an PhaseValidator for cross-cluster deployments.

func NewNamespacedPhaseValidator

func NewNamespacedPhaseValidator(
	restMapper restMapper,
	writer client.Writer,
) *PhaseValidator

NewNamespacedPhaseValidator returns an ObjecctValidator for single-namespace deployments.

func (*PhaseValidator) Validate

func (v *PhaseValidator) Validate(
	ctx context.Context, phase types.Phase, opts ...types.PhaseReconcileOption,
) error

Validate runs validation of the phase and its objects.

type RevisionValidationError

type RevisionValidationError struct {
	RevisionName   string
	RevisionNumber int64
	Phases         []PhaseValidationError
}

RevisionValidationError gathers all validation errors across multiple phases.

func (RevisionValidationError) Error

func (e RevisionValidationError) Error() string

Error implements the error interface.

func (RevisionValidationError) String

func (e RevisionValidationError) String() string

String returns a human readable report of all error messages and the context the error was encountered in, if available.

func (RevisionValidationError) Unwrap

func (e RevisionValidationError) Unwrap() []error

Unwrap implements the errors unwrap interface for errors.Is and errors.As.

type RevisionValidator

type RevisionValidator struct{}

RevisionValidator runs basic validation against all phases and objects making up a revision.

It performes less detailed checks than ObjectValidator or PhaseValidator as detailed checks (using e.g. dry run) should only be run right before a phase is installed to prevent false positives.

func NewRevisionValidator

func NewRevisionValidator() *RevisionValidator

NewRevisionValidator returns a new RevisionValidator instance.

func (*RevisionValidator) Validate

func (v *RevisionValidator) Validate(_ context.Context, rev types.Revision) error

Validate a revision compromising of multiple phases.

Jump to

Keyboard shortcuts

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