-
Notifications
You must be signed in to change notification settings - Fork 259
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
Fix Network Namespace Bug For Ctr #1270
Conversation
If you try and run a hypervisor isolated container through ctr (.\ctr.exe run --runtime io.containerd.runhcs.v1 --rm --isolated mcr.microsoft.com/windows/nanoserver:1809 xenon-test cmd /c "echo Hello World!") currently you'll get "ctr: failure while creating namespace for container: network namespace not found: unknown". The normal path through ctr is no network namespace is passed, so our shim will try and make one. The namespace was being created via `hns.CreateNamespace` which stores the ID of the namespace in all caps, however later on in the process when we go to add the namespace to the uvm we re-grab a namespace object via `hcn.GetNamespaceByID` which populates the Id field in all lowercase. When we originally store the namespace in our map of known namespaces we use the hns packages casing, and when we go to add any endpoints to the vm (there shouldn't be any anyways if we went through ctr and didn't provide --cni) then we'll fail to find the namespace due to a casing mismatch. We already create the namespace for cri interactions with the hcn package so this truthfully brings this fallback path in line. Signed-off-by: Daniel Canter <dcanter@microsoft.com>
Did some RNG to assign two people and it landed on you @helsaawy @katiewasnothere 😆 |
It seems righteous to move from |
@kevpar I'd thought of this also but thought that might be a longer discussion for removing this path altogether. It seems like the path exists if the client decides to allocate their own endpoints and place them in https://github.com/opencontainers/runtime-spec/blob/8958f93039ab90be53d803cd7e231a775f644451/specs-go/config.go#L548, which we don't use that field anywhere else in this project besides for this fallback path.
Right, if nothings in the |
@kevpar Just skipping networking completely turns out fine which isn't too much of a surprise. Would you prefer we swap to this approach and get rid of the code that makes a netns for the fallback path as well? package hcsoci
@@ -216,14 +217,12 @@ func initializeCreateOptions(ctx context.Context, createOptions *CreateOptions)
// configureSandboxNetwork creates a new network namespace for the pod (sandbox)
// if required and then adds that namespace to the pod.
func configureSandboxNetwork(ctx context.Context, coi *createOptionsInternal, r *resources.Resources, ct oci.KubernetesContainerType) error {
- if coi.NetworkNamespace != "" {
- r.SetNetNS(coi.NetworkNamespace)
- } else {
- err := createNetworkNamespace(ctx, coi, r)
- if err != nil {
- return err
- }
+ if coi.NetworkNamespace == "" {
+ // Nothing for us to do as the caller didn't supply a network namespace, the container(s) will not have a network adapter unless
+ // added through external means.
+ return nil
}
+ r.SetNetNS(coi.NetworkNamespace) |
Ideally I'd want to get this into the new hcsshim tag I was planning so folks can actually launch hyper-v containers through ctr when Containerd 1.6 comes out. @helsaawy @kevpar Let me know what makes the most sense to y'all. To me it's probably easier to reason with there being no fallback "make a net namespace for them" route like we have currently. |
Sorry, not completely following. Sounds like you're trying to pick between two options. Can you define what option A and B are, and what pros and cons they have? What do you think is the right path forward? |
@kevpar Yep. The gist of the problem is by default no namespace (networking in general really) is setup through ctr so we end up taking a slightly different code path than you normally would through a cri interaction. The reason this is a problem currently is stated in the pr/commit description so I won't rehash there, but the two options are as follows: Option A Pros:
Cons:
Option B Pros:
Cons:
|
@dcantah I prefer option A personally unless there's some actual need for the fallback case. |
@katiewasnothere Agreed, only bit is if by some small chance someone was relying on this behavior. It's been here since 2018 5ab7622#diff-f2f83f5f5b4ef2d52a5b06695dc8393c3e26aae86610c4c50d1fa93809c20d5dR8 |
@helsaawy What do you think about the above? #1270 (comment) |
I prefer option B: |
@helsaawy I mean I'm fine with sticking with the fix in this PR currently (option B). If anything we can get this in, backport to the release/0.9 branch, and then do option A and have it be the 0.10 way of doing things. Hard to reason with changes like this and versioning when we don't follow semver to a t |
Talked internally. Our plan will be to go with the fix in this PR (Option B) for now, backport the fix to release/0.9 and get out a new 0.9.x tag, and then get rid of this fallback path for the 0.10.x line going forward. |
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
If you try and run a hypervisor isolated container through ctr (.\ctr.exe run --runtime io.containerd.runhcs.v1 --rm --isolated mcr.microsoft.com/windows/nanoserver:1809 xenon-test cmd /c "echo Hello World!") currently you'll get "ctr: failure while creating namespace for container: network namespace not found: unknown". The normal path through ctr is no network namespace is passed, so our shim will try and make one. The namespace was being created via `hns.CreateNamespace` which stores the ID of the namespace in all caps, however later on in the process when we go to add the namespace to the uvm we re-grab a namespace object via `hcn.GetNamespaceByID` which populates the Id field in all lowercase. When we originally store the namespace in our map of known namespaces we use the hns packages casing, and when we go to add any endpoints to the vm (there shouldn't be any anyways if we went through ctr and didn't provide --cni) then we'll fail to find the namespace due to a casing mismatch. We already create the namespace for cri interactions with the hcn package so this truthfully brings this fallback path in line. Signed-off-by: Daniel Canter <dcanter@microsoft.com>
If you try and run a hypervisor isolated container through ctr (
.\ctr.exe run --runtime io.containerd.runhcs.v1 --rm --isolated mcr.microsoft.com/windows/nanoserver:1809 hyp-test cmd /c "echo Hello World!"
) currently you'll get "ctr: failure while creating namespace for container: network namespace not found: unknown". The normal path through ctr is no network namespace is passed, so our shim will try and make one. The namespace was being created viahns.CreateNamespace
which stores the ID of the namespace in all caps, however later on in the process when we go to add the namespace to the uvm we re-grab a namespace object viahcn.GetNamespaceByID
which populates the Id field in all lowercase.When we originally store the namespace in our map of known namespaces we use the hns packages casing, and when we go to add any endpoints to the vm then we'll fail to find the namespace due to the casing mismatch. We already create the namespace for cri interactions with the hcn package so this truthfully brings this fallback path in line.