Documentation
¶
Overview ¶
Package pkg defines the concept of a kpt package.
Package pkg contains utility functions for packages
Index ¶
- Constants
- Variables
- func ClearInternalAnnotations(annotations map[string]string)
- func CopyPackage(src, dst string, copyRootKptfile bool, matcher SubpackageMatcher) error
- func DecodeRGFile(in io.Reader) (*rgfilev1alpha1.ResourceGroup, error)
- func Exists(path string) (bool, error)
- func FindSubpackagesForPaths(matcher SubpackageMatcher, recurse bool, pkgPaths ...string) ([]string, error)
- func FormatPackage(pkgPath string)
- func GetPkgPathAnnotation(rn *yaml.RNode) (string, error)
- func ImageBaseName(fullName string) string
- func IsPackageDir(fsys filesys.FileSystem, path string) (bool, error)
- func IsPackageUnfetched(path string) (bool, error)
- func PipelineStepNameOrImage(name, image string) string
- func ReadRGFile(pkgPath, rgfile string) (*rgfilev1alpha1.ResourceGroup, error)
- func RemovePackageContent(path string, removeRootKptfile bool) error
- func RemovePkgPathAnnotation(rn *yaml.RNode) error
- func RemoveStaleItems(org, src, dst string, _ bool, _ SubpackageMatcher) error
- func RootPkgFirstSorter(paths []string) func(i, j int) bool
- func RoundTripKptfilesInPkg(pkgPath string) error
- func SetPkgPathAnnotation(rn *yaml.RNode, pkgPath types.UniquePath) error
- func SubPkgFirstSorter(paths []string) func(i, j int) bool
- func Subpackages(fsys filesys.FileSystem, rootPath string, matcher SubpackageMatcher, ...) ([]string, error)
- func WalkPackage(src string, c func(string, os.FileInfo, error) error) error
- type InvInfoInvalid
- type MultipleInventoryInfoError
- type MultipleKfInv
- type MultipleResourceGroupsError
- type NoInvInfoError
- type Pkg
- func (p *Pkg) DirectSubpackages() ([]*Pkg, error)
- func (p *Pkg) Kptfile() (*kptfilev1.KptFile, error)
- func (p *Pkg) LocalInventory() (kptfilev1.Inventory, error)
- func (p *Pkg) LocalResources() (resources []*yaml.RNode, err error)
- func (p *Pkg) Pipeline() (*kptfilev1.Pipeline, error)
- func (p *Pkg) ReadRGFile(rgfile string) (*rgfilev1alpha1.ResourceGroup, error)
- func (p *Pkg) RelativePathTo(ancestorPkg *Pkg) (string, error)
- func (p *Pkg) String() string
- func (p *Pkg) ValidatePipeline() error
- type RGError
- type RemoteKptfileError
- type SubpackageMatcher
Constants ¶
const CurDir = "."
const ParentDir = ".."
Variables ¶
var MatchAllKRM = append([]string{kptfilev1.KptFileName}, kio.MatchAll...)
MatchAllKRM represents set of glob pattern to match all KRM resources including Kptfile.
Functions ¶
func CopyPackage ¶
func CopyPackage(src, dst string, copyRootKptfile bool, matcher SubpackageMatcher) error
CopyPackage copies the content of a single package from src to dst. If includeSubpackages is true, it will copy resources belonging to any subpackages.
func DecodeRGFile ¶
func DecodeRGFile(in io.Reader) (*rgfilev1alpha1.ResourceGroup, error)
DecodeRGFile converts a string reader into structured a ResourceGroup object.
func Exists ¶
Exists returns true if a file or directory exists on the provided path, and false otherwise.
func FindSubpackagesForPaths ¶
func FindSubpackagesForPaths(matcher SubpackageMatcher, recurse bool, pkgPaths ...string) ([]string, error)
FindSubpackagesForPaths traverses the provided package paths and finds all subpackages using the provided pkgLocatorFunc
func FormatPackage ¶
func FormatPackage(pkgPath string)
FormatPackage formats resources and meta-resources in the package and all its subpackages
func GetPkgPathAnnotation ¶
GetPkgPathAnnotation returns the package path annotation on a given resource.
func ImageBaseName ¶
ImageBaseName extracts the "base name" from a full/partial image repository name
TODO: This probably already exist somewhere
func IsPackageDir ¶
func IsPackageDir(fsys filesys.FileSystem, path string) (bool, error)
IsPackageDir checks if there exists a Kptfile on the provided path, i.e. whether the provided path is the root of a package.
func IsPackageUnfetched ¶
IsPackageUnfetched returns true if a package has Upstream information, but no UpstreamLock. For local packages that doesn't have Upstream information, it will always return false. If a Kptfile is not found on the provided path, an error will be returned.
func PipelineStepNameOrImage ¶
PipelineStepNameOrImage returns the name if it's not empty or extracts the base name of the image
func ReadRGFile ¶
func ReadRGFile(pkgPath, rgfile string) (*rgfilev1alpha1.ResourceGroup, error)
ReadRGFile reads the resourcegroup inventory in the given pkg.
func RemovePackageContent ¶
func RemovePkgPathAnnotation ¶
RemovePkgPathAnnotation removes the package path on a given resource.
func RemoveStaleItems ¶
func RemoveStaleItems(org, src, dst string, _ bool, _ SubpackageMatcher) error
RemoveStaleItems removes files and directories from the dst package that were present in the org package, but are not present in the src package. It does not remove the root Kptfile of the dst package.
func RootPkgFirstSorter ¶
RootPkgFirstSorter returns a "less" function that can be used with the sort.Slice function to correctly sort package paths so parent packages are always before subpackages.
func RoundTripKptfilesInPkg ¶
RoundTripKptfilesInPkg reads and writes all Kptfiles in the package including subpackages. This is used to format Kptfiles in the order of go structures TODO: phanimarupaka remove this method after addressing https://github.com/kptdev/kpt/issues/2052
func SetPkgPathAnnotation ¶
func SetPkgPathAnnotation(rn *yaml.RNode, pkgPath types.UniquePath) error
SetPkgPathAnnotation sets package path on a given resource.
func SubPkgFirstSorter ¶
SubPkgFirstSorter returns a "less" function that can be used with the sort.Slice function to correctly sort package paths so subpackages are always before parent packages.
func Subpackages ¶
func Subpackages(fsys filesys.FileSystem, rootPath string, matcher SubpackageMatcher, recursive bool) ([]string, error)
Subpackages returns a slice of paths to any subpackages of the provided path. The matcher parameter decides the types of subpackages should be considered(ALL/LOCAL/REMOTE/NONE), and the recursive parameter determines if only direct subpackages are considered. All returned paths will be relative to the provided rootPath. The top level package is not considered a subpackage. If the provided path doesn't exist, an empty slice will be returned. Symlinks are ignored. TODO: For now this accepts the path as a string type. See if we can leverage the package type here.
Types ¶
type InvInfoInvalid ¶
type InvInfoInvalid struct{}
func (*InvInfoInvalid) Error ¶
func (e *InvInfoInvalid) Error() string
type MultipleInventoryInfoError ¶
type MultipleInventoryInfoError struct{}
MultipleInventoryInfoError is the error returned if there are multiple inventories provided in a stream or package contained with both Kptfile and ResourceGroup objects.
func (*MultipleInventoryInfoError) Error ¶
func (e *MultipleInventoryInfoError) Error() string
type MultipleKfInv ¶
type MultipleKfInv struct{}
MultipleKfInv is the error returned if there are multiple inventories provided in a stream or package as ResourceGroup objects.
func (*MultipleKfInv) Error ¶
func (e *MultipleKfInv) Error() string
type MultipleResourceGroupsError ¶
type MultipleResourceGroupsError struct{}
MultipleResourceGroupsError is the error returned if there are multiple inventories provided in a stream or package as ResourceGroup objects.
func (*MultipleResourceGroupsError) Error ¶
func (e *MultipleResourceGroupsError) Error() string
type NoInvInfoError ¶
type NoInvInfoError struct{}
NoInvInfoError is the error returned if there are no inventory information provided in either a stream or locally.
func (*NoInvInfoError) Error ¶
func (e *NoInvInfoError) Error() string
type Pkg ¶
type Pkg struct {
// UniquePath represents absolute unique OS-defined path to the package directory on the filesystem.
UniquePath types.UniquePath
// DisplayPath represents Slash-separated path to the package directory on the filesystem relative
// to parent directory of root package on which the command is invoked.
// root package is defined as the package on which the command is invoked by user
// This is not guaranteed to be unique (e.g. in presence of symlinks) and should only
// be used for display purposes and is subject to change.
DisplayPath types.DisplayPath
// contains filtered or unexported fields
}
Pkg represents a kpt package with a one-to-one mapping to a directory on the local filesystem.
func New ¶
func New(fs filesys.FileSystem, path string) (*Pkg, error)
New returns a pkg given an absolute OS-defined path. Use ReadKptfile or ReadPipeline on the return value to read meta resources from filesystem.
func (*Pkg) DirectSubpackages ¶
DirectSubpackages returns subpackages of a pkg. It will return all direct subpackages, i.e. subpackages that aren't nested inside other subpackages under the current package. It will return packages that are nested inside directories of the current package. TODO: This does not support symlinks, so we need to figure out how we should support that with kpt.
func (*Pkg) Kptfile ¶
Kptfile returns the Kptfile meta resource by lazy loading it from the filesytem. A nil value represents an implicit package.
func (*Pkg) LocalInventory ¶
LocalInventory returns the package inventory stored within a package. If more than one, or no inventories are found, an error is returned instead.
func (*Pkg) LocalResources ¶
LocalResources returns resources that belong to this package excluding the subpackage resources.
func (*Pkg) Pipeline ¶
Pipeline returns the Pipeline section of the pkg's Kptfile. if pipeline is not specified in a Kptfile, it returns Zero value of the pipeline.
func (*Pkg) ReadRGFile ¶
func (p *Pkg) ReadRGFile(rgfile string) (*rgfilev1alpha1.ResourceGroup, error)
ReadRGFile returns the resourcegroup object by lazy loading it from the filesytem.
func (*Pkg) RelativePathTo ¶
RelativePathTo returns current package's path relative to a given package. It returns an error if relative path doesn't exist. In a nested package chain, one can use this method to get the relative path of a subpackage relative to an ancestor package up the chain. Example: rel, _ := subpkg.RelativePathTo(rootPkg) The returned relative path is compatible with the target operating system-defined file paths.
func (*Pkg) ValidatePipeline ¶
Validates the package pipeline.
type RGError ¶
type RGError struct {
Path types.UniquePath
Err error
}
RGError is an implementation of the error interface that is returned whenever kpt encounters errors reading a resourcegroup object file.
type RemoteKptfileError ¶
RemoteKptfileError records errors regarding reading or parsing of a Kptfile in a remote repo.
func (*RemoteKptfileError) Error ¶
func (e *RemoteKptfileError) Error() string
func (*RemoteKptfileError) Unwrap ¶
func (e *RemoteKptfileError) Unwrap() error
type SubpackageMatcher ¶
type SubpackageMatcher string
SubpackageMatcher is type for specifying the types of subpackages which should be included when listing them.
const ( // All means all types of subpackages will be returned. All SubpackageMatcher = "ALL" // Local means only local subpackages will be returned. Local SubpackageMatcher = "LOCAL" // remote means only remote subpackages will be returned. Remote SubpackageMatcher = "REMOTE" // None means that no subpackages will be returned. None SubpackageMatcher = "NONE" )