Skip to content

Commit

Permalink
driver: refactor GetDriver func to take init config
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Jul 16, 2024
1 parent 3005743 commit 4304d38
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
15 changes: 13 additions & 2 deletions builder/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,19 @@ func (b *Builder) LoadNodes(ctx context.Context, opts ...LoadNodesOption) (_ []N
kcc = kccInCluster
}
}

d, err := driver.GetDriver(ctx, driver.BuilderName(n.Name), factory, n.Endpoint, dockerapi, imageopt.Auth, kcc, n.BuildkitdFlags, n.Files, n.DriverOpts, n.Platforms, b.opts.contextPathHash, lno.dialMeta)
d, err := driver.GetDriver(ctx, factory, driver.InitConfig{
Name: driver.BuilderName(n.Name),
EndpointAddr: n.Endpoint,
DockerAPI: dockerapi,
KubeClientConfig: kcc,
BuildkitdFlags: n.BuildkitdFlags,
Files: n.Files,
DriverOpts: n.DriverOpts,
Auth: imageopt.Auth,
Platforms: n.Platforms,
ContextPathHash: b.opts.contextPathHash,
DialMeta: lno.dialMeta,
})
if err != nil {
node.Err = err
return nil
Expand Down
21 changes: 4 additions & 17 deletions driver/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (k KubeClientConfigInCluster) Namespace() (string, bool, error) {
}

type InitConfig struct {
// This object needs updates to be generic for different drivers
// TODO: This object needs updates to be generic for different drivers
Name string
EndpointAddr string
DockerAPI dockerclient.APIClient
Expand Down Expand Up @@ -104,28 +104,15 @@ func GetFactory(name string, instanceRequired bool) (Factory, error) {
return nil, errors.Errorf("failed to find driver %q", name)
}

func GetDriver(ctx context.Context, name string, f Factory, endpointAddr string, api dockerclient.APIClient, auth Auth, kcc KubeClientConfig, buildkitdFlags []string, files map[string][]byte, do map[string]string, platforms []specs.Platform, contextPathHash string, dialMeta map[string][]string) (*DriverHandle, error) {
ic := InitConfig{
EndpointAddr: endpointAddr,
DockerAPI: api,
KubeClientConfig: kcc,
Name: name,
BuildkitdFlags: buildkitdFlags,
DriverOpts: do,
Auth: auth,
Platforms: platforms,
ContextPathHash: contextPathHash,
DialMeta: dialMeta,
Files: files,
}
func GetDriver(ctx context.Context, f Factory, cfg InitConfig) (*DriverHandle, error) {
if f == nil {
var err error
f, err = GetDefaultFactory(ctx, endpointAddr, api, false, dialMeta)
f, err = GetDefaultFactory(ctx, cfg.EndpointAddr, cfg.DockerAPI, false, cfg.DialMeta)
if err != nil {
return nil, err
}
}
d, err := f.New(ctx, ic)
d, err := f.New(ctx, cfg)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 4304d38

Please sign in to comment.