-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
For docker stack ls make an error if Swarm and Kubernetes hosts do not match #1035
Conversation
Renamed to "WIP", because this depends on #1031 to be merged first |
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.
LGTM, thanks @mat007 !
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.
SGTM :fallen_leaf:
cc @thaJeztah
Ah, yes, I was looking at this one a couple of times, trying to grasp the "local socket" situation; let me have a look again |
cli/command/stack/kubernetes/cli.go
Outdated
} | ||
} | ||
} | ||
return fmt.Errorf("Swarm and Kubernetes hosts do not match, check DOCKER_HOST and Kubernetes context") |
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.
So, wondering if we should error, or just print a warning. For example, running inside my development container, this means I can't use --orchestrator=all
;
cat ~/.kube/config | grep server:
server: https://192.168.65.2:6443
docker stack ls
Swarm and Kubernetes hosts do not match, check DOCKER_HOST and Kubernetes context
docker --orchestrator=kubernetes stack ls
NAME SERVICES ORCHESTRATOR NAMESPACE
cat ~/.kube/config | grep server:
server: https://host.docker.internal:6443
docker stack ls
Swarm and Kubernetes hosts do not match, check DOCKER_HOST and Kubernetes context
docker --orchestrator=kubernetes stack ls
NAME SERVICES ORCHESTRATOR NAMESPACE
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.
We should also have a way to find out what we're using, e.g. docker version
doesn't show which server(s) I'm connected to ;
Client:
Version: 18.06.0-dev
API version: 1.37
Go version: go1.10.2
Git commit: 6dc89d02
Built: Fri May 18 11:15:43 2018
OS/Arch: linux/amd64
Experimental: true
Orchestrator: all
Server:
Engine:
Version: 18.05.0-ce
API version: 1.37 (minimum version 1.12)
Go version: go1.10.1
Git commit: f150324
Built: Wed May 9 22:20:16 2018
OS/Arch: linux/amd64
Experimental: true
Kubernetes:
Version: v1.9.6
StackAPI: v1beta2
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.
Maybe it should land to docker info
instead?
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.
Yes, docker info definitely, and likely the error/warning should include the information as well;
Swarm and Kubernetes hosts do not match, check DOCKER_HOST and Kubernetes context
(i.e, it should mention what it found)
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.
I agree we should try to get more details exposed (most likely in info
) but there may be some other wrinkles we need to work out to get that fully wired up. A follow up PR perhaps?
If we could improve the error message to give a little more contextual information that might help users get themselves unstuck. Perhaps something like this?
return fmt.Errorf("Swarm and Kubernetes hosts do not match - DOCKER_HOST=%s and kubernetes context=%s - update DOCKER_HOST or use 'kubectl config use-context' to match", daemonEndpoint.Hostname(), kubeEndpoint.Hostname())
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.
@dhiltgen question is: should it be a fatal error? In the example I gave, swarm and kubernetes are actually on the same host, but we're not able to detect that (because we don't know that 192.168.65.2
is actually localhost
).
My worry is that this will be a blocker for users (for example, when running a docker CLI inside a container, which is a fairly common situation for CI)
Instead of returning an error here, we could print a warning, and just use the host.
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.
I think folks were concerned about subtle failure modes with miswired configurations leading to worse confusion. My $0.02 is a hard fail is OK as long as there's enough detail in the error message so the user can figure it out and correct the problem.
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.
so the user can figure it out and correct the problem.
That's exactly the problem: the user's configuration is correct, so there is no workaround for the user.
It's a "best effort" detection to notify the user in situations where (possibly) swarm and kubernetes don't match, but there's many scenarios where we will be wrong.
I updated the message and turned it into a warning log, @thaJeztah @dhiltgen just tell me if we rather want an error instead and I'll change it back. What sort of output do we want in |
cli/command/stack/kubernetes/cli.go
Outdated
} | ||
} | ||
} | ||
fmt.Fprintf(c.Out(), "Warning: Swarm and Kubernetes hosts do not match - DOCKER_HOST=%s and kubernetes context=%s -"+ |
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.
Should probably be printed on stderr
instead of stdout
?
cli/command/stack/kubernetes/cli.go
Outdated
} | ||
} | ||
fmt.Fprintf(c.Out(), "Warning: Swarm and Kubernetes hosts do not match - DOCKER_HOST=%s and kubernetes context=%s -"+ | ||
" update DOCKER_HOST or use 'kubectl config use-context' to match\n", daemonEndpoint.Hostname(), kubeEndpoint.Hostname()) |
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.
let me think a bit about mentioning DOCKER_HOST
, because this could also be because of docker -H=<some host>
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.
What about
"WARNING: Swarm and Kubernetes hosts do not match - docker host=%s and kubernetes context=%s -"+
" update DOCKER_HOST (or pass -H) or use 'kubectl config use-context' to match
?
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.
Yes that looks better. Perhaps put the "docker host / kubernetes host" in brackets, and align the output for readability (as it's printed when working with docker interactively, we should make it user-friendly) e.g.;
WARNING: Swarm and Kubernetes hosts do not match (docker host=%s, kubernetes host=%s)
Update $DOCKER_HOST (or pass -H), or use 'kubectl config use-context' to match.
Should we use context=
or host=
for k8s? "Context" may be confused with the name of the context?
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.
host
should be fine, I updated the message.
… match Signed-off-by: Mathieu Champlon <mathieu.champlon@docker.com>
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.
LGTM, thanks!
- What I did
Issued an error for docker stack ls if Swarm and Kubernetes hosts do not match when
--orchestrator=all
- How I did it
By comparing the host names:
- How to verify it
Having both Docker for Desktop with Kubernetes and UCP installed and configured:
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)