From 8181aa8879e2f89da6c1dbac318f85f6b6b2e105 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 20 Jun 2023 13:36:54 +0200 Subject: [PATCH] cli/command/context: don't pass CLI if we only need context-store Signed-off-by: Sebastiaan van Stijn --- cli/command/context/create.go | 10 +++++----- cli/command/context/options.go | 9 ++++----- cli/command/context/update.go | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/cli/command/context/create.go b/cli/command/context/create.go index 757d40adef..6334ce6c34 100644 --- a/cli/command/context/create.go +++ b/cli/command/context/create.go @@ -80,7 +80,7 @@ func RunCreate(cli command.Cli, o *CreateOptions) error { case o.From != "": err = createFromExistingContext(s, o.From, o) default: - err = createNewContext(o, cli, s) + err = createNewContext(s, o) } if err == nil { fmt.Fprintln(cli.Out(), o.Name) @@ -89,11 +89,11 @@ func RunCreate(cli command.Cli, o *CreateOptions) error { return err } -func createNewContext(o *CreateOptions, cli command.Cli, s store.Writer) error { +func createNewContext(contextStore store.ReaderWriter, o *CreateOptions) error { if o.Docker == nil { return errors.New("docker endpoint configuration is required") } - dockerEP, dockerTLS, err := getDockerEndpointMetadataAndTLS(cli, o.Docker) + dockerEP, dockerTLS, err := getDockerEndpointMetadataAndTLS(contextStore, o.Docker) if err != nil { return errors.Wrap(err, "unable to create docker endpoint config") } @@ -115,10 +115,10 @@ func createNewContext(o *CreateOptions, cli command.Cli, s store.Writer) error { if err := validateEndpoints(contextMetadata); err != nil { return err } - if err := s.CreateOrUpdate(contextMetadata); err != nil { + if err := contextStore.CreateOrUpdate(contextMetadata); err != nil { return err } - return s.ResetTLSMaterial(o.Name, &contextTLSData) + return contextStore.ResetTLSMaterial(o.Name, &contextTLSData) } func checkContextNameForCreation(s store.Reader, name string) error { diff --git a/cli/command/context/options.go b/cli/command/context/options.go index 39707fe3e9..ce79d57a4f 100644 --- a/cli/command/context/options.go +++ b/cli/command/context/options.go @@ -5,7 +5,6 @@ import ( "strconv" "strings" - "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/context" "github.com/docker/cli/cli/context/docker" "github.com/docker/cli/cli/context/store" @@ -86,12 +85,12 @@ func validateConfig(config map[string]string, allowedKeys map[string]struct{}) e return errors.New(strings.Join(errs, "\n")) } -func getDockerEndpoint(dockerCli command.Cli, config map[string]string) (docker.Endpoint, error) { +func getDockerEndpoint(contextStore store.Reader, config map[string]string) (docker.Endpoint, error) { if err := validateConfig(config, allowedDockerConfigKeys); err != nil { return docker.Endpoint{}, err } if contextName, ok := config[keyFrom]; ok { - metadata, err := dockerCli.ContextStore().GetMetadata(contextName) + metadata, err := contextStore.GetMetadata(contextName) if err != nil { return docker.Endpoint{}, err } @@ -126,8 +125,8 @@ func getDockerEndpoint(dockerCli command.Cli, config map[string]string) (docker. return ep, nil } -func getDockerEndpointMetadataAndTLS(dockerCli command.Cli, config map[string]string) (docker.EndpointMeta, *store.EndpointTLSData, error) { - ep, err := getDockerEndpoint(dockerCli, config) +func getDockerEndpointMetadataAndTLS(contextStore store.Reader, config map[string]string) (docker.EndpointMeta, *store.EndpointTLSData, error) { + ep, err := getDockerEndpoint(contextStore, config) if err != nil { return docker.EndpointMeta{}, nil, err } diff --git a/cli/command/context/update.go b/cli/command/context/update.go index eefd5d2442..5a776cb1db 100644 --- a/cli/command/context/update.go +++ b/cli/command/context/update.go @@ -84,7 +84,7 @@ func RunUpdate(cli command.Cli, o *UpdateOptions) error { tlsDataToReset := make(map[string]*store.EndpointTLSData) if o.Docker != nil { - dockerEP, dockerTLS, err := getDockerEndpointMetadataAndTLS(cli, o.Docker) + dockerEP, dockerTLS, err := getDockerEndpointMetadataAndTLS(s, o.Docker) if err != nil { return errors.Wrap(err, "unable to create docker endpoint config") }