-
Notifications
You must be signed in to change notification settings - Fork 2k
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
support CNI_ARGS parameters #16197
Comments
Related: #13520 |
#12120 (comment) shows an example of how EDIT: now that I've looked at the CNI library interface it looks like it accepts a |
is it possible to get at least, the |
I've done a bit of experimenting with this, and while I was hoping we could include interesting metadata like this across the board without caveat, some plugins reject unknown keys being passed in, e.g. with
Fairly sure that comes from here: This patch seems to be effective in my little experiment, with a custom plugin in a CNI config chain after --- a/client/allocrunner/networking_cni.go
+++ b/client/allocrunner/networking_cni.go
@@ -102,7 +102,19 @@ func (c *cniNetworkConfigurator) Setup(ctx context.Context, alloc *structs.Alloc
var res *cni.CNIResult
for attempt := 1; ; attempt++ {
var err error
- if res, err = c.cni.Setup(ctx, alloc.ID, spec.Path, cni.WithCapabilityPortMap(getPortMapping(alloc, c.ignorePortMappingHostIP))); err != nil {
+ if res, err = c.cni.Setup(ctx, alloc.ID, spec.Path,
+ cni.WithCapabilityPortMap(getPortMapping(alloc, c.ignorePortMappingHostIP)),
+ // "labels" get turned into CNI_ARGS env for CNI plugins to consume.
+ cni.WithLabels(map[string]string{
+ // some plugins (ex bridge) reject unknown fields by default,
+ // unless this is set.
+ "IgnoreUnknown": "true",
+ // nomad-specific info for plugins to use
+ "nomad_alloc_id": alloc.ID,
+ "nomad_namespace": alloc.Namespace,
+ }),
+ ); err != nil {
c.logger.Warn("failed to configure network", "error", err, "attempt", attempt)
switch attempt {
case 1: It produces this env var in the CNI plugin execution:
So that's promising, but I'm still somewhat reluctant to make this less-strict behavior the default... The potential usages do feel pretty compelling to me, though. It could obviate the need for intermediate Nomad->other CNI plugins to hit Nomad API themselves. Or even further downstream, programs that run out of band to reconcile Nomad alloc state with Cilium endpoints, for example. |
Would it make sense to extend the network {
mode = "cni/mynet"
cni {
K8S_POD_NAMESPACE = "${NOMAD_NAMESPACE}"
K8S_POD_NAME = "${NOMAD_TASK_NAME}"
}
} |
Yeah, I think that's roughly what we're looking at. I've got a branch that should be landing in the next little while that adds the plumbing for CNI args without exposing them to the user yet (to support #10628). And then we'll be able to come back and add a jobspec field pretty easily! |
This is done! It will be shipped in 1.8.2. |
Hi @tgross, I have a follow up question if you do not mind. What do you mean by:
in your initial post? As far as I understand this is exactly ment for the orchestrator/container runtime to pass in additional args -- mesos does this as well https://mesos.apache.org/documentation/latest/cni/#passing-network-labels-and-port-mapping-information-to-cni-plugi EDIT:// And since we are now setting nomad/client/allocrunner/networking_cni.go Line 128 in 682c8c0
EDIT2:// Or just like the transparent proxy does for the iptables stuff we could json serialize an object like:
Passing in via the json |
With the caveat that I'm trying to remember the intent of my unclear wording from over a year ago... 😀 When a job has something like Rather than doing that, we've just used the CNI library's
Are there existing third-party plugins that can react to this value? Or are you talking about custom plugins? I definitely like the idea of having some kind of "Nomad CNI protocol" of expected arguments, or the format of the JSON blob as you suggested (although I guess it could actually be shaped like anything). But we'd want that to be a stable interface for downstream plugin authors to rely on it. Can I get you to open a new issue to discuss that with any thoughts you have / context on how you might use it? There's a project going on exploring VM networking and I'd like to pull the folks looking at that into the conversation. |
Yeah I was thinking about doing that. Wasteful for sure, but compared to spawning a few process (bridge etc) probably not that bad.
Well, I'd argue it is an explicit contract and not an implementation detail. But okay, works well enough.
Currently not, there are CNI plugins reacting to
Will do. |
I'm going to lock this issue because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active issues. |
Some CNI plugins support accepting arguments in addition to the plugin config in JSON. (See https://www.cni.dev/docs/conventions/). They typically are passed in the
CNI_ARGS
environment variable, because passing them in the JSONargs
field would mean needing separate files for each argument variant. In Nomad (and k8s for that matter), the JSON config isn't typically accessible to job submitters.Some examples where this is useful:
static
plugin for static IP address assignment supports an address for the static IP and gateway, which are useful for cases where IPs are being assigned outside of Nomad.tc-redirect-tap
plugin (used for Firecracker VMs) supports arguments for per-VM jailer users/groups and tap names.The text was updated successfully, but these errors were encountered: