validate

package
v0.0.1-test Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package validate implements offline schema validation of Crossplane resources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsErrBaseLayerNotFound

func IsErrBaseLayerNotFound(err error) bool

IsErrBaseLayerNotFound checks if the error is of type BaseLayerNotFoundError.

func NewBaseLayerNotFoundError

func NewBaseLayerNotFoundError(image string) error

NewBaseLayerNotFoundError returns a new BaseLayerNotFoundError error.

Types

type BaseLayerNotFoundError

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

BaseLayerNotFoundError is returned when the base layer of the image could not be found.

func (*BaseLayerNotFoundError) Error

func (e *BaseLayerNotFoundError) Error() string

Error implements the error interface.

type Cache

type Cache interface {
	Store(schemas [][]byte, path string) error
	Flush() error
	Init() error
	Load(image string) ([]*unstructured.Unstructured, error)
	Exists(image string) (string, error)
}

Cache defines an interface for caching schemas.

type Cmd

type Cmd struct {
	// Arguments.
	Extensions string `arg:"" help:"Extension sources as a comma-separated list of files, directories, or '-' for standard input."`
	Resources  string `arg:"" help:"Resource sources as a comma-separated list of files, directories, or '-' for standard input."`

	// Flags. Keep them in alphabetical order.
	CacheDir              string `` /* 159-byte string literal not displayed */
	CleanCache            bool   `help:"Clean the cache directory before downloading package schemas."`
	CrossplaneImage       string `` /* 137-byte string literal not displayed */
	ErrorOnMissingSchemas bool   `default:"false"                                                      help:"Return non zero exit code if missing schemas."`
	// rendererFlag.Decode rejects unknown formats, which is what Kong's
	// "enum" tag would normally enforce — but enum doesn't apply to
	// MapperValue-backed fields. The help text is the user-facing list
	// of valid values.
	Output             rendererFlag `` /* 307-byte string literal not displayed */
	SkipSuccessResults bool         `help:"Skip printing success results."`
	UpdateCache        bool         `` /* 297-byte string literal not displayed */
	// contains filtered or unexported fields
}

Cmd arguments and flags for render subcommand.

func (*Cmd) AfterApply

func (c *Cmd) AfterApply() error

AfterApply implements kong.AfterApply. The renderer is already resolved by Kong's MapperValue plumbing on Cmd.Output by the time this runs, so AfterApply only sets the filesystem.

func (*Cmd) Help

func (c *Cmd) Help() string

Help prints out the help for the validate command.

func (*Cmd) Run

func (c *Cmd) Run(k *kong.Context, _ logging.Logger) error

Run validate.

type Fetcher

type Fetcher struct{}

Fetcher implements the ImageFetcher interface.

func (*Fetcher) FetchBaseLayer

func (f *Fetcher) FetchBaseLayer(image string) (string, *conregv1.Layer, error)

FetchBaseLayer fetches the base layer of the image which contains the 'package.yaml' file.

func (*Fetcher) FetchImage

func (f *Fetcher) FetchImage(image string) (string, []conregv1.Layer, error)

FetchImage pulls the full image and extracts the CRDs folder to fetch .yaml files.

type ImageFetcher

type ImageFetcher interface {
	FetchBaseLayer(image string) (string, *conregv1.Layer, error)
	FetchImage(image string) (string, []conregv1.Layer, error)
}

ImageFetcher defines an interface for fetching images.

type LocalCache

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

LocalCache implements the Cache interface.

func (*LocalCache) Exists

func (c *LocalCache) Exists(image string) (string, error)

Exists checks if the cache contains the image and returns the path if it doesn't exist. If the image contains a semantic version constraint, the returned cache-path will include it on cache miss, as it can not be resolved by the cache.

func (*LocalCache) Flush

func (c *LocalCache) Flush() error

Flush removes the cache directory.

func (*LocalCache) Init

func (c *LocalCache) Init() error

Init creates the cache directory if it doesn't exist.

func (*LocalCache) Load

func (c *LocalCache) Load(image string) ([]*unstructured.Unstructured, error)

Load loads schemas from the cache directory. image should be a validated image name with the format: <registry>/<image>:<tag>. <tag> can be a constraint, in which case the latest version of the schema that satisfies this constraint is loaded from the cache.

func (*LocalCache) Store

func (c *LocalCache) Store(schemas [][]byte, path string) error

Store stores the schemas in the directory.

type Manager

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

Manager defines a Manager for preparing Crossplane packages for validation.

func NewManager

func NewManager(cacheDir string, fs afero.Fs, w io.Writer, opts ...Option) *Manager

NewManager returns a new Manager.

func (*Manager) CRDs

func (m *Manager) CRDs() []*extv1.CustomResourceDefinition

CRDs returns the collected CRDs.

func (*Manager) CacheAndLoad

func (m *Manager) CacheAndLoad(cleanCache bool) error

CacheAndLoad finds and caches dependencies and loads them as CRDs.

func (*Manager) PrepExtensions

func (m *Manager) PrepExtensions(extensions []*unstructured.Unstructured) error

PrepExtensions converts the unstructured XRDs/CRDs to CRDs and extract package images to add as a dependency.

type Option

type Option func(*Manager)

Option defines an option for the Manager.

func WithCrossplaneImage

func WithCrossplaneImage(image string) Option

WithCrossplaneImage sets the Crossplane image to use for fetching CRDs.

func WithUpdateCache

func WithUpdateCache(update bool) Option

WithUpdateCache forces re-downloading packages with ranged semver constraints even when a matching version is already cached.

Jump to

Keyboard shortcuts

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