-
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
add --from flag to context create #1773
Conversation
9bd25c8
to
a1b6398
Compare
Codecov Report
@@ Coverage Diff @@
## master #1773 +/- ##
=========================================
Coverage ? 56.28%
=========================================
Files ? 308
Lines ? 21323
Branches ? 0
=========================================
Hits ? 12001
Misses ? 8445
Partials ? 877 |
ping @dhiltgen |
a1b6398
to
62b46d6
Compare
cli/command/context/create.go
Outdated
@@ -63,6 +64,7 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command { | |||
"Default orchestrator for stack operations to use with this context (swarm|kubernetes|all)") | |||
flags.StringToStringVar(&opts.Docker, "docker", nil, "set the docker endpoint") | |||
flags.StringToStringVar(&opts.Kubernetes, "kubernetes", nil, "set the kubernetes endpoint") | |||
flags.BoolVar(&opts.FromCurrent, "from-current", false, "get docker endpoint from current configuration") |
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 from-current
flag is misleading, we don't know from what it is: from current context, from current environment? Reading the code it's clear it's from the current context, so I think we should be explicit here and rename it to from-current-context
.
The description should also be amended with something more explicit like: create a new context from the current 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.
In context (no pun intended) it'll be docker context --from-current
. With the proposed change it'll be docker context --from-current-context
which seems stuttery to me. Is the current naming not clear enough when you see it used in context?
When rewording the help we should be careful not to obscure too much the fact that if your current context is the automatic one derived from envvars then that is what you will be importing -- that's the 80% use case for this flag I think (otherwise we'd call this context copy --from=xxx
or context create --from=xxx
etc I think).
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 already have a "flag" (to be fair it's a CSV key) which is from-current
, but creates a context with docker configuration from the current environment
. Same for kubernetes
.
That's a lot of from-current
here, with different semantic. That's why I think we should be explicit here.
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.
After off-line discussion with @ijc, I agree with docker context create --from=my-current-context
👍
@thaJeztah any thought about that?
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.
from-current
either as a flag or as the csv config key, always refers to the current context (being a real one, or default
. It just applies at a different scope (e.g. either copy both, or only one of the endpoints as is).
I agree that naming might be confusing though. We should make sure it is clean before 19.03 is out, but I think we should keep both the flag and the setting names consistent.
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'm good with this 👍
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.
My question would be what is the state of --kubernetes
in the final case -- is it blank or is it inherited from the current context. IOW does passing any single option completely disable the copying behaviour of the first case for all options?
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 if --docker
is not set and --kubernetes
is then it acts as an alias for --docker from-current=true --kubernetes blah=blah
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.
@ijc I guess it is a matter of opinion. My guess is if you want a custom endpoint configuration, you are in fully customized way, but that does not disallow things like:
docker context create my-ctx --docker host=tcp://42.42.42.42:42 --kubernetes from=default ...
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 wasn't expressing (and don't really have) an opinion, but we should make a decision for one or the other.
62b46d6
to
1e01375
Compare
@zappy-shu there is a linter error:
|
a962b05
to
0cb1a47
Compare
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 👍
Reference documentation must be updated then :) |
For symmetry, we need to remove |
I agree, I think the functionality overlaps Would this be a common scenario? As this is already possible (and would be symmetrical with, e.g. docker context export default - | docker context import mynewcontext - |
(Was also thinking of a |
@thaJeztah it is actually how --from is implemented. It allows to override original description / default stack orchestrator though.
and be done with it. |
@@ -63,6 +64,7 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command { | |||
"Default orchestrator for stack operations to use with this context (swarm|kubernetes|all)") | |||
flags.StringToStringVar(&opts.Docker, "docker", nil, "set the docker endpoint") | |||
flags.StringToStringVar(&opts.Kubernetes, "kubernetes", nil, "set the kubernetes endpoint") | |||
flags.StringVar(&opts.From, "from", "", "create context from a named 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.
Perhaps the flag description should mention what the default is
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.
The default depends on whether you use --docker
/--kubernetes
or not. With then it will use the options given to those arguments, without it will create from the current context. Seems a bit finicky to me I'll admit.
To make it less so we could remove the defaulting entirely but then creating from the current/environment is a bit more of a pain.
|
||
func createFromExistingContext(s store.Store, fromContextName string, stackOrchestrator command.Orchestrator, o *CreateOptions) error { | ||
if len(o.Docker) != 0 || len(o.Kubernetes) != 0 { | ||
return errors.New("cannot use --docker or --kubernetes flags when --from is set") |
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.
Do we allow --default-stack-orchestrator
and --description
? Perhaps that's a bit inconsistent (i.e., allowing some options to be overridden when creating --from
, but not others)
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.
Being able to set the description makes sense to me as it is a new context. The default stack orchestrator I don't know much about. From what I understand the main purpose of --from
is to make it easier to copy the connection details for docker/kubernetes from a context or environment variables
@@ -72,4 +73,14 @@ $ export KUBECONFIG=/path/to/my/kubeconfig | |||
$ docker context create my-context --kubernetes "from-current=true" --docker "host=/var/run/docker.sock" | |||
``` | |||
|
|||
By default the `context` will be created from the current context. This will include both docker and, if set, kubernetes endpoint configuration. This is equivalent to `--docker "from-current=true"` or, if the current context has a kubernetes contfiguration, `--docker "from-current=true" --kubernetes "from-current=true"`: |
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.
Can you wrap this to ~80 chars? Also try to avoid future tense;
By default the `context` will be created from the current context. This will include both docker and, if set, kubernetes endpoint configuration. This is equivalent to `--docker "from-current=true"` or, if the current context has a kubernetes contfiguration, `--docker "from-current=true" --kubernetes "from-current=true"`: | |
By default the `context` is created from the current context. This includes | |
both `docker` and, if set, `kubernetes` endpoint configuration. This is | |
equivalent to `--docker "from-current=true"` or, if the current context has | |
a kubernetes contfiguration, `--docker "from-current=true" --kubernetes | |
"from-current=true"`: |
If we agree on removing the from-current
;
By default the `context` will be created from the current context. This will include both docker and, if set, kubernetes endpoint configuration. This is equivalent to `--docker "from-current=true"` or, if the current context has a kubernetes contfiguration, `--docker "from-current=true" --kubernetes "from-current=true"`: | |
By default the `context` is created from the current context. This includes | |
both `docker` and, if set, `kubernetes` endpoint configuration: |
Or (explaining what "by default" means);
By default the `context` will be created from the current context. This will include both docker and, if set, kubernetes endpoint configuration. This is equivalent to `--docker "from-current=true"` or, if the current context has a kubernetes contfiguration, `--docker "from-current=true" --kubernetes "from-current=true"`: | |
If the `--from` option is not set, the `context` is created from the current | |
context, and copies the `docker` and, if set, `kubernetes` endpoint configuration: |
Wondering though it the part about docker
and kubernetes
is a bit redundant (and if just mentioning that it's copied from the current context is sufficient?)
$ docker context create my-context | ||
``` | ||
|
||
You can select a different `context` to create from by using the `--from` option: |
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.
You can select a different `context` to create from by using the `--from` option: | |
Use the `--from=<context name>` option to create a new context from an | |
existing context. The example below creates a new context named | |
`my-context` from the existing `existing-context` context. |
That feels like a band-aid solution; can we include an actual context in the UCP bundle, so that we can |
@thaJeztah we will in the next release. But users that don't upgrade their clusters - and whose bundles don't have the dockercontext file in it - should have something better that what we have now. |
Well, if they don't update they would still use an old client 😉, but I get the idea; as long as we make sure to document the |
Also wondering if we can backport the "include context in UCP bundle" to older UCP releases (as part of a patch release) |
Not likely because of golang vendoring hell (vendoring a new CLI requires vendoring a new docker engine... which is not possible for patch releases in UCP - except bumping a patch release of the currently supported engine) |
cbe62a9
to
1e0dce0
Compare
--from creates a context from a named context. By default `context create` will create a context from the current context. Replaced "from-current=" docker/kubernetes option with "from=" to allow specifying which context to copy the settings from. Signed-off-by: Nick Adcock <nick.adcock@docker.com>
1e0dce0
to
8bb152d
Compare
@@ -23,7 +23,7 @@ Create a context | |||
Docker endpoint config: | |||
|
|||
NAME DESCRIPTION | |||
from-current Copy current Docker endpoint configuration | |||
from Copy Docker endpoint configuration from an existing 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.
Do we still want the from
for docker
and kubernetes
, now that we have the top-level --from
? Basically; wondering if we want context create
and context update
to allow mish-mashing two unrelated contexts.
I can slightly see this being something when creating a new context, but not entirely sure for updating an existing one.
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 it is not about "usefulness" but more about symetry: endpoint configuration options would be easier to learn if they are the same for both create and update.
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
/cc @nigelpoulton |
oh, and /cc @albers (for completion scripts; forgot that those might need updating) |
- What I did
Added
--from
option tocontext create
command that simplifies creation of a context from a namedor the current context.
If
--from
is set then the context will be created using the existing context with the provided name. If--from
,--docker
, and--kubernetes
is not set then the context will be created using the current context.- How I did it
Uses the context store to export the current context, then updates the details (description and orchestrator), and uses the context store to import the new context.
- How to verify it
Tests have been added to check the new functionality and ensure the user cannot use the
--from-current
flag with other docker/kubernetes settings