Skip to content
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

Closed

Conversation

foolusion
Copy link

@foolusion foolusion commented Feb 6, 2019

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

@k8s-ci-robot
Copy link
Contributor

Welcome @foolusion! It looks like this is your first PR to kubernetes-sigs/kind 🎉

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 6, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: foolusion
To fully approve this pull request, please assign additional approvers.
We suggest the following additional approver: bentheelder

If they are not already assigned, you can assign the PR to them by writing /assign @bentheelder in a comment when ready.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Feb 6, 2019
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 6, 2019
@k8s-ci-robot
Copy link
Contributor

@foolusion: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

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.

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.

Copy link
Member

@neolit123 neolit123 left a 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

pkg/cluster/internal/meta/meta.go Show resolved Hide resolved
@@ -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")
Copy link
Member

@neolit123 neolit123 Feb 6, 2019

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?

Copy link
Author

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.

Copy link
Member

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)
Copy link
Member

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.

Copy link
Member

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... 🤔

Copy link
Author

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?

Copy link
Member

@BenTheElder BenTheElder Feb 22, 2019

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/nodes/create.go Outdated Show resolved Hide resolved
pkg/cluster/nodes/create.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added the priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. label Feb 6, 2019
return c.network
}

func (c *ClusterMeta) SetNetwork(network string) {
Copy link
Member

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 :|

Copy link
Author

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.

Copy link
Member

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.
@k8s-ci-robot
Copy link
Contributor

@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.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 21, 2019
type Option func(*contextConfig)

// WithNetwork sets the container network to be used when creating a cluster.
func WithNetwork(network string) func(*contextConfig) {
Copy link
Member

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.

Copy link
Author

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.

@BenTheElder
Copy link
Member

I think we should add this in the network struct proposed in #340 instead.

@foolusion
Copy link
Author

I think we should add this in the network struct proposed in #340 instead.

Would the only change be removing the flag and setting the value from the config or do you have a different idea?

@DazWorrall
Copy link

Out of scope for this PR but I wanted to mention it somewhere: for our use case being able to use --net-alias is also important, so somewhere to hang container-runtime specific configuration would be really useful.

@foolusion
Copy link
Author

I realized that I can just join the kind containers to a custom network after creation. For example docker network connect my-custom-network kind-control-plane Maybe that makes this PR less useful. Wondering what your thoughts are @BenTheElder @neolit123

@BenTheElder
Copy link
Member

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"
   ...

@BenTheElder
Copy link
Member

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

stg-0 added a commit to stg-0/kind that referenced this pull request Sep 11, 2023
* Change unbalance logic

* Clean code

* Clean code

* Add validation

* Fix validation

---------

Co-authored-by: stg <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow configurable docker network for kind cluster nodes
5 participants