packagetypes

package
v1.11.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// OCIPathPrefix defines under which subfolder files within a package container should be located.
	OCIPathPrefix = "package"
	// Package manifest filename without file-extension.
	PackageManifestFilename = "manifest"
	// Package manifest lock filename without file-extension.
	PackageManifestLockFilename = "manifest.lock"
	// Name of the components folder for multi-components.
	ComponentsFolder = "components"
)

Variables

View Source
var (
	// PackageManifestGroupKind is the kubernetes schema group kind of a PackageManifest.
	PackageManifestGroupKind = schema.GroupKind{Group: manifestsv1alpha1.GroupVersion.Group, Kind: "PackageManifest"}
	// PackageManifestLockGroupKind is the kubernetes schema group kind of a PackageManifestLock.
	PackageManifestLockGroupKind = schema.GroupKind{
		Group: manifestsv1alpha1.GroupVersion.Group, Kind: "PackageManifestLock",
	}
)
View Source
var ErrEmptyPackage = ViolationError{
	Reason: ViolationReasonEmptyPackage,
}
View Source
var ErrManifestNotFound = ViolationError{
	Reason:  ViolationReasonPackageManifestNotFound,
	Details: fmt.Sprintf("searched at %s.yaml and %s.yml", PackageManifestFilename, PackageManifestFilename),
}

ErrManifestNotFound indicates that a package manifest was not found at any expected location.

Functions

func IsTemplateFile

func IsTemplateFile(path string) bool

Is path suffixed by [TemplateFileSuffix].

func IsYAMLFile

func IsYAMLFile(fileName string) bool

IsYAMLFile return true if the given fileName is suffixed by .yml or .yaml.

func StripTemplateSuffix

func StripTemplateSuffix(path string) string

StripTemplateSuffix removes a [TemplateFileSuffix] suffix from a string if present.

func ValidateEachComponent added in v1.11.0

func ValidateEachComponent(
	ctx context.Context, pkg *Package,
	validateFn func(context.Context, *Package, bool) error,
) error

Types

type Files

type Files map[string][]byte

Files is an in-memory representation of the package FileSystem. It maps file paths to their contents.

func (Files) DeepCopy

func (f Files) DeepCopy() Files

Returns a deep copy of the files map.

type ObjectValidator

type ObjectValidator interface {
	ValidateObjects(
		ctx context.Context,
		manifest *manifests.PackageManifest,
		objects map[string][]unstructured.Unstructured,
	) error
}

ObjectValidator knows how to validate objects within a Package.

type Package

type Package struct {
	Manifest     *manifests.PackageManifest
	ManifestLock *manifests.PackageManifestLock
	Files        Files
	Components   []Package
}

Package has passed basic schema/structure admission. Exact output still depends on configuration and the install environment.

func (*Package) DeepCopy

func (p *Package) DeepCopy() *Package

Returns a deep copy of the RawPackage map.

type PackageInstance

type PackageInstance struct {
	Manifest     *manifests.PackageManifest
	ManifestLock *manifests.PackageManifestLock
	Objects      []unstructured.Unstructured
}

PackageInstance is the concrete instance of a package after rendering templates from configuration and environment information.

type PackageRenderContext

type PackageRenderContext struct {
	Package     manifests.TemplateContextPackage `json:"package"`
	Config      map[string]any                   `json:"config"`
	Images      map[string]string                `json:"images"`
	Environment manifests.PackageEnvironment     `json:"environment"`
}

PackageRenderContext contains all data that is needed to render a Package into a PackageInstance.

type PackageValidator

type PackageValidator interface {
	ValidatePackage(ctx context.Context, pkg *Package) error
}

PackageValidator knows how to validate Packages.

type RawPackage

type RawPackage struct {
	Files Files
}

RawPackage right after import. No validation has been performed yet.

func (*RawPackage) DeepCopy

func (rp *RawPackage) DeepCopy() *RawPackage

Returns a deep copy of the RawPackage map.

type ViolationError

type ViolationError struct {
	Reason    ViolationReason // Reason is a [ViolationReason] which shortly describes what the reason of this error is.
	Details   string          // Details describes the violation and what to do against it in a more verbose matter.
	Path      string          // Path shows which file path in the package is responsible for this error.
	Component string          // Component indicates which component the error is associated with
	Index     *int            // Index is the index of the YAML document within Path.
	Subject   string          // Complete subject producing the error, may be the whole yaml file, a single document, etc.
}

ViolationError describes the reason why and which part of a package is violating sanitation checks.

func (ViolationError) Error

func (v ViolationError) Error() string

type ViolationReason

type ViolationReason string

ViolationReason describes in short how something violates violating sanitation checks.

const (
	ViolationReasonEmptyPackage                  ViolationReason = "Package image contains no files. Might be corrupted."
	ViolationReasonPackageManifestNotFound       ViolationReason = "PackageManifest not found"
	ViolationReasonUnknownGVK                    ViolationReason = "unknown GVK"
	ViolationReasonPackageManifestInvalid        ViolationReason = "PackageManifest invalid"
	ViolationReasonPackageManifestDuplicated     ViolationReason = "PackageManifest present multiple times"
	ViolationReasonPackageManifestLockInvalid    ViolationReason = "PackageManifestLock invalid"
	ViolationReasonPackageManifestLockDuplicated ViolationReason = "PackageManifestLock present multiple times"
	ViolationReasonInvalidYAML                   ViolationReason = "Invalid YAML"
	ViolationReasonMissingPhaseAnnotation        ViolationReason = "Missing " + manifests.PackagePhaseAnnotation + " Annotation" //nolint: lll
	ViolationReasonMissingGVK                    ViolationReason = "GroupVersionKind not set"
	ViolationReasonDuplicateObject               ViolationReason = "Duplicate Object"
	ViolationReasonLabelsInvalid                 ViolationReason = "Labels invalid"
	ViolationReasonUnsupportedScope              ViolationReason = "Package unsupported scope"
	ViolationReasonFixtureMismatch               ViolationReason = "File mismatch against fixture"
	ViolationReasonComponentsNotEnabled          ViolationReason = "Components not enabled"
	ViolationReasonComponentNotFound             ViolationReason = "Component not found"
	ViolationReasonInvalidComponentPath          ViolationReason = "Invalid component path"
	ViolationReasonUnknown                       ViolationReason = "Unknown reason"
	ViolationReasonNestedMultiComponentPkg       ViolationReason = "Nesting multi-component packages not allowed"
	ViolationReasonInvalidFileInComponentsDir    ViolationReason = "The components directory may only contain folders and dot files" //nolint: lll
	ViolationReasonKubeconform                   ViolationReason = "Kubeconform rejected schema"
	ViolationReasonLockfileMissing               ViolationReason = "Missing image in manifest.lock.yaml, but using PackageManifest.spec.images. Try running: kubectl package update" //nolint: lll
	ViolationReasonImageMissingInLockfile        ViolationReason = "Image specified in manifest but missing from lockfile. Try running: kubectl package update"                      //nolint: lll
	ViolationReasonImageDifferentToLockfile      ViolationReason = "Image specified in manifest does not match with lockfile. Try running: kubectl package update"                   //nolint: lll
	ViolationReasonInvalidCELExpression          ViolationReason = "The CEL expression in " + manifests.PackageCELConditionAnnotation + " annotation is invalid."                    //nolint: lll
)

Predefined reasons for package violations.

Jump to

Keyboard shortcuts

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