Documentation
¶
Overview ¶
Package executor provides mock implementations and test utilities for testing the Kaniko executor functionality
Index ¶
- Constants
- Variables
- func CalculateDependencies(stages []config.KanikoStage, opts *config.KanikoOptions, ...) (map[int][]string, error)
- func CheckPushPermissions(opts *config.KanikoOptions) error
- func DoBuild(opts *config.KanikoOptions) (v1.Image, error)
- func DoMultiPlatformBuild(opts *config.KanikoOptions) (v1.ImageIndex, error)
- func DoPush(image v1.Image, opts *config.KanikoOptions) error
- func InitMultiPlatformBuild()
- func ResolveCrossStageInstructions(stages []config.KanikoStage) map[string]string
- type CommandNode
- type CommandType
- type CompositeCache
- type DependencyGraph
- func (g *DependencyGraph) GetDependencies(index int) []int
- func (g *DependencyGraph) GetDependents(index int) []int
- func (g *DependencyGraph) GetExecutionOrder() []int
- func (g *DependencyGraph) GetIndependentCommands(executed map[int]bool) []int
- func (g *DependencyGraph) GetNode(index int) *CommandNode
- func (g *DependencyGraph) String() string
- type ImmutableRef
- type MockCachedDockerCommand
- func (m MockCachedDockerCommand) CacheCommand(_ v1.Image) commands.DockerCommand
- func (m MockCachedDockerCommand) ExecuteCommand(_ *v1.Config, _ *dockerfile.BuildArgs) error
- func (m MockCachedDockerCommand) FilesToSnapshot() []string
- func (m MockCachedDockerCommand) FilesUsedFromContext(_ *v1.Config, _ *dockerfile.BuildArgs) ([]string, error)
- func (m MockCachedDockerCommand) IsArgsEnvsRequiredInCache() bool
- func (m MockCachedDockerCommand) MetadataOnly() bool
- func (m MockCachedDockerCommand) ProvidesFilesToSnapshot() bool
- func (m MockCachedDockerCommand) RequiresUnpackedFS() bool
- func (m MockCachedDockerCommand) ShouldCacheOutput() bool
- func (m MockCachedDockerCommand) ShouldDetectDeletedFiles() bool
- func (m MockCachedDockerCommand) String() string
- type MockDockerCommand
- func (m MockDockerCommand) CacheCommand(_ v1.Image) commands.DockerCommand
- func (m MockDockerCommand) ExecuteCommand(_ *v1.Config, _ *dockerfile.BuildArgs) error
- func (m MockDockerCommand) FilesToSnapshot() []string
- func (m MockDockerCommand) FilesUsedFromContext(_ *v1.Config, _ *dockerfile.BuildArgs) ([]string, error)
- func (m MockDockerCommand) IsArgsEnvsRequiredInCache() bool
- func (m MockDockerCommand) MetadataOnly() bool
- func (m MockDockerCommand) ProvidesFilesToSnapshot() bool
- func (m MockDockerCommand) RequiresUnpackedFS() bool
- func (m MockDockerCommand) ShouldCacheOutput() bool
- func (m MockDockerCommand) ShouldDetectDeletedFiles() bool
- func (m MockDockerCommand) String() string
- type MutableRef
- type SimpleExecutor
- type StageSnapshot
Constants ¶
const ( DefaultDirPerm = 0o750 // DefaultRetryMaxDelay is the default maximum delay for retry operations DefaultRetryMaxDelay = 30 * time.Second // DefaultRetryBackoff is the default exponential backoff multiplier DefaultRetryBackoff = 2.0 )
Constants for magic number replacements
const ( // Snapshot mode constants SnapshotModeTime = "time" // Compression constants CompressionZstd = "zstd" // Performance optimization constants // NoCacheParallelMultiplier removed - parallel execution is no longer supported MemoryLimitGB = 2 MemoryLimitBytes = 2 * 1024 * 1024 * 1024 // 2GB CommandTimeoutMinutes = 30 MaxFileSizeMB = 500 MaxFileSizeBytes = 500 * 1024 * 1024 // 500MB MaxTotalFileSizeGB = 10 MaxTotalFileSizeBytes = 10 * 1024 * 1024 * 1024 // 10GB // Network optimization constants MaxIdleConns = 200 MaxIdleConnsPerHost = 20 MaxConnsPerHost = 100 IdleConnTimeoutMin = 5 MaxConcurrency = 15 RequestTimeoutMin = 5 RetryAttempts = 5 RetryDelaySec = 2 DNSCacheTimeoutMin = 10 ManifestCacheTimeoutMin = 30 )
Optimization constants
const ( // UpstreamClientUaKey is the environment variable key for upstream client type // used to set User-Agent header in HTTP requests UpstreamClientUaKey = "UPSTREAM_CLIENT_TYPE" // DummyDestination is a placeholder destination used when no push destinations are specified DummyDestination = "docker.io/unset-repo/unset-image-name" )
Variables ¶
var (
DummyDestinations = []string{DummyDestination}
)
for testing
Functions ¶
func CalculateDependencies ¶
func CalculateDependencies( stages []config.KanikoStage, opts *config.KanikoOptions, stageNameToIdx map[string]string, ) (map[int][]string, error)
CalculateDependencies calculates cross-stage dependencies for multi-stage builds. It analyzes COPY --from commands and other cross-stage references to determine which files need to be preserved between stages.
func CheckPushPermissions ¶
func CheckPushPermissions(opts *config.KanikoOptions) error
CheckPushPermissions checks that the configured credentials can be used to push to every specified destination.
func DoBuild ¶
func DoBuild(opts *config.KanikoOptions) (v1.Image, error)
DoBuild executes building the Dockerfile
func DoMultiPlatformBuild ¶
func DoMultiPlatformBuild(opts *config.KanikoOptions) (v1.ImageIndex, error)
DoMultiPlatformBuild executes multi-platform builds using the specified driver
func DoPush ¶
func DoPush(image v1.Image, opts *config.KanikoOptions) error
DoPush is responsible for pushing image to the destinations specified in opts. A dummy destination would be set when --no-push is set to true and --tar-path is not empty with empty --destinations.
func InitMultiPlatformBuild ¶
func InitMultiPlatformBuild()
InitMultiPlatformBuild initializes the multi-platform build functionality
func ResolveCrossStageInstructions ¶
func ResolveCrossStageInstructions(stages []config.KanikoStage) map[string]string
ResolveCrossStageInstructions iterates over a list of KanikoStage and resolves instructions referring to earlier stages. It returns a mapping of stage name to stage id, f.e - ["first": "0", "second": "1", "target": "2"]
Types ¶
type CommandNode ¶ added in v1.25.4
type CommandNode struct {
Index int
Command commands.DockerCommand
Dependencies []int // Indices of commands this node depends on
Dependents []int // Indices of commands that depend on this node
}
CommandNode represents a command in the dependency graph This provides explicit representation of dependencies between commands
type CommandType ¶
type CommandType interface {
*instructions.CopyCommand | *instructions.EnvCommand | *instructions.ArgCommand
}
CommandType represents the type of command that can be processed for dependencies. This constraint ensures type safety when processing Dockerfile commands.
type CompositeCache ¶
type CompositeCache struct {
// contains filtered or unexported fields
}
CompositeCache is a type that generates a cache key from a series of keys.
func NewCompositeCache ¶
func NewCompositeCache(initial ...string) *CompositeCache
NewCompositeCache returns an initialized composite cache object.
func (*CompositeCache) AddKey ¶
func (s *CompositeCache) AddKey(k ...string)
AddKey adds the specified key to the sequence.
func (*CompositeCache) AddPath ¶
func (s *CompositeCache) AddPath(p string, context util.FileContext) error
AddPath adds a file or directory path to the composite cache key
func (*CompositeCache) Hash ¶
func (s *CompositeCache) Hash() (string, error)
Hash returns the composite key in a string SHA256 format. Results are cached to avoid recomputation for the same key set.
func (*CompositeCache) Key ¶
func (s *CompositeCache) Key() string
Key returns the human readable composite key as a string.
type DependencyGraph ¶ added in v1.25.4
type DependencyGraph struct {
// contains filtered or unexported fields
}
DependencyGraph represents the dependency graph of commands Inspired by BuildKit LLB's explicit dependency representation
func BuildDependencyGraph ¶ added in v1.25.4
func BuildDependencyGraph( cmds []commands.DockerCommand, config *v1.Config, buildArgs *dockerfile.BuildArgs, ) (*DependencyGraph, error)
BuildDependencyGraph builds a dependency graph from a list of commands
func NewDependencyGraph ¶ added in v1.25.4
func NewDependencyGraph() *DependencyGraph
NewDependencyGraph creates a new empty dependency graph
func (*DependencyGraph) GetDependencies ¶ added in v1.25.4
func (g *DependencyGraph) GetDependencies(index int) []int
GetDependencies returns dependencies for a command
func (*DependencyGraph) GetDependents ¶ added in v1.25.4
func (g *DependencyGraph) GetDependents(index int) []int
GetDependents returns commands that depend on this command
func (*DependencyGraph) GetExecutionOrder ¶ added in v1.25.4
func (g *DependencyGraph) GetExecutionOrder() []int
GetExecutionOrder returns the topological execution order
func (*DependencyGraph) GetIndependentCommands ¶ added in v1.25.4
func (g *DependencyGraph) GetIndependentCommands(executed map[int]bool) []int
GetIndependentCommands returns commands that can be executed in parallel (commands with no dependencies or all dependencies already executed)
func (*DependencyGraph) GetNode ¶ added in v1.25.4
func (g *DependencyGraph) GetNode(index int) *CommandNode
GetNode returns a node by index
func (*DependencyGraph) String ¶ added in v1.25.4
func (g *DependencyGraph) String() string
String returns a string representation of the graph
type ImmutableRef ¶ added in v1.25.4
type ImmutableRef struct {
Image v1.Image // Immutable image with this layer
Digest string // Image digest
Layers []v1.Layer // All layers in the image
}
ImmutableRef represents an immutable layer reference (already committed) This provides clear separation between committed and uncommitted layers
type MockCachedDockerCommand ¶
type MockCachedDockerCommand struct {
// contains filtered or unexported fields
}
MockCachedDockerCommand is a mock implementation for cached Docker commands used in executor unit tests
func (MockCachedDockerCommand) CacheCommand ¶
func (m MockCachedDockerCommand) CacheCommand(_ v1.Image) commands.DockerCommand
CacheCommand returns nil since this is already a cached command mock
func (MockCachedDockerCommand) ExecuteCommand ¶
func (m MockCachedDockerCommand) ExecuteCommand(_ *v1.Config, _ *dockerfile.BuildArgs) error
ExecuteCommand is a mock implementation that always returns nil
func (MockCachedDockerCommand) FilesToSnapshot ¶
func (m MockCachedDockerCommand) FilesToSnapshot() []string
FilesToSnapshot returns test file paths for snapshot testing
func (MockCachedDockerCommand) FilesUsedFromContext ¶
func (m MockCachedDockerCommand) FilesUsedFromContext(_ *v1.Config, _ *dockerfile.BuildArgs) ([]string, error)
FilesUsedFromContext returns mock context files for testing
func (MockCachedDockerCommand) IsArgsEnvsRequiredInCache ¶
func (m MockCachedDockerCommand) IsArgsEnvsRequiredInCache() bool
IsArgsEnvsRequiredInCache indicates whether args/envs affect cache key for this mock
func (MockCachedDockerCommand) MetadataOnly ¶
func (m MockCachedDockerCommand) MetadataOnly() bool
MetadataOnly indicates this mock command affects both metadata and filesystem
func (MockCachedDockerCommand) ProvidesFilesToSnapshot ¶
func (m MockCachedDockerCommand) ProvidesFilesToSnapshot() bool
ProvidesFilesToSnapshot indicates that this mock provides files for snapshotting
func (MockCachedDockerCommand) RequiresUnpackedFS ¶
func (m MockCachedDockerCommand) RequiresUnpackedFS() bool
RequiresUnpackedFS indicates this mock doesn't require unpacked filesystem
func (MockCachedDockerCommand) ShouldCacheOutput ¶
func (m MockCachedDockerCommand) ShouldCacheOutput() bool
ShouldCacheOutput indicates this mock command output should not be cached
func (MockCachedDockerCommand) ShouldDetectDeletedFiles ¶
func (m MockCachedDockerCommand) ShouldDetectDeletedFiles() bool
ShouldDetectDeletedFiles indicates this mock doesn't detect deleted files
func (MockCachedDockerCommand) String ¶
func (m MockCachedDockerCommand) String() string
String returns a fixed string representation for testing
type MockDockerCommand ¶
type MockDockerCommand struct {
// contains filtered or unexported fields
}
MockDockerCommand is a mock implementation of DockerCommand interface for use in unit tests of the executor package
func (MockDockerCommand) CacheCommand ¶
func (m MockDockerCommand) CacheCommand(_ v1.Image) commands.DockerCommand
CacheCommand returns the cached command implementation for testing
func (MockDockerCommand) ExecuteCommand ¶
func (m MockDockerCommand) ExecuteCommand(_ *v1.Config, _ *dockerfile.BuildArgs) error
ExecuteCommand is a mock implementation that always returns nil
func (MockDockerCommand) FilesToSnapshot ¶
func (m MockDockerCommand) FilesToSnapshot() []string
FilesToSnapshot returns test file paths for snapshot testing
func (MockDockerCommand) FilesUsedFromContext ¶
func (m MockDockerCommand) FilesUsedFromContext(_ *v1.Config, _ *dockerfile.BuildArgs) ([]string, error)
FilesUsedFromContext returns mock context files for testing
func (MockDockerCommand) IsArgsEnvsRequiredInCache ¶
func (m MockDockerCommand) IsArgsEnvsRequiredInCache() bool
IsArgsEnvsRequiredInCache indicates whether args/envs affect cache key for this mock
func (MockDockerCommand) MetadataOnly ¶
func (m MockDockerCommand) MetadataOnly() bool
MetadataOnly indicates this mock command affects both metadata and filesystem
func (MockDockerCommand) ProvidesFilesToSnapshot ¶
func (m MockDockerCommand) ProvidesFilesToSnapshot() bool
ProvidesFilesToSnapshot indicates that this mock provides files for snapshotting
func (MockDockerCommand) RequiresUnpackedFS ¶
func (m MockDockerCommand) RequiresUnpackedFS() bool
RequiresUnpackedFS indicates this mock doesn't require unpacked filesystem
func (MockDockerCommand) ShouldCacheOutput ¶
func (m MockDockerCommand) ShouldCacheOutput() bool
ShouldCacheOutput indicates this mock command output should be cached
func (MockDockerCommand) ShouldDetectDeletedFiles ¶
func (m MockDockerCommand) ShouldDetectDeletedFiles() bool
ShouldDetectDeletedFiles indicates this mock doesn't detect deleted files
func (MockDockerCommand) String ¶
func (m MockDockerCommand) String() string
String returns the command string representation for testing
type MutableRef ¶ added in v1.25.4
type MutableRef struct {
Parent *ImmutableRef // Parent immutable layer
Changes []string // Changed files in this layer
Snapshot string // Path to tar snapshot
Committed bool // Whether the layer has been committed
CreatedBy string // Command that created this layer
}
MutableRef represents a mutable layer reference (in progress) Used during command execution before committing to immutable
type SimpleExecutor ¶ added in v1.25.4
type SimpleExecutor struct {
// contains filtered or unexported fields
}
SimpleExecutor provides simple sequential command execution This is the default executor for reliability and simplicity Inspired by the original Kaniko approach
func NewSimpleExecutor ¶ added in v1.25.4
func NewSimpleExecutor( cmds []commands.DockerCommand, sb *stageBuilder, opts *config.KanikoOptions, args *dockerfile.BuildArgs, ) *SimpleExecutor
NewSimpleExecutor creates a new simple sequential executor
func (*SimpleExecutor) ExecuteInParallel ¶ added in v1.25.4
func (e *SimpleExecutor) ExecuteInParallel(compositeKey *CompositeCache, initSnapshotTaken bool) error
ExecuteInParallel executes commands in parallel for explicitly independent commands This is an optional optimization that groups commands by dependencies
func (*SimpleExecutor) ExecuteSequentially ¶ added in v1.25.4
func (e *SimpleExecutor) ExecuteSequentially(compositeKey *CompositeCache, initSnapshotTaken bool) error
ExecuteSequentially executes commands sequentially (default behavior) This is simple, reliable, and avoids race conditions
type StageSnapshot ¶ added in v1.25.4
type StageSnapshot struct {
Image v1.Image // Immutable stage image
Digest string // Image digest
Files []string // List of files to save (from CalculateDependencies)
Extracted bool // Whether the image has been extracted
ExtractDir string // Extraction directory (if needed)
// contains filtered or unexported fields
}
StageSnapshot represents an immutable snapshot of a stage image This simplifies cross-stage dependencies by storing the image directly instead of extracting to temporary directories