Skip to content

Commit 91bb382

Browse files
committed
more kubernetes context
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent a0f4c18 commit 91bb382

File tree

11 files changed

+12
-268
lines changed

11 files changed

+12
-268
lines changed

cli/command/context/create.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ func longCreateDescription() string {
3232
fmt.Fprintf(tw, "%s\t%s\n", d.name, d.description)
3333
}
3434
tw.Flush()
35-
buf.WriteString("\nKubernetes endpoint config:\n\n")
36-
tw = tabwriter.NewWriter(buf, 20, 1, 3, ' ', 0)
37-
fmt.Fprintln(tw, "NAME\tDESCRIPTION")
38-
for _, d := range kubernetesConfigKeysDescriptions {
39-
fmt.Fprintf(tw, "%s\t%s\n", d.name, d.description)
40-
}
41-
tw.Flush()
4235
buf.WriteString("\nExample:\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")
4336
return buf.String()
4437
}

cli/command/context/create_test.go

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/docker/cli/cli/command"
1010
"github.com/docker/cli/cli/config/configfile"
1111
"github.com/docker/cli/cli/context/docker"
12-
"github.com/docker/cli/cli/context/kubernetes"
1312
"github.com/docker/cli/cli/context/store"
1413
"github.com/docker/cli/internal/test"
1514
"gotest.tools/v3/assert"
@@ -22,7 +21,6 @@ func makeFakeCli(t *testing.T, opts ...func(*test.FakeCli)) (*test.FakeCli, func
2221
storeConfig := store.NewConfig(
2322
func() interface{} { return &command.DockerContext{} },
2423
store.EndpointTypeGetter(docker.DockerEndpoint, func() interface{} { return &docker.EndpointMeta{} }),
25-
store.EndpointTypeGetter(kubernetes.KubernetesEndpoint, func() interface{} { return &kubernetes.EndpointMeta{} }),
2624
)
2725
store := &command.ContextStoreWithDefault{
2826
Store: store.New(dir, storeConfig),
@@ -106,14 +104,6 @@ func TestCreateInvalids(t *testing.T) {
106104
},
107105
expecterErr: `specified orchestrator "invalid" is invalid, please use either kubernetes, swarm or all`,
108106
},
109-
{
110-
options: CreateOptions{
111-
Name: "orchestrator-kubernetes-no-endpoint",
112-
DefaultStackOrchestrator: "kubernetes",
113-
Docker: map[string]string{},
114-
},
115-
expecterErr: `cannot specify orchestrator "kubernetes" without configuring a Kubernetes endpoint`,
116-
},
117107
{
118108
options: CreateOptions{
119109
Name: "orchestrator-all-no-endpoint",
@@ -162,43 +152,6 @@ func TestCreateOrchestratorEmpty(t *testing.T) {
162152
assertContextCreateLogging(t, cli, "test")
163153
}
164154

165-
func validateTestKubeEndpoint(t *testing.T, s store.Reader, name string) {
166-
t.Helper()
167-
ctxMetadata, err := s.GetMetadata(name)
168-
assert.NilError(t, err)
169-
kubeMeta := ctxMetadata.Endpoints[kubernetes.KubernetesEndpoint].(kubernetes.EndpointMeta)
170-
kubeEP, err := kubeMeta.WithTLSData(s, name)
171-
assert.NilError(t, err)
172-
assert.Equal(t, "https://someserver.example.com", kubeEP.Host)
173-
assert.Equal(t, "the-ca", string(kubeEP.TLSData.CA))
174-
assert.Equal(t, "the-cert", string(kubeEP.TLSData.Cert))
175-
assert.Equal(t, "the-key", string(kubeEP.TLSData.Key))
176-
}
177-
178-
func createTestContextWithKube(t *testing.T, cli command.Cli) {
179-
t.Helper()
180-
revert := env.Patch(t, "KUBECONFIG", "./testdata/test-kubeconfig")
181-
defer revert()
182-
183-
err := RunCreate(cli, &CreateOptions{
184-
Name: "test",
185-
DefaultStackOrchestrator: "all",
186-
Kubernetes: map[string]string{
187-
keyFrom: "default",
188-
},
189-
Docker: map[string]string{},
190-
})
191-
assert.NilError(t, err)
192-
}
193-
194-
func TestCreateOrchestratorAllKubernetesEndpointFromCurrent(t *testing.T) {
195-
cli, cleanup := makeFakeCli(t)
196-
defer cleanup()
197-
createTestContextWithKube(t, cli)
198-
assertContextCreateLogging(t, cli, "test")
199-
validateTestKubeEndpoint(t, cli.ContextStore(), "test")
200-
}
201-
202155
func TestCreateFromContext(t *testing.T) {
203156
cases := []struct {
204157
name string
@@ -282,12 +235,9 @@ func TestCreateFromContext(t *testing.T) {
282235
assert.NilError(t, err)
283236
dockerEndpoint, err := docker.EndpointFromContext(newContext)
284237
assert.NilError(t, err)
285-
kubeEndpoint := kubernetes.EndpointFromContext(newContext)
286-
assert.Check(t, kubeEndpoint != nil)
287238
assert.Equal(t, newContextTyped.Description, c.expectedDescription)
288239
assert.Equal(t, newContextTyped.StackOrchestrator, c.expectedOrchestrator)
289240
assert.Equal(t, dockerEndpoint.Host, "tcp://42.42.42.42:2375")
290-
assert.Equal(t, kubeEndpoint.Host, "https://someserver.example.com")
291241
})
292242
}
293243
}
@@ -311,12 +261,6 @@ func TestCreateFromCurrent(t *testing.T) {
311261
expectedDescription: "new description",
312262
expectedOrchestrator: command.OrchestratorSwarm,
313263
},
314-
{
315-
name: "override-orchestrator",
316-
orchestrator: "kubernetes",
317-
expectedDescription: "original description",
318-
expectedOrchestrator: command.OrchestratorKubernetes,
319-
},
320264
}
321265

322266
cli, cleanup := makeFakeCli(t)
@@ -356,12 +300,9 @@ func TestCreateFromCurrent(t *testing.T) {
356300
assert.NilError(t, err)
357301
dockerEndpoint, err := docker.EndpointFromContext(newContext)
358302
assert.NilError(t, err)
359-
kubeEndpoint := kubernetes.EndpointFromContext(newContext)
360-
assert.Check(t, kubeEndpoint != nil)
361303
assert.Equal(t, newContextTyped.Description, c.expectedDescription)
362304
assert.Equal(t, newContextTyped.StackOrchestrator, c.expectedOrchestrator)
363305
assert.Equal(t, dockerEndpoint.Host, "tcp://42.42.42.42:2375")
364-
assert.Equal(t, kubeEndpoint.Host, "https://someserver.example.com")
365306
})
366307
}
367308
}

cli/command/context/export-import_test.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ func TestExportImportWithFile(t *testing.T) {
1919
contextFile := filepath.Join(contextDir, "exported")
2020
cli, cleanup := makeFakeCli(t)
2121
defer cleanup()
22-
createTestContextWithKube(t, cli)
2322
cli.ErrBuffer().Reset()
2423
assert.NilError(t, RunExport(cli, &ExportOptions{
2524
ContextName: "test",
@@ -45,7 +44,6 @@ func TestExportImportWithFile(t *testing.T) {
4544
func TestExportImportPipe(t *testing.T) {
4645
cli, cleanup := makeFakeCli(t)
4746
defer cleanup()
48-
createTestContextWithKube(t, cli)
4947
cli.ErrBuffer().Reset()
5048
cli.OutBuffer().Reset()
5149
assert.NilError(t, RunExport(cli, &ExportOptions{
@@ -70,39 +68,13 @@ func TestExportImportPipe(t *testing.T) {
7068
assert.Equal(t, "Successfully imported context \"test2\"\n", cli.ErrBuffer().String())
7169
}
7270

73-
func TestExportKubeconfig(t *testing.T) {
74-
contextDir, err := ioutil.TempDir("", t.Name()+"context")
75-
assert.NilError(t, err)
76-
defer os.RemoveAll(contextDir)
77-
contextFile := filepath.Join(contextDir, "exported")
78-
cli, cleanup := makeFakeCli(t)
79-
defer cleanup()
80-
createTestContextWithKube(t, cli)
81-
cli.ErrBuffer().Reset()
82-
assert.NilError(t, RunExport(cli, &ExportOptions{
83-
ContextName: "test",
84-
Dest: contextFile,
85-
Kubeconfig: true,
86-
}))
87-
assert.Equal(t, cli.ErrBuffer().String(), fmt.Sprintf("Written file %q\n", contextFile))
88-
assert.NilError(t, RunCreate(cli, &CreateOptions{
89-
Name: "test2",
90-
Kubernetes: map[string]string{
91-
keyKubeconfig: contextFile,
92-
},
93-
Docker: map[string]string{},
94-
}))
95-
validateTestKubeEndpoint(t, cli.ContextStore(), "test2")
96-
}
97-
9871
func TestExportExistingFile(t *testing.T) {
9972
contextDir, err := ioutil.TempDir("", t.Name()+"context")
10073
assert.NilError(t, err)
10174
defer os.RemoveAll(contextDir)
10275
contextFile := filepath.Join(contextDir, "exported")
10376
cli, cleanup := makeFakeCli(t)
10477
defer cleanup()
105-
createTestContextWithKube(t, cli)
10678
cli.ErrBuffer().Reset()
10779
assert.NilError(t, ioutil.WriteFile(contextFile, []byte{}, 0644))
10880
err = RunExport(cli, &ExportOptions{ContextName: "test", Dest: contextFile})

cli/command/context/options.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ const (
2020
keyCert = "cert"
2121
keyKey = "key"
2222
keySkipTLSVerify = "skip-tls-verify"
23-
keyKubeconfig = "config-file"
24-
keyKubecontext = "context-override"
25-
keyKubenamespace = "namespace-override"
2623
)
2724

2825
type configKeyDescription struct {
@@ -39,12 +36,6 @@ var (
3936
keyKey: {},
4037
keySkipTLSVerify: {},
4138
}
42-
allowedKubernetesConfigKeys = map[string]struct{}{
43-
keyFrom: {},
44-
keyKubeconfig: {},
45-
keyKubecontext: {},
46-
keyKubenamespace: {},
47-
}
4839
dockerConfigKeysDescriptions = []configKeyDescription{
4940
{
5041
name: keyFrom,
@@ -71,24 +62,6 @@ var (
7162
description: "Skip TLS certificate validation",
7263
},
7364
}
74-
kubernetesConfigKeysDescriptions = []configKeyDescription{
75-
{
76-
name: keyFrom,
77-
description: "Copy named context's Kubernetes endpoint configuration",
78-
},
79-
{
80-
name: keyKubeconfig,
81-
description: "Path to a Kubernetes config file",
82-
},
83-
{
84-
name: keyKubecontext,
85-
description: "Overrides the context set in the kubernetes config file",
86-
},
87-
{
88-
name: keyKubenamespace,
89-
description: "Overrides the namespace set in the kubernetes config file",
90-
},
91-
}
9265
)
9366

9467
func parseBool(config map[string]string, name string) (bool, error) {

cli/command/context/update.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@ func longUpdateDescription() string {
3131
fmt.Fprintf(tw, "%s\t%s\n", d.name, d.description)
3232
}
3333
tw.Flush()
34-
buf.WriteString("\nKubernetes endpoint config:\n\n")
35-
tw = tabwriter.NewWriter(buf, 20, 1, 3, ' ', 0)
36-
fmt.Fprintln(tw, "NAME\tDESCRIPTION")
37-
for _, d := range kubernetesConfigKeysDescriptions {
38-
fmt.Fprintf(tw, "%s\t%s\n", d.name, d.description)
39-
}
40-
tw.Flush()
4134
buf.WriteString("\nExample:\n\n$ docker context update my-context --description \"some description\" --docker \"host=tcp://myserver:2376,ca=~/ca-file,cert=~/cert-file,key=~/key-file\"\n")
4235
return buf.String()
4336
}

cli/command/context/update_test.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55

66
"github.com/docker/cli/cli/command"
77
"github.com/docker/cli/cli/context/docker"
8-
"github.com/docker/cli/cli/context/kubernetes"
98
"gotest.tools/v3/assert"
109
"gotest.tools/v3/assert/cmp"
1110
)
@@ -52,38 +51,10 @@ func TestUpdateDockerOnly(t *testing.T) {
5251
assert.NilError(t, err)
5352
assert.Equal(t, dc.StackOrchestrator, command.OrchestratorSwarm)
5453
assert.Equal(t, dc.Description, "description of test")
55-
assert.Check(t, cmp.Contains(c.Endpoints, kubernetes.KubernetesEndpoint))
5654
assert.Check(t, cmp.Contains(c.Endpoints, docker.DockerEndpoint))
5755
assert.Equal(t, c.Endpoints[docker.DockerEndpoint].(docker.EndpointMeta).Host, "tcp://some-host")
5856
}
5957

60-
func TestUpdateStackOrchestratorStrategy(t *testing.T) {
61-
cli, cleanup := makeFakeCli(t)
62-
defer cleanup()
63-
err := RunCreate(cli, &CreateOptions{
64-
Name: "test",
65-
DefaultStackOrchestrator: "swarm",
66-
Docker: map[string]string{},
67-
})
68-
assert.NilError(t, err)
69-
err = RunUpdate(cli, &UpdateOptions{
70-
Name: "test",
71-
DefaultStackOrchestrator: "kubernetes",
72-
})
73-
assert.ErrorContains(t, err, `cannot specify orchestrator "kubernetes" without configuring a Kubernetes endpoint`)
74-
}
75-
76-
func TestUpdateStackOrchestratorStrategyRemoveKubeEndpoint(t *testing.T) {
77-
cli, cleanup := makeFakeCli(t)
78-
defer cleanup()
79-
createTestContextWithKubeAndSwarm(t, cli, "test", "kubernetes")
80-
err := RunUpdate(cli, &UpdateOptions{
81-
Name: "test",
82-
Kubernetes: map[string]string{},
83-
})
84-
assert.ErrorContains(t, err, `cannot specify orchestrator "kubernetes" without configuring a Kubernetes endpoint`)
85-
}
86-
8758
func TestUpdateInvalidDockerHost(t *testing.T) {
8859
cli, cleanup := makeFakeCli(t)
8960
defer cleanup()

cli/command/formatter/context.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ package formatter
22

33
const (
44
// ClientContextTableFormat is the default client context format
5-
ClientContextTableFormat = "table {{.Name}}{{if .Current}} *{{end}}\t{{.Description}}\t{{.DockerEndpoint}}\t{{.KubernetesEndpoint}}\t{{.StackOrchestrator}}"
5+
ClientContextTableFormat = "table {{.Name}}{{if .Current}} *{{end}}\t{{.Description}}\t{{.DockerEndpoint}}\t{{.StackOrchestrator}}"
66

77
dockerEndpointHeader = "DOCKER ENDPOINT"
8-
kubernetesEndpointHeader = "KUBERNETES ENDPOINT"
98
stackOrchestrastorHeader = "ORCHESTRATOR"
109
quietContextFormat = "{{.Name}}"
1110
)
@@ -23,12 +22,11 @@ func NewClientContextFormat(source string, quiet bool) Format {
2322

2423
// ClientContext is a context for display
2524
type ClientContext struct {
26-
Name string
27-
Description string
28-
DockerEndpoint string
29-
KubernetesEndpoint string
30-
StackOrchestrator string
31-
Current bool
25+
Name string
26+
Description string
27+
DockerEndpoint string
28+
StackOrchestrator string
29+
Current bool
3230
}
3331

3432
// ClientContextWrite writes formatted contexts using the Context
@@ -52,11 +50,10 @@ type clientContextContext struct {
5250
func newClientContextContext() *clientContextContext {
5351
ctx := clientContextContext{}
5452
ctx.Header = SubHeaderContext{
55-
"Name": NameHeader,
56-
"Description": DescriptionHeader,
57-
"DockerEndpoint": dockerEndpointHeader,
58-
"KubernetesEndpoint": kubernetesEndpointHeader,
59-
"StackOrchestrator": stackOrchestrastorHeader,
53+
"Name": NameHeader,
54+
"Description": DescriptionHeader,
55+
"DockerEndpoint": dockerEndpointHeader,
56+
"StackOrchestrator": stackOrchestrastorHeader,
6057
}
6158
return &ctx
6259
}
@@ -82,7 +79,7 @@ func (c *clientContextContext) DockerEndpoint() string {
8279
}
8380

8481
func (c *clientContextContext) KubernetesEndpoint() string {
85-
return c.c.KubernetesEndpoint
82+
return ""
8683
}
8784

8885
func (c *clientContextContext) StackOrchestrator() string {

0 commit comments

Comments
 (0)