Make default context behaves like a real context:
- when using "--context default" parameter - when printing the list of contexts - when exporting the default context to a tarball Signed-off-by: Jean-Christophe Sirot <jean-christophe.sirot@docker.com> (+1 squashed commit) Squashed commits: [20670495] Fix CLI initialization for the `docker stack deploy --help` command and ensure that the dockerCli.CurrentContext() always returns a non empty context name (default as a fallback) Remove now obsolete code handling empty string context name Minor code cleanup Signed-off-by: Jean-Christophe Sirot <jean-christophe.sirot@docker.com>
This commit is contained in:
@ -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 {
|
||||
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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user