Refactor buildkit init in daemon startup#48950
Conversation
b338145 to
33813ea
Compare
|
After some futher investigation, this buildkir PR seems to be resolving the issue: moby/buildkit#5550 |
33813ea to
1608d2f
Compare
|
I've updated this to just remove the timeout minor refactor. |
|
Failure looks consistent; not sure how it relates directly though |
| c, err := createAndStartCluster(cli, d) | ||
| if err != nil { | ||
| log.G(ctx).Fatalf("Error starting cluster component: %v", err) | ||
| return errors.Wrap(err, "error starting cluster component") |
There was a problem hiding this comment.
Wondering if we want to both log and return this one (not sure if the error shows up in logs?)
edit: answering myself; it looks like we do this already for som other errors further up. Looking it such errors were logged, I noticed that for windows we explicitly send it to the logs (but only when running as service), but for unix we don't;
on Windows;
moby/cmd/dockerd/docker_windows.go
Lines 28 to 33 in 2f6953f
on Linux;
moby/cmd/dockerd/docker_unix.go
Lines 12 to 14 in 2f6953f
There was a problem hiding this comment.
huh, I don't remember changing this line of code.
Maybe I saw it was return fmt.Errorf(...) with a %v and not properly wrapped...
| // Get a the current daemon config, because the daemon sets up config | ||
| // during initialization. We cannot user the cli.Config for that reason, | ||
| // as that only holds the config that was set by the user. | ||
| // | ||
| // FIXME(thaJeztah): better separate runtime and config data? | ||
| daemonCfg := d.Config() | ||
| routerOpts, err := newRouterOptions(routerCtx, &daemonCfg, d, c) | ||
|
|
||
| bb, sm, err := initBuildkit(ctx, &daemonCfg, d) |
There was a problem hiding this comment.
This is the only place where daemonCfg is used, so perhaps we should move the code (and comment?) above inside initBuildkit as it's already having access to the daemon, and uses it for various other purposes.
The code comment was added in 00c9785 to prevent buildkit being initialised with the wrong "host-gateway-ip";
| bb, sm, err := initBuildkit(ctx, &daemonCfg, d) | ||
| if err != nil { | ||
| return err | ||
| return fmt.Errorf("error initializing buildkit") |
There was a problem hiding this comment.
Looks like we're discarding the original error here
| bb, err := buildbackend.NewBackend(d.ImageService(), manager, bk, d.EventsService) | ||
| if err != nil { |
There was a problem hiding this comment.
On a fun note; it looks like NewBackend never return an error; not for this PR, but wondering if we should even get rid of the constructor (or remove the error return)
moby/api/server/backend/build/backend.go
Lines 40 to 43 in 2f6953f
| return routerOptions{}, errors.Wrap(err, "failed to create buildmanager") | ||
| return nil, nil, errors.Wrap(err, "failed to create buildmanager") |
There was a problem hiding this comment.
As we're updating, perhaps we should change this to failed to create build backend, but see above; looks like this never returns an error.
| cluster *cluster.Cluster | ||
| } | ||
| func initBuildkit(ctx context.Context, config *config.Config, d *daemon.Daemon) (*buildbackend.Backend, *session.Manager, error) { | ||
| log.G(ctx).Info("Initializing buildkit") |
There was a problem hiding this comment.
Nit/question: do we use (lowercase) buildkit or BuildKit in our logs?
| return routerOptions{}, errors.Wrap(err, "failed to create buildmanager") | ||
| return nil, nil, errors.Wrap(err, "failed to create buildmanager") | ||
| } | ||
| return bb, sm, nil |
There was a problem hiding this comment.
Would it make sense to log here that we finished initialising BuildKit? To make it the counterpart of;
log.G(ctx).Info("Completed initializing BuildKit")or
log.G(ctx).Info("Finished initializing BuildKit")|
I'll move the first commit to a separate PR so that we can test that in isolation and backport it. edit: created PR: |
e29382f to
b9ea8a1
Compare
|
This should be good to go now. |
thaJeztah
left a comment
There was a problem hiding this comment.
DOH! I started a review, and have a branch with some of the changes (mostly to look wha they'd look like); I'm AFK for some hours but can push those later for discussion
| ro.buildBackend = bb | ||
| ro.buildkit = bk | ||
| ro.sessionManager = sm |
There was a problem hiding this comment.
Wonder what it would look like if we had a separate type for the builder options so that we could return it instead of manipulating the routerOptions 🤔
| Rootless: daemon.Rootless(config), | ||
| Rootless: daemon.Rootless(&config), |
There was a problem hiding this comment.
note to self; perhaps daemon.Rootless would make more sense to be part of the config package. It's just to abstract that config.Rootless is only defined on Linux (not windows)
| Rootless: daemon.Rootless(&config), | ||
| IdentityMapping: d.IdentityMapping(), | ||
| DNSConfig: config.DNSConfig, | ||
| ApparmorProfile: daemon.DefaultApparmorProfile(), |
There was a problem hiding this comment.
note to self: maybe same for daemon.DefaultApparmorProfile 🤔
2c71f31 to
b7591f8
Compare
1. Move the "Daemon has completed initialization" log to where it has actually completed initialization. 2. Move buildkkt init to its own function. Signed-off-by: Brian Goff <[email protected]> Signed-off-by: Sebastiaan van Stijn <[email protected]>
b7591f8 to
4c7eb3e
Compare
|
did a quick rebase after #49078 was merged (minor conflict) |
|
I updated the title, description and labels I updated #49040 as well to squash it into 2 commits, and moved it out of draft; if others prefer that PR, we can merge that one instead. |
Refactor buildkit init in daemon startup
actually completed initialization.