util

package
v1.22.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 42 Imported by: 22

Documentation

Index

Constants

View Source
const (
	DoNotChangeUID = -1
	DoNotChangeGID = -1
)

Variables

View Source
var ErrNotSymLink = fmt.Errorf("not a symlink")

Functions

func AddToDefaultIgnoreList added in v1.7.0

func AddToDefaultIgnoreList(entry IgnoreListEntry)

func AddToIgnoreList added in v1.1.0

func AddToIgnoreList(entry IgnoreListEntry)

func AddVolumePathToIgnoreList added in v0.23.0

func AddVolumePathToIgnoreList(path string)

AddVolumePath adds the given path to the volume ignorelist.

func CacheHasher added in v0.4.0

func CacheHasher() func(string) (string, error)

CacheHasher takes into account everything the regular hasher does except for mtime

func CheckCleanedPathAgainstIgnoreList added in v1.14.0

func CheckCleanedPathAgainstIgnoreList(path string) bool

func CheckCleanedPathAgainstProvidedIgnoreList added in v1.14.0

func CheckCleanedPathAgainstProvidedIgnoreList(path string, wl []IgnoreListEntry) bool

func CheckIgnoreList added in v0.23.0

func CheckIgnoreList(path string) bool

func ContainsWildcards

func ContainsWildcards(paths []string) bool

ContainsWildcards returns true if any entry in paths contains wildcards

func CopyDir

func CopyDir(src, dest string, context FileContext, uid, gid int64) ([]string, error)

CopyDir copies the file or directory at src to dest It returns a list of files it copied over

func CopyFile

func CopyFile(src, dest string, context FileContext, uid, gid int64) (bool, error)

CopyFile copies the file at src to dest

func CopyFileOrSymlink(src string, destDir string, root string) error

For cross stage dependencies kaniko must persist the referenced path so that it can be used in the dependent stage. For symlinks we copy the target path because copying the symlink would result in a dead link

func CopyOwnership added in v1.8.0

func CopyOwnership(src string, destDir string, root string) error

CopyOwnership copies the file or directory ownership recursively at src to dest

func CopySymlink(src, dest string, context FileContext) (bool, error)

CopySymlink copies the symlink at src to dest.

func CreateFile

func CreateFile(path string, reader io.Reader, perm os.FileMode, uid uint32, gid uint32) error

CreateFile creates a file at path and copies over contents from the reader

func CreateTarballOfDirectory added in v1.9.0

func CreateTarballOfDirectory(pathToDir string, f io.Writer) error

func CreateTargetTarfile added in v0.14.0

func CreateTargetTarfile(tarpath string) (*os.File, error)

CreateTargetTarfile creates target tar file for downloading the context file. Make directory if directory does not exist

func DeleteFilesystem

func DeleteFilesystem() error

DeleteFilesystem deletes the extracted image file system

func DestinationFilepath

func DestinationFilepath(src, dest, cwd string) (string, error)

DestinationFilepath returns the destination filepath from the build context to the image filesystem If source is a file:

If dest is a dir, copy it to /dest/relpath
If dest is a file, copy directly to dest

If source is a dir:

Assume dest is also a dir, and copy to dest/

If dest is not an absolute filepath, add /cwd to the beginning

func DetectFilesystemIgnoreList added in v0.23.0

func DetectFilesystemIgnoreList(path string) error

Get ignorelist from roots of mounted files Each line of /proc/self/mountinfo is in the form: 36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue (1)(2)(3) (4) (5) (6) (7) (8) (9) (10) (11) Where (5) is the mount point relative to the process's root From: https://www.kernel.org/doc/Documentation/filesystems/proc.txt

func DetermineTargetFileOwnership added in v0.18.0

func DetermineTargetFileOwnership(fi os.FileInfo, uid, gid int64) (int64, int64)

DetermineTargetFileOwnership returns the user provided uid/gid combination. If they are set to -1, the uid/gid from the original file is used.

func DockerConfLocation added in v1.8.0

func DockerConfLocation() string

DockerConfLocation returns the file system location of the Docker configuration file under the directory set in the DOCKER_CONFIG environment variable. If that variable is not set, it returns the OS-equivalent of "/kaniko/.docker/config.json".

func DownloadFileToDest

func DownloadFileToDest(rawurl, dest string, uid, gid int64) error

DownloadFileToDest downloads the file at rawurl to the given dest for the ADD command From add command docs:

  1. If <src> is a remote file URL: - destination will have permissions of 0600 - If remote file has HTTP Last-Modified header, we set the mtime of the file to that timestamp
func EvalSymLink(path string) (string, error)

func ExtractFile added in v0.15.0

func ExtractFile(dest string, hdr *tar.Header, cleanedName string, tr io.Reader) error

func FilepathExists

func FilepathExists(path string) bool

FilepathExists returns true if the path exists

func GetFSFromImage

func GetFSFromImage(root string, img v1.Image, extract ExtractFunction) ([]string, error)

GetFSFromImage extracts the layers of img to root It returns a list of all files extracted

func GetFSFromLayers added in v0.17.0

func GetFSFromLayers(root string, layers []v1.Layer, opts ...FSOpt) ([]string, error)

func GetFSInfoMap added in v1.0.0

func GetFSInfoMap(dir string, existing map[string]os.FileInfo) (map[string]os.FileInfo, []string)

GetFSInfoMap given a directory gets a map of FileInfo for all files

func GetInputFrom added in v0.20.0

func GetInputFrom(r io.Reader) ([]byte, error)

GetInputFrom returns Reader content

func GetSymLink(path string) (string, error)

func GetUserGroup added in v0.19.0

func GetUserGroup(chownStr string, env []string) (int64, int64, error)

func HasFilepathPrefix

func HasFilepathPrefix(path, prefix string, prefixMatchOnly bool) bool

HasFilepathPrefix checks if the given file path begins with prefix

func Hasher

func Hasher() func(string) (string, error)

Hasher returns a hash function, used in snapshotting to determine if a file has changed

func InitIgnoreList added in v1.7.0

func InitIgnoreList() error

InitIgnoreList will initialize the ignore list using: - defaultIgnoreList - mounted paths via DetectFilesystemIgnoreList()

func IsDestDir

func IsDestDir(path string) bool

func IsFileLocalTarArchive

func IsFileLocalTarArchive(src string) bool

IsFileLocalTarArchive returns true if the file is a local tar archive

func IsInIgnoreList added in v0.23.0

func IsInIgnoreList(path string) bool

func IsInProvidedIgnoreList added in v0.23.0

func IsInProvidedIgnoreList(path string, wl []IgnoreListEntry) bool

func IsSrcRemoteFileURL

func IsSrcRemoteFileURL(rawurl string) bool

func IsSrcsValid

func IsSrcsValid(srcsAndDest instructions.SourcesAndDest, resolvedSources []string, fileContext FileContext) error
func IsSymlink(fi os.FileInfo) bool

Returns true if a file is a symlink

func Lgetxattr added in v1.9.0

func Lgetxattr(path string, attr string) ([]byte, error)

func LookupUser added in v1.9.0

func LookupUser(userStr string) (*user.User, error)

LookupUser will try to lookup the userStr inside the passwd file. If the user does not exists, the function will fallback to parsing the userStr as an uid.

func MakeTransport added in v0.23.0

func MakeTransport(opts config.RegistryOptions, registryName string) (http.RoundTripper, error)

func MkdirAllWithPermissions added in v1.9.2

func MkdirAllWithPermissions(path string, mode os.FileMode, uid, gid int64) error

func MtimeHasher

func MtimeHasher() func(string) (string, error)

MtimeHasher returns a hash function, which only looks at mtime to determine if a file has changed. Note that the mtime can lag, so it's possible that a file will have changed but the mtime may look the same.

func ParentDirectories

func ParentDirectories(path string) []string

ParentDirectories returns a list of paths to all parent directories Ex. /some/temp/dir -> [/, /some, /some/temp, /some/temp/dir]

func ParentDirectoriesWithoutLeadingSlash added in v0.12.0

func ParentDirectoriesWithoutLeadingSlash(path string) []string

ParentDirectoriesWithoutLeadingSlash returns a list of paths to all parent directories all subdirectories do not contain a leading / Ex. /some/temp/dir -> [/, some, some/temp, some/temp/dir]

func RedoHasher added in v0.24.0

func RedoHasher() func(string) (string, error)

RedoHasher returns a hash function, which looks at mtime, size, filemode, owner uid and gid Note that the mtime can lag, so it's possible that a file will have changed but the mtime may look the same.

func RelativeFiles

func RelativeFiles(fp string, root string) ([]string, error)

RelativeFiles returns a list of all files at the filepath relative to root

func ResolveEnvAndWildcards added in v0.10.0

func ResolveEnvAndWildcards(sd instructions.SourcesAndDest, fileContext FileContext, envs []string) ([]string, string, error)

func ResolveEnvironmentReplacement

func ResolveEnvironmentReplacement(value string, envs []string, isFilepath bool) (string, error)

ResolveEnvironmentReplacement resolves replacing env variables in some text from envs It takes in a string representation of the command, the value to be resolved, and a list of envs (config.Env) Ex: value = $foo/newdir, envs = [foo=/foodir], then this should return /foodir/newdir The dockerfile/shell package handles processing env values It handles escape characters and supports expansion from the config.Env array Shlex handles some of the following use cases (these and more are tested in integration tests) ""a'b'c"" -> "a'b'c" "Rex\ The\ Dog \" -> "Rex The Dog" "a\"b" -> "a"b"

func ResolveEnvironmentReplacementList

func ResolveEnvironmentReplacementList(values, envs []string, isFilepath bool) ([]string, error)

ResolveEnvironmentReplacementList resolves a list of values by calling resolveEnvironmentReplacement

func ResolveSources

func ResolveSources(srcs []string, root string) ([]string, error)

ResolveSources resolves the given sources if the sources contains wildcards It returns a list of resolved sources

func Retry added in v1.5.1

func Retry(operation retryFunc, retryCount int, initialDelayMilliseconds int) error

Retry retries an operation

func RetryWithResult added in v1.19.0

func RetryWithResult[T any](operation func() (T, error), retryCount int, initialDelayMilliseconds int) (result T, err error)

Retry retries an operation with a return value

func SHA256 added in v0.4.0

func SHA256(r io.Reader) (string, error)

SHA256 returns the shasum of the contents of r

func SyscallCredentials added in v0.20.0

func SyscallCredentials(userStr string) (*syscall.Credential, error)

func URLDestinationFilepath

func URLDestinationFilepath(rawurl, dest, cwd string, envs []string) (string, error)

URLDestinationFilepath gives the destination a file from a remote URL should be saved to

func UnTar added in v1.8.0

func UnTar(r io.Reader, dest string) ([]string, error)

UnTar returns a list of files that have been extracted from the tar archive at r to the path at dest

func UnpackCompressedTar

func UnpackCompressedTar(path, dir string) error

UnpackCompressedTar unpacks the compressed tar at path to dir

func UnpackLocalTarArchive

func UnpackLocalTarArchive(path, dest string) ([]string, error)

UnpackLocalTarArchive unpacks the tar archive at path to the directory dest Returns the files extracted from the tar archive

func UpdateConfigEnv

func UpdateConfigEnv(envVars []instructions.KeyValuePair, config *v1.Config, replacementEnvs []string) error

func ValidAzureBlobStorageHost added in v0.14.0

func ValidAzureBlobStorageHost(context string) bool

Validate if the host url provided is with correct suffix for AzureCloud, AzureChinaCloud, AzureGermanCloud and AzureUSGovernment RegEX for supported suffix defined in constants.AzureBlobStorageHostRegEx

func Volumes added in v0.9.0

func Volumes() []string

func WalkFS added in v0.24.0

func WalkFS(
	dir string,
	existingPaths map[string]struct{},
	changeFunc func(string) (bool, error),
) ([]string, map[string]struct{})

WalkFS given a directory dir and list of existing files existingPaths, returns a list of changed files determined by `changeFunc` and a list of deleted files. Input existingPaths is changed inside this function and returned as deleted files map. It timesout after 90 mins which can be configured via setting an environment variable SNAPSHOT_TIMEOUT in the kaniko pod definition.

Types

type CertPool added in v0.23.0

type CertPool interface {
	// contains filtered or unexported methods
}

type ExtractFunction added in v0.15.0

type ExtractFunction func(string, *tar.Header, string, io.Reader) error

type FSConfig added in v0.17.0

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

type FSOpt added in v0.17.0

type FSOpt func(*FSConfig)

func ExtractFunc added in v0.17.0

func ExtractFunc(extractFunc ExtractFunction) FSOpt

func IncludeWhiteout added in v0.17.0

func IncludeWhiteout() FSOpt

type FileContext added in v1.3.0

type FileContext struct {
	Root          string
	ExcludedFiles []string
}

func NewFileContextFromDockerfile added in v1.3.0

func NewFileContextFromDockerfile(dockerfilePath, buildcontext string) (FileContext, error)

func (FileContext) ExcludesFile added in v1.3.0

func (c FileContext) ExcludesFile(path string) bool

ExcludesFile returns true if the file context specified this file should be ignored. Usually this is specified via .dockerignore

type IgnoreListEntry added in v0.23.0

type IgnoreListEntry struct {
	Path            string
	PrefixMatchOnly bool
}

func IgnoreList added in v0.23.0

func IgnoreList() []IgnoreListEntry

type KeyPairLoader added in v1.10.0

type KeyPairLoader interface {
	// contains filtered or unexported methods
}

type Tar added in v0.4.0

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

Tar knows how to write files to a tar file.

func NewTar added in v0.4.0

func NewTar(f io.Writer) Tar

NewTar will create an instance of Tar that can write files to the writer at f.

func (*Tar) AddFileToTar added in v0.4.0

func (t *Tar) AddFileToTar(p string) error

AddFileToTar adds the file at path p to the tar

func (*Tar) Close added in v0.4.0

func (t *Tar) Close()

Close will close any open streams used by Tar.

func (*Tar) Whiteout added in v0.4.0

func (t *Tar) Whiteout(p string) error

type X509CertPool added in v0.23.0

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

type X509KeyPairLoader added in v1.10.0

type X509KeyPairLoader struct {
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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