Skip to content

Commit a445d97

Browse files
authored
Merge pull request #3715 from thaJeztah/context_cleanup_part1a
cli/command: remove unused args from ResolveDefaultContext()
2 parents f1615fa + 049811f commit a445d97

File tree

5 files changed

+18
-39
lines changed

5 files changed

+18
-39
lines changed

cli/command/cli.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...Initialize
216216
cli.contextStore = &ContextStoreWithDefault{
217217
Store: baseContextStore,
218218
Resolver: func() (*DefaultContext, error) {
219-
return ResolveDefaultContext(opts.Common, cli.ConfigFile(), cli.contextStoreConfig, cli.Err())
219+
return ResolveDefaultContext(opts.Common, cli.contextStoreConfig)
220220
},
221221
}
222222
cli.currentContext, err = resolveContextName(opts.Common, cli.configFile, cli.contextStore)
@@ -244,7 +244,7 @@ func NewAPIClientFromFlags(opts *cliflags.CommonOptions, configFile *configfile.
244244
contextStore := &ContextStoreWithDefault{
245245
Store: store.New(config.ContextStoreDir(), storeConfig),
246246
Resolver: func() (*DefaultContext, error) {
247-
return ResolveDefaultContext(opts, configFile, storeConfig, io.Discard)
247+
return ResolveDefaultContext(opts, storeConfig)
248248
},
249249
}
250250
contextName, err := resolveContextName(opts, configFile, contextStore)

cli/command/cli_options.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package command
22

33
import (
4-
"fmt"
54
"io"
65
"os"
76
"strconv"
87

9-
"github.com/docker/cli/cli/context/docker"
10-
"github.com/docker/cli/cli/context/store"
118
"github.com/docker/cli/cli/streams"
129
"github.com/moby/term"
1310
)
@@ -82,19 +79,6 @@ func WithContentTrust(enabled bool) DockerCliOption {
8279
}
8380
}
8481

85-
// WithContextEndpointType add support for an additional typed endpoint in the context store
86-
// Plugins should use this to store additional endpoints configuration in the context store
87-
func WithContextEndpointType(endpointName string, endpointType store.TypeGetter) DockerCliOption {
88-
return func(cli *DockerCli) error {
89-
switch endpointName {
90-
case docker.DockerEndpoint:
91-
return fmt.Errorf("cannot change %q endpoint type", endpointName)
92-
}
93-
cli.contextStoreConfig.SetEndpoint(endpointName, endpointType)
94-
return nil
95-
}
96-
}
97-
9882
// WithDefaultContextStoreConfig configures the cli to use the default context store configuration.
9983
func WithDefaultContextStoreConfig() DockerCliOption {
10084
return func(cli *DockerCli) error {

cli/command/context/create.go

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,24 @@ func createNewContext(o *CreateOptions, cli command.Cli, s store.Writer) error {
9292
if o.Docker == nil {
9393
return errors.New("docker endpoint configuration is required")
9494
}
95-
contextMetadata := newContextMetadata(o)
96-
contextTLSData := store.ContextTLSData{
97-
Endpoints: make(map[string]store.EndpointTLSData),
98-
}
9995
dockerEP, dockerTLS, err := getDockerEndpointMetadataAndTLS(cli, o.Docker)
10096
if err != nil {
10197
return errors.Wrap(err, "unable to create docker endpoint config")
10298
}
103-
contextMetadata.Endpoints[docker.DockerEndpoint] = dockerEP
99+
contextMetadata := store.Metadata{
100+
Endpoints: map[string]interface{}{
101+
docker.DockerEndpoint: dockerEP,
102+
},
103+
Metadata: command.DockerContext{
104+
Description: o.Description,
105+
},
106+
Name: o.Name,
107+
}
108+
contextTLSData := store.ContextTLSData{}
104109
if dockerTLS != nil {
105-
contextTLSData.Endpoints[docker.DockerEndpoint] = *dockerTLS
110+
contextTLSData.Endpoints = map[string]store.EndpointTLSData{
111+
docker.DockerEndpoint: *dockerTLS,
112+
}
106113
}
107114
if err := validateEndpoints(contextMetadata); err != nil {
108115
return err
@@ -161,13 +168,3 @@ func (d *descriptionDecorator) GetMetadata(name string) (store.Metadata, error)
161168
c.Metadata = typedContext
162169
return c, nil
163170
}
164-
165-
func newContextMetadata(o *CreateOptions) store.Metadata {
166-
return store.Metadata{
167-
Endpoints: make(map[string]interface{}),
168-
Metadata: command.DockerContext{
169-
Description: o.Description,
170-
},
171-
Name: o.Name,
172-
}
173-
}

cli/command/defaultcontextstore.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package command
22

33
import (
44
"fmt"
5-
"io"
65

7-
"github.com/docker/cli/cli/config/configfile"
86
"github.com/docker/cli/cli/context/docker"
97
"github.com/docker/cli/cli/context/store"
108
cliflags "github.com/docker/cli/cli/flags"
@@ -45,7 +43,7 @@ type EndpointDefaultResolver interface {
4543
}
4644

4745
// ResolveDefaultContext creates a Metadata for the current CLI invocation parameters
48-
func ResolveDefaultContext(opts *cliflags.CommonOptions, config *configfile.ConfigFile, storeconfig store.Config, stderr io.Writer) (*DefaultContext, error) {
46+
func ResolveDefaultContext(opts *cliflags.CommonOptions, config store.Config) (*DefaultContext, error) {
4947
contextTLSData := store.ContextTLSData{
5048
Endpoints: make(map[string]store.EndpointTLSData),
5149
}
@@ -66,7 +64,7 @@ func ResolveDefaultContext(opts *cliflags.CommonOptions, config *configfile.Conf
6664
contextTLSData.Endpoints[docker.DockerEndpoint] = *dockerEP.TLSData.ToStoreTLSData()
6765
}
6866

69-
if err := storeconfig.ForeachEndpointType(func(n string, get store.TypeGetter) error {
67+
if err := config.ForeachEndpointType(func(n string, get store.TypeGetter) error {
7068
if n == docker.DockerEndpoint { // handled above
7169
return nil
7270
}

cli/command/defaultcontextstore_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestDefaultContextInitializer(t *testing.T) {
6060
TLSOptions: &tlsconfig.Options{
6161
CAFile: "./testdata/ca.pem",
6262
},
63-
}, cli.ConfigFile(), DefaultContextStoreConfig(), cli.Err())
63+
}, DefaultContextStoreConfig())
6464
assert.NilError(t, err)
6565
assert.Equal(t, "default", ctx.Meta.Name)
6666
assert.DeepEqual(t, "ssh://someswarmserver", ctx.Meta.Endpoints[docker.DockerEndpoint].(docker.EndpointMeta).Host)

0 commit comments

Comments
 (0)