Documentation
¶
Index ¶
- Constants
- Variables
- func IsTemplateFile(path string) bool
- func IsYAMLFile(fileName string) bool
- func JoinYAMLDocuments(documents [][]byte) []byte
- func SplitYAMLDocuments(file []byte) (docs [][]byte)
- func StripTemplateSuffix(path string) string
- func ValidateEachComponent(ctx context.Context, pkg *Package, ...) error
- type Files
- type ObjectValidator
- type Package
- type PackageInstance
- type PackageRenderContext
- type PackageValidator
- type RawPackage
- type ViolationError
- type ViolationReason
Constants ¶
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 ¶
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", } )
var ErrEmptyPackage = ViolationError{ Reason: ViolationReasonEmptyPackage, }
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 ¶
Is path suffixed by [TemplateFileSuffix].
func IsYAMLFile ¶
IsYAMLFile return true if the given fileName is suffixed by .yml or .yaml.
func JoinYAMLDocuments ¶ added in v1.12.0
Joins multiple YAML documents together.
func SplitYAMLDocuments ¶ added in v1.12.0
Splits a YAML file into multiple documents.
func StripTemplateSuffix ¶
StripTemplateSuffix removes a [TemplateFileSuffix] suffix from a string if present.
Types ¶
type Files ¶
Files is an in-memory representation of the package FileSystem. It maps file paths to their contents.
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.
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 ¶
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 ViolationReasonPhaseNotFound ViolationReason = "Phase name not found in manifest" //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.