Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for delayed pre-pull #822

Merged
merged 4 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/commands/worker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Config struct {

ResourceModifiers []*resourcemodifier.Modifier `yaml:"resource-modifiers"`

TartPrePull []string `yaml:"tart-pre-pull"`
TartPrePull *worker.TartPrePull `yaml:"tart-pre-pull"`
}

type ConfigLog struct {
Expand Down Expand Up @@ -227,7 +227,7 @@ func buildWorker(output io.Writer) (*worker.Worker, error) {
))
}

if len(config.TartPrePull) != 0 {
if config.TartPrePull != nil {
opts = append(opts, worker.WithTartPrePull(config.TartPrePull))
}

Expand Down
1 change: 1 addition & 0 deletions internal/executor/instance/abstract/abstract.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type WarmableInstance interface {
ctx context.Context,
ident string,
env map[string]string,
lazyPull bool,
warmupScript string,
warmupTimeout time.Duration,
logger *echelon.Logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ func (tart *Tart) Warmup(
ctx context.Context,
ident string,
additionalEnvironment map[string]string,
lazyPull bool,
warmupScript string,
warmupTimeout time.Duration,
logger *echelon.Logger,
) error {
err := tart.bootVM(ctx, ident, additionalEnvironment, "", false, logger)
err := tart.bootVM(ctx, ident, additionalEnvironment, "", lazyPull, logger)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ func (vetu *Vetu) Warmup(
ctx context.Context,
ident string,
env map[string]string,
lazyPull bool,
_ string,
_ time.Duration,
logger *echelon.Logger,
) error {
return vetu.bootVM(ctx, ident, env, false, logger)
return vetu.bootVM(ctx, ident, env, lazyPull, logger)
}

func (vetu *Vetu) bootVM(
Expand Down
2 changes: 1 addition & 1 deletion internal/worker/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func WithResourceModifiersManager(resourceModifiersManager *resourcemodifier.Man
}
}

func WithTartPrePull(tartPrePull []string) Option {
func WithTartPrePull(tartPrePull *TartPrePull) Option {
return func(e *Worker) {
e.tartPrePull = tartPrePull
}
Expand Down
17 changes: 17 additions & 0 deletions internal/worker/prepull.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package worker

import "time"

type TartPrePull struct {
Images []string `yaml:"images"`
CheckInterval time.Duration `yaml:"check-interval"`
LastCheck time.Time
}

func (pull TartPrePull) NeedsPrePull() bool {
if pull.CheckInterval == 0 {
return true
}

return time.Now().After(pull.LastCheck.Add(pull.CheckInterval))
}
38 changes: 27 additions & 11 deletions internal/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type Worker struct {
standbyInstance abstract.Instance
standbyInstanceStartedAt time.Time

tartPrePull []string
tartPrePull *TartPrePull
}

func New(opts ...Option) (*Worker, error) {
Expand Down Expand Up @@ -266,15 +266,6 @@ func (worker *Worker) tryCreateStandby(ctx context.Context) {
return
}

// Pre-pull the configured Tart VM images first
for _, image := range worker.tartPrePull {
worker.logger.Infof("pre-pulling Tart VM image %q...", image)

if err := tart.PrePull(ctx, image, worker.echelonLogger); err != nil {
worker.logger.Errorf("failed to pre-pull Tart VM image %q: %v", image, err)
}
}

worker.logger.Debugf("creating a new standby instance with isolation %s", worker.standbyConfig.Isolation)

standbyInstance, err := persistentworker.New(worker.standbyConfig.Isolation, worker.security,
Expand All @@ -285,9 +276,34 @@ func (worker *Worker) tryCreateStandby(ctx context.Context) {
return
}

lazyPull := false

if worker.tartPrePull != nil {
// Pre-pull the configured Tart VM images first
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say we have configured ghcr.io/cirruslabs/macos-runner:sonoma for the pre-pull.

A new version of this image gets released, and we skip this code block because we've already performed a check recently, but before the image was available.

As a result, lazyPull won't be set to true, and Warmup() below will pull the new image. This will likely happen on all the workers, which corresponds to the current behavior 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad! You are absolutely correct. What about this logic in 84f7462?

for _, image := range worker.tartPrePull.Images {
for _, attr := range standbyInstance.Attributes() {
if attr.Key == "image" && attr.Value.AsString() == image {
lazyPull = true
}
}

if !worker.tartPrePull.NeedsPrePull() {
continue
}

worker.logger.Infof("pre-pulling Tart VM image %q...", image)

if err := tart.PrePull(ctx, image, worker.echelonLogger); err != nil {
worker.logger.Errorf("failed to pre-pull Tart VM image %q: %v", image, err)
continue
}
}
worker.tartPrePull.LastCheck = time.Now()
}

worker.logger.Debugf("warming-up the standby instance")

if err := standbyInstance.(abstract.WarmableInstance).Warmup(ctx, "standby", nil,
if err := standbyInstance.(abstract.WarmableInstance).Warmup(ctx, "standby", nil, lazyPull,
worker.standbyConfig.Warmup.Script, worker.standbyConfig.Warmup.Timeout, worker.echelonLogger); err != nil {
worker.logger.Errorf("failed to warm-up a standby instance: %v", err)

Expand Down
2 changes: 1 addition & 1 deletion pkg/api/cirrus_ci_service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.