-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 a flag to configure docker network #277
Conversation
Welcome @foolusion! It looks like this is your first PR to kubernetes-sigs/kind 🎉 |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: foolusion If they are not already assigned, you can assign the PR to them by writing The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Hi @foolusion. Thanks for your PR. I'm waiting for a kubernetes-sigs or kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@foolusion: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
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.
thanks for this PR @foolusion
mostly LGTM, one major topic is evaluating that we want to pass the network flag transparently from the kind CLI to Docker.
/priority important-longterm
@@ -51,6 +52,7 @@ func NewCommand() *cobra.Command { | |||
}, | |||
} | |||
cmd.Flags().StringVar(&flags.Name, "name", cluster.DefaultName, "cluster context name") | |||
cmd.Flags().StringVar(&flags.Network, "network", "", "network to use for cluster") |
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.
could we use something more descriptive here, e.g. outlining that this network will be used for the containers.
e.g. container network to use for the cluster
- listing possible values?
also, what is the state of other container runtimes in terms of supporting such a flag; what are the alternatives in naming and values?
e.g. do CRI-O / containerd have a --network
where the Docker values such as "bridge" will make sense?
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 checked out a few of the other container runtimes.
rkt has a --net
flag that you can pass one or more networks I believe it uses CNI.
docker seems to also support the shorter --net
flag
CRI-O, containerd do not support networking directly, you must configure it through runc or CNI.
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.
thanks for checking.
CRI-O and containerd are the 2 more active CR after docker in the k8s space, while rkt is not used a lot.
) | ||
} | ||
if network != "" { | ||
extraArgs = append(extraArgs, "--network", network) |
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.
this binds a kind CLI flag to the underlying CR (docker).
i guess we need to evaluate if we want this coupling for the 1.0 release.
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.
yeah, i'm iffy on this. 🤔
I this probably does make sense as a flag, I guess, but as a rule of thumb we should prefer config... 🤔
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.
If it was in the config would it be at the top level?
Is there any setup where your nodes would be in different networks?
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.
sorry, time flew by so fast :(
i'm not sure.. I could see this (EDIT: this = per node network options) maybe, we could start top level and do an override.
Either way we're mostly decoupled from docker at the user interface right now, and I do intend to support podman etc., I meant to investigate further if there was a better way to specify this or any other work arounds.
I do see how this is a feature we need to enable.
pkg/cluster/internal/meta/meta.go
Outdated
return c.network | ||
} | ||
|
||
func (c *ClusterMeta) SetNetwork(network string) { |
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.
cluster meta is not supposed to be mutable.
I should really clean up how create works :|
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.
Ah, I didn't want to add anything to the NewClusterMeta
func yet since it would require more changes. I can add it as a variadic param to NewClusterMeta since network is not required and existing code doesn't break.
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.
er what I really meant by this, is that clusterMeta is a terrible name, this is really just the cluster key (name) and some utils right now, I suspect Create(...) is the right place to plumb this through.
moved the network config into the cluster.Context. When you use cluster.NewContext you can pass optional parameters like network. This is so we won't mutate the ClusterMeta struct. fixed doc and nit issues.
@foolusion: PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
type Option func(*contextConfig) | ||
|
||
// WithNetwork sets the container network to be used when creating a cluster. | ||
func WithNetwork(network string) func(*contextConfig) { |
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.
is there any reason this should be an option on context instead of Create()? do you forsee other calls needing this?
👍 for this pattern in general.
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 didn't know if anything else was calling Create so I didn't want to change the parameters. Either way works. I haven't dug into the code enough to see how/where it is used.
I think we should add this in the |
Would the only change be removing the flag and setting the value from the config or do you have a different idea? |
Out of scope for this PR but I wanted to mention it somewhere: for our use case being able to use |
I realized that I can just join the kind containers to a custom network after creation. For example |
Apologies -- I've been heads down on a big refactor (#360) of cluster creation to make extending this sort of thing easier hopefully... I hoped to get it in before too many PRs adding more to the existing cluster creation code piled up. (should be more or less going in now finally..) I think a field in config for runtime specific options makes sense, ideally we should continue to do this one step above flags so we at least leave eg the docker client library open as an option in the future: maybe: apiVersion: kind.sigs.k8s.io/v1alpha3
kind: Cluster
dockerOptions:
net: "foo"
... |
superseded by #484, it turns out there are some other issues with using a non-default docker network (the behavior changes on docker's end a bit and we need to work around it) thanks again for the PR, hopefully some variant of this feature will be in 0.4 |
* Change unbalance logic * Clean code * Clean code * Add validation * Fix validation --------- Co-authored-by: stg <[email protected]>
I've implemented a minimal solution for adding a docker network.
This adds a flag
--network
to the create cluster command.It will error if the network doesn't exist.
If the network flag is not passed it uses the default bridge network.
We can work from here on design and implementation.
resolves #273