Skip to content

Commit d1f5262

Browse files
authored
Merge pull request #4362 from thaJeztah/context_dont_pass_cli
cli/command/context: don't pass CLI if we only need context-store
2 parents 5d55800 + 8181aa8 commit d1f5262

3 files changed

Lines changed: 10 additions & 11 deletions

File tree

cli/command/context/create.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func RunCreate(cli command.Cli, o *CreateOptions) error {
8080
case o.From != "":
8181
err = createFromExistingContext(s, o.From, o)
8282
default:
83-
err = createNewContext(o, cli, s)
83+
err = createNewContext(s, o)
8484
}
8585
if err == nil {
8686
fmt.Fprintln(cli.Out(), o.Name)
@@ -89,11 +89,11 @@ func RunCreate(cli command.Cli, o *CreateOptions) error {
8989
return err
9090
}
9191

92-
func createNewContext(o *CreateOptions, cli command.Cli, s store.Writer) error {
92+
func createNewContext(contextStore store.ReaderWriter, o *CreateOptions) error {
9393
if o.Docker == nil {
9494
return errors.New("docker endpoint configuration is required")
9595
}
96-
dockerEP, dockerTLS, err := getDockerEndpointMetadataAndTLS(cli, o.Docker)
96+
dockerEP, dockerTLS, err := getDockerEndpointMetadataAndTLS(contextStore, o.Docker)
9797
if err != nil {
9898
return errors.Wrap(err, "unable to create docker endpoint config")
9999
}
@@ -115,10 +115,10 @@ func createNewContext(o *CreateOptions, cli command.Cli, s store.Writer) error {
115115
if err := validateEndpoints(contextMetadata); err != nil {
116116
return err
117117
}
118-
if err := s.CreateOrUpdate(contextMetadata); err != nil {
118+
if err := contextStore.CreateOrUpdate(contextMetadata); err != nil {
119119
return err
120120
}
121-
return s.ResetTLSMaterial(o.Name, &contextTLSData)
121+
return contextStore.ResetTLSMaterial(o.Name, &contextTLSData)
122122
}
123123

124124
func checkContextNameForCreation(s store.Reader, name string) error {

cli/command/context/options.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"strconv"
66
"strings"
77

8-
"github.com/docker/cli/cli/command"
98
"github.com/docker/cli/cli/context"
109
"github.com/docker/cli/cli/context/docker"
1110
"github.com/docker/cli/cli/context/store"
@@ -86,12 +85,12 @@ func validateConfig(config map[string]string, allowedKeys map[string]struct{}) e
8685
return errors.New(strings.Join(errs, "\n"))
8786
}
8887

89-
func getDockerEndpoint(dockerCli command.Cli, config map[string]string) (docker.Endpoint, error) {
88+
func getDockerEndpoint(contextStore store.Reader, config map[string]string) (docker.Endpoint, error) {
9089
if err := validateConfig(config, allowedDockerConfigKeys); err != nil {
9190
return docker.Endpoint{}, err
9291
}
9392
if contextName, ok := config[keyFrom]; ok {
94-
metadata, err := dockerCli.ContextStore().GetMetadata(contextName)
93+
metadata, err := contextStore.GetMetadata(contextName)
9594
if err != nil {
9695
return docker.Endpoint{}, err
9796
}
@@ -126,8 +125,8 @@ func getDockerEndpoint(dockerCli command.Cli, config map[string]string) (docker.
126125
return ep, nil
127126
}
128127

129-
func getDockerEndpointMetadataAndTLS(dockerCli command.Cli, config map[string]string) (docker.EndpointMeta, *store.EndpointTLSData, error) {
130-
ep, err := getDockerEndpoint(dockerCli, config)
128+
func getDockerEndpointMetadataAndTLS(contextStore store.Reader, config map[string]string) (docker.EndpointMeta, *store.EndpointTLSData, error) {
129+
ep, err := getDockerEndpoint(contextStore, config)
131130
if err != nil {
132131
return docker.EndpointMeta{}, nil, err
133132
}

cli/command/context/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func RunUpdate(cli command.Cli, o *UpdateOptions) error {
8484
tlsDataToReset := make(map[string]*store.EndpointTLSData)
8585

8686
if o.Docker != nil {
87-
dockerEP, dockerTLS, err := getDockerEndpointMetadataAndTLS(cli, o.Docker)
87+
dockerEP, dockerTLS, err := getDockerEndpointMetadataAndTLS(s, o.Docker)
8888
if err != nil {
8989
return errors.Wrap(err, "unable to create docker endpoint config")
9090
}

0 commit comments

Comments
 (0)