@@ -8,20 +8,22 @@ import (
88 "github.com/docker/cli/cli"
99 "github.com/docker/cli/cli/command"
1010 "github.com/docker/cli/cli/context/docker"
11- "github.com/docker/cli/cli/context/kubernetes"
1211 "github.com/docker/cli/cli/context/store"
1312 "github.com/pkg/errors"
1413 "github.com/spf13/cobra"
1514)
1615
1716// CreateOptions are the options used for creating a context
1817type CreateOptions struct {
19- Name string
20- Description string
18+ Name string
19+ Description string
20+ Docker map [string ]string
21+ From string
22+
23+ // Deprecated
2124 DefaultStackOrchestrator string
22- Docker map [string ]string
23- Kubernetes map [string ]string
24- From string
25+ // Deprecated
26+ Kubernetes map [string ]string
2527}
2628
2729func longCreateDescription () string {
@@ -33,13 +35,6 @@ func longCreateDescription() string {
3335 fmt .Fprintf (tw , "%s\t %s\n " , d .name , d .description )
3436 }
3537 tw .Flush ()
36- buf .WriteString ("\n Kubernetes endpoint config:\n \n " )
37- tw = tabwriter .NewWriter (buf , 20 , 1 , 3 , ' ' , 0 )
38- fmt .Fprintln (tw , "NAME\t DESCRIPTION" )
39- for _ , d := range kubernetesConfigKeysDescriptions {
40- fmt .Fprintf (tw , "%s\t %s\n " , d .name , d .description )
41- }
42- tw .Flush ()
4338 buf .WriteString ("\n Example:\n \n $ docker context create my-context --description \" some description\" --docker \" host=tcp://myserver:2376,ca=~/ca-file,cert=~/cert-file,key=~/key-file\" \n " )
4439 return buf .String ()
4540}
@@ -63,31 +58,30 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command {
6358 "default-stack-orchestrator" , "" ,
6459 "Default orchestrator for stack operations to use with this context (swarm|kubernetes|all)" )
6560 flags .SetAnnotation ("default-stack-orchestrator" , "deprecated" , nil )
61+ flags .MarkDeprecated ("default-stack-orchestrator" , "option will be ignored" )
6662 flags .StringToStringVar (& opts .Docker , "docker" , nil , "set the docker endpoint" )
6763 flags .StringToStringVar (& opts .Kubernetes , "kubernetes" , nil , "set the kubernetes endpoint" )
6864 flags .SetAnnotation ("kubernetes" , "kubernetes" , nil )
6965 flags .SetAnnotation ("kubernetes" , "deprecated" , nil )
66+ flags .MarkDeprecated ("kubernetes" , "option will be ignored" )
7067 flags .StringVar (& opts .From , "from" , "" , "create context from a named context" )
7168 return cmd
7269}
7370
7471// RunCreate creates a Docker context
7572func RunCreate (cli command.Cli , o * CreateOptions ) error {
7673 s := cli .ContextStore ()
77- if err := checkContextNameForCreation (s , o .Name ); err != nil {
78- return err
79- }
80- stackOrchestrator , err := command .NormalizeOrchestrator (o .DefaultStackOrchestrator )
74+ err := checkContextNameForCreation (s , o .Name )
8175 if err != nil {
82- return errors . Wrap ( err , "unable to parse default-stack-orchestrator" )
76+ return err
8377 }
8478 switch {
8579 case o .From == "" && o .Docker == nil && o .Kubernetes == nil :
86- err = createFromExistingContext (s , cli .CurrentContext (), stackOrchestrator , o )
80+ err = createFromExistingContext (s , cli .CurrentContext (), o )
8781 case o .From != "" :
88- err = createFromExistingContext (s , o .From , stackOrchestrator , o )
82+ err = createFromExistingContext (s , o .From , o )
8983 default :
90- err = createNewContext (o , stackOrchestrator , cli , s )
84+ err = createNewContext (o , cli , s )
9185 }
9286 if err == nil {
9387 fmt .Fprintln (cli .Out (), o .Name )
@@ -96,11 +90,11 @@ func RunCreate(cli command.Cli, o *CreateOptions) error {
9690 return err
9791}
9892
99- func createNewContext (o * CreateOptions , stackOrchestrator command. Orchestrator , cli command.Cli , s store.Writer ) error {
93+ func createNewContext (o * CreateOptions , cli command.Cli , s store.Writer ) error {
10094 if o .Docker == nil {
10195 return errors .New ("docker endpoint configuration is required" )
10296 }
103- contextMetadata := newContextMetadata (stackOrchestrator , o )
97+ contextMetadata := newContextMetadata (o )
10498 contextTLSData := store.ContextTLSData {
10599 Endpoints : make (map [string ]store.EndpointTLSData ),
106100 }
@@ -112,22 +106,7 @@ func createNewContext(o *CreateOptions, stackOrchestrator command.Orchestrator,
112106 if dockerTLS != nil {
113107 contextTLSData .Endpoints [docker .DockerEndpoint ] = * dockerTLS
114108 }
115- if o .Kubernetes != nil {
116- kubernetesEP , kubernetesTLS , err := getKubernetesEndpointMetadataAndTLS (cli , o .Kubernetes )
117- if err != nil {
118- return errors .Wrap (err , "unable to create kubernetes endpoint config" )
119- }
120- if kubernetesEP == nil && stackOrchestrator .HasKubernetes () {
121- return errors .Errorf ("cannot specify orchestrator %q without configuring a Kubernetes endpoint" , stackOrchestrator )
122- }
123- if kubernetesEP != nil {
124- contextMetadata .Endpoints [kubernetes .KubernetesEndpoint ] = kubernetesEP
125- }
126- if kubernetesTLS != nil {
127- contextTLSData .Endpoints [kubernetes .KubernetesEndpoint ] = * kubernetesTLS
128- }
129- }
130- if err := validateEndpointsAndOrchestrator (contextMetadata ); err != nil {
109+ if err := validateEndpoints (contextMetadata ); err != nil {
131110 return err
132111 }
133112 if err := s .CreateOrUpdate (contextMetadata ); err != nil {
@@ -152,26 +131,24 @@ func checkContextNameForCreation(s store.Reader, name string) error {
152131 return nil
153132}
154133
155- func createFromExistingContext (s store.ReaderWriter , fromContextName string , stackOrchestrator command. Orchestrator , o * CreateOptions ) error {
134+ func createFromExistingContext (s store.ReaderWriter , fromContextName string , o * CreateOptions ) error {
156135 if len (o .Docker ) != 0 || len (o .Kubernetes ) != 0 {
157136 return errors .New ("cannot use --docker or --kubernetes flags when --from is set" )
158137 }
159- reader := store .Export (fromContextName , & descriptionAndOrchestratorStoreDecorator {
160- Reader : s ,
161- description : o .Description ,
162- orchestrator : stackOrchestrator ,
138+ reader := store .Export (fromContextName , & descriptionDecorator {
139+ Reader : s ,
140+ description : o .Description ,
163141 })
164142 defer reader .Close ()
165143 return store .Import (o .Name , s , reader )
166144}
167145
168- type descriptionAndOrchestratorStoreDecorator struct {
146+ type descriptionDecorator struct {
169147 store.Reader
170- description string
171- orchestrator command.Orchestrator
148+ description string
172149}
173150
174- func (d * descriptionAndOrchestratorStoreDecorator ) GetMetadata (name string ) (store.Metadata , error ) {
151+ func (d * descriptionDecorator ) GetMetadata (name string ) (store.Metadata , error ) {
175152 c , err := d .Reader .GetMetadata (name )
176153 if err != nil {
177154 return c , err
@@ -183,19 +160,15 @@ func (d *descriptionAndOrchestratorStoreDecorator) GetMetadata(name string) (sto
183160 if d .description != "" {
184161 typedContext .Description = d .description
185162 }
186- if d .orchestrator != command .Orchestrator ("" ) {
187- typedContext .StackOrchestrator = d .orchestrator
188- }
189163 c .Metadata = typedContext
190164 return c , nil
191165}
192166
193- func newContextMetadata (stackOrchestrator command. Orchestrator , o * CreateOptions ) store.Metadata {
167+ func newContextMetadata (o * CreateOptions ) store.Metadata {
194168 return store.Metadata {
195169 Endpoints : make (map [string ]interface {}),
196170 Metadata : command.DockerContext {
197- Description : o .Description ,
198- StackOrchestrator : stackOrchestrator ,
171+ Description : o .Description ,
199172 },
200173 Name : o .Name ,
201174 }
0 commit comments