Skip to content

Kubernetes-as-orchestrator fails to process multi-file $KUBECONFIG #2334

@TBBle

Description

@TBBle

(Migrating over from docker/for-win#4491)

  • I have tried with the latest version of my channel (Stable)
  • I have uploaded Diagnostics
  • Diagnostics ID: N/A, no crash or other behaviour to trigger the diagnostics uploader

Expected behavior

With a customised KUBECONFIG env-var that lists multiple config files, docker ps should still function when the option "Deploy Docker Stacks to Kubernetes by default" is selected.

Actual behavior

With a customised KUBECONFIG env-var that lists multiple config files, docker ps fails function when the option "Deploy Docker Stacks to Kubernetes by default" is selected, with the following output:

PS C:\Users\paulh> docker ps
unable to resolve docker endpoint: default orchestrator is kubernetes but unable to resolve kubernetes endpoint: Error loading config file "C:\Users\paulh\.kube\config;C:\Users\paulh\.kube\dev.config;C:\Users\paulh\.kube\ci.config;C:\Users\paulh\.kube\k8s-test.config;C:\Users\paulh\.kube\ci2.config;C:\Users\paulh\.kube\project.config;": open C:\Users\paulh\.kube\config;C:\Users\paulh\.kube\dev.config;C:\Users\paulh\.kube\ci.config;C:\Users\paulh\.kube\k8s-test.config;C:\Users\paulh\.kube\ci2.config;C:\Users\paulh\.kube\project.config;: The filename, directory name, or volume label syntax is incorrect.

It's pretty clearly trying to blindly open(${KUBE_CONFIG}), assuming the environment variable points to a single file, not a list of config files.

I couldn't change the setting as the 'Apply & Restart' button wouldn't light up, since the setting is on the Kubernetes tab, and Kubernetes was still starting. So I manually removed the setting from %USERPROFILE%\.docker\config.json, and docker ps was working again.

I also suspect this was blocking the Docker Desktop Kubernetes stack from starting, but it could also have been a coincidence that as soon as I changed the config file, it started up.

Information

  • Windows Version: Windows 10 Enterprise 1903 (18362.175)
  • Docker Desktop Version: 2.1.0.1 (37199) Stable

Steps to reproduce the behavior

  1. Install fresh Docker Desktop for Windows
  2. Enable Kubernetes
  3. Customise your KUBECONFIG environment variable to point to extra config files for other Kubernetes stacks you work with
  4. Confirm docker ps operates correctly.
  5. Enable the 'Deploy Docker Stacks to Kubernetes by default' setting, click "Apply & Restart"
  6. Confirm docker ps now gives the listed error.

As noted by @mat007 in docker/for-win#4491 (comment), the problem is that in the two places I can see in this code-base that use KUBECONFIG, (func (c *EndpointMeta) kubernetes.ResolveDefault and func context.getKubernetesEndpoint) they both take that value, default it to ~/.kube/config if unset, and pass it to func kubernetes.FromKubeConfig.

This function passes the passed-in filename to clientcmd.NewNonInteractiveDeferredLoadingClientConfig as clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeconfig}, which suppresses the merging behaviour normally employed by kubectl.

I think what we want to do is either use or reimplement a workalike for NewDefaultClientConfigLoadingRules which takes care of multi-file KUBECONFIG, and defaults to ~/.kube/config if not set.

Neither of these code-paths otherwise cares about the filename in question.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions