Merge pull request #1273 from jedevc/fix-1269

create: improve interface when attempting to create docker driver
pull/1280/head v0.9.0
Tõnis Tiigi 2 years ago committed by GitHub
commit 611329fc7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -135,8 +135,8 @@ func runCreate(dockerCli command.Cli, in createOptions, args []string) error {
} }
} }
if driver.GetFactory(driverName, true) == nil { if _, err := driver.GetFactory(driverName, true); err != nil {
return errors.Errorf("failed to find driver %q", driverName) return err
} }
ngOriginal := ng ngOriginal := ng
@ -282,7 +282,7 @@ func createCmd(dockerCli command.Cli) *cobra.Command {
var options createOptions var options createOptions
var drivers bytes.Buffer var drivers bytes.Buffer
for _, d := range driver.GetFactories() { for _, d := range driver.GetFactories(true) {
if len(drivers.String()) > 0 { if len(drivers.String()) > 0 {
drivers.WriteString(", ") drivers.WriteString(", ")
} }

@ -60,8 +60,9 @@ func driversForNodeGroup(ctx context.Context, dockerCli command.Cli, ng *store.N
var f driver.Factory var f driver.Factory
if ng.Driver != "" { if ng.Driver != "" {
f = driver.GetFactory(ng.Driver, true) var err error
if f == nil { f, err = driver.GetFactory(ng.Driver, true)
if err != nil {
return nil, errors.Errorf("failed to find driver %q", f) return nil, errors.Errorf("failed to find driver %q", f)
} }
} else { } else {

@ -15,7 +15,7 @@ Create a new builder instance
| `--bootstrap` | | | Boot builder after creation | | `--bootstrap` | | | Boot builder after creation |
| [`--buildkitd-flags`](#buildkitd-flags) | `string` | | Flags for buildkitd daemon | | [`--buildkitd-flags`](#buildkitd-flags) | `string` | | Flags for buildkitd daemon |
| [`--config`](#config) | `string` | | BuildKit config file | | [`--config`](#config) | `string` | | BuildKit config file |
| [`--driver`](#driver) | `string` | | Driver to use (available: `docker`, `docker-container`, `kubernetes`, `remote`) | | [`--driver`](#driver) | `string` | | Driver to use (available: `docker-container`, `kubernetes`, `remote`) |
| [`--driver-opt`](#driver-opt) | `stringArray` | | Options for the driver | | [`--driver-opt`](#driver-opt) | `stringArray` | | Options for the driver |
| [`--leave`](#leave) | | | Remove a node from builder instead of changing it | | [`--leave`](#leave) | | | Remove a node from builder instead of changing it |
| [`--name`](#name) | `string` | | Builder instance name | | [`--name`](#name) | `string` | | Builder instance name |

@ -92,16 +92,16 @@ func GetDefaultFactory(ctx context.Context, ep string, c dockerclient.APIClient,
return dd[0].f, nil return dd[0].f, nil
} }
func GetFactory(name string, instanceRequired bool) Factory { func GetFactory(name string, instanceRequired bool) (Factory, error) {
for _, f := range drivers { for _, f := range drivers {
if instanceRequired && !f.AllowsInstances() {
continue
}
if f.Name() == name { if f.Name() == name {
return f if instanceRequired && !f.AllowsInstances() {
return nil, errors.Errorf("additional instances of driver %q cannot be created", name)
}
return f, nil
} }
} }
return nil 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, flags []string, files map[string][]byte, do map[string]string, platforms []specs.Platform, contextPathHash string) (Driver, error) { func GetDriver(ctx context.Context, name string, f Factory, endpointAddr string, api dockerclient.APIClient, auth Auth, kcc KubeClientConfig, flags []string, files map[string][]byte, do map[string]string, platforms []specs.Platform, contextPathHash string) (Driver, error) {
@ -131,9 +131,12 @@ func GetDriver(ctx context.Context, name string, f Factory, endpointAddr string,
return &cachedDriver{Driver: d}, nil return &cachedDriver{Driver: d}, nil
} }
func GetFactories() []Factory { func GetFactories(instanceRequired bool) []Factory {
ds := make([]Factory, 0, len(drivers)) ds := make([]Factory, 0, len(drivers))
for _, d := range drivers { for _, d := range drivers {
if instanceRequired && !d.AllowsInstances() {
continue
}
ds = append(ds, d) ds = append(ds, d)
} }
sort.Slice(ds, func(i, j int) bool { sort.Slice(ds, func(i, j int) bool {

Loading…
Cancel
Save