Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.2k
Makes the default docker context behavior consistent#1719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -9,7 +9,6 @@ import ( | ||
| "github.com/docker/cli/cli/command/formatter" | ||
| "github.com/docker/cli/cli/context/docker" | ||
| kubecontext "github.com/docker/cli/cli/context/kubernetes" | ||
| "github.com/docker/cli/kubernetes" | ||
| "github.com/spf13/cobra" | ||
| "vbom.ml/util/sortorder" | ||
| ) | ||
| @@ -61,6 +60,9 @@ func runList(dockerCli command.Cli, opts *listOptions) error { | ||
| if kubernetesEndpoint != nil { | ||
| kubEndpointText = fmt.Sprintf("%s (%s)", kubernetesEndpoint.Host, kubernetesEndpoint.DefaultNamespace) | ||
| } | ||
| if rawMeta.Name == command.DefaultContextName { | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @thaJeztah I didn't want to add specific code for import/export command to avoid, when importing an exported default context, having a second context with the "Current DOCKER_HOST based configuration" description. Therefore I decided to leave the description empty for the default context and add handle that case here. Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still a bit on the fence on this one (i.e., the same applies to other contexts, which also by default copy the description), but not a blocker
| ||
| meta.Description = "Current DOCKER_HOST based configuration" | ||
| } | ||
| desc := formatter.ClientContext{ | ||
| Name: rawMeta.Name, | ||
| Current: rawMeta.Name == curContext, | ||
| @@ -71,29 +73,6 @@ func runList(dockerCli command.Cli, opts *listOptions) error { | ||
| } | ||
| contexts = append(contexts, &desc) | ||
| } | ||
| if !opts.quiet { | ||
| desc := &formatter.ClientContext{ | ||
| Name: "default", | ||
| Description: "Current DOCKER_HOST based configuration", | ||
| } | ||
| if dockerCli.CurrentContext() == "" { | ||
| orchestrator, _ := dockerCli.StackOrchestrator("") | ||
| kubEndpointText := "" | ||
| kubeconfig := kubernetes.NewKubernetesConfig("") | ||
| if cfg, err := kubeconfig.ClientConfig(); err == nil { | ||
| ns, _, _ := kubeconfig.Namespace() | ||
| if ns == "" { | ||
| ns = "default" | ||
| } | ||
| kubEndpointText = fmt.Sprintf("%s (%s)", cfg.Host, ns) | ||
| } | ||
| desc.Current = true | ||
| desc.StackOrchestrator = string(orchestrator) | ||
| desc.DockerEndpoint = dockerCli.DockerEndpoint().Host | ||
| desc.KubernetesEndpoint = kubEndpointText | ||
| } | ||
| contexts = append(contexts, desc) | ||
| } | ||
| sort.Slice(contexts, func(i, j int) bool { | ||
| return sortorder.NaturalLess(contexts[i].Name, contexts[j].Name) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,7 +4,6 @@ import ( | ||
| "testing" | ||
| "github.com/docker/cli/cli/command" | ||
| "github.com/docker/cli/cli/context/docker" | ||
| "gotest.tools/assert" | ||
| "gotest.tools/env" | ||
| "gotest.tools/golden" | ||
| @@ -36,20 +35,6 @@ func TestList(t *testing.T) { | ||
| golden.Assert(t, cli.OutBuffer().String(), "list.golden") | ||
| } | ||
| func TestListNoContext(t *testing.T) { | ||
silvin-lubecki marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| cli, cleanup := makeFakeCli(t) | ||
| defer cleanup() | ||
| defer env.Patch(t, "KUBECONFIG", "./testdata/test-kubeconfig")() | ||
| cli.SetDockerEndpoint(docker.Endpoint{ | ||
| EndpointMeta: docker.EndpointMeta{ | ||
| Host: "https://someswarmserver", | ||
| }, | ||
| }) | ||
| cli.OutBuffer().Reset() | ||
| assert.NilError(t, runList(cli, &listOptions{})) | ||
| golden.Assert(t, cli.OutBuffer().String(), "list.no-context.golden") | ||
| } | ||
| func TestListQuiet(t *testing.T) { | ||
| cli, cleanup := makeFakeCli(t) | ||
| defer cleanup() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| NAME DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT ORCHESTRATOR | ||
| current * description of current https://someswarmserver https://someserver (default) all | ||
| default Current DOCKER_HOST based configuration | ||
| other description of other https://someswarmserver https://someserver (default) all | ||
| unset description of unset https://someswarmserver https://someserver (default) | ||
| NAME DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT ORCHESTRATOR | ||
| current * description of current https://someswarmserver https://someserver (default) all | ||
| default Current DOCKER_HOST based configuration unix:///var/run/docker.sockswarm | ||
| other description of other https://someswarmserver https://someserver (default) all | ||
| unset description of unset https://someswarmserver https://someserver (default) |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| current | ||
| default | ||
| other |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for this PR, but something similar came up in another discussion with @simonferquel - I think this should be an error; we should not silently fall back to
DOCKER_HOST(because then I may be running commands against the wrong environment, which is likely not what you want)