-
Notifications
You must be signed in to change notification settings - Fork 285
Add support for creating network namespaces inside cloned uvms. #837
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
Merged
ambarve
merged 3 commits into
user/ambarve/lcpr2_clone_uvm
from
user/ambarve/lcpr3_networking_changes
Jan 27, 2021
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/Microsoft/hcsshim/internal/clone" | ||
| "github.com/Microsoft/hcsshim/internal/uvm" | ||
| ) | ||
|
|
||
| // saveAsTemplate saves the UVM and container inside it as a template and also stores the | ||
| // relevant information in the registry so that clones can be created from this template. | ||
| // Every cloned uvm gets its own NIC and we do not want to create clones of a template | ||
| // which still has a NIC attached to it. So remove the NICs attached to the template uvm | ||
| // before saving it. | ||
| // Similar to the NIC scenario we do not want to create clones from a template with an | ||
| // active GCS connection so close the GCS connection too. | ||
| func saveAsTemplate(ctx context.Context, templateTask *hcsTask) (err error) { | ||
| var utc *uvm.UVMTemplateConfig | ||
| var templateConfig *clone.TemplateConfig | ||
|
|
||
| if err = templateTask.host.RemoveAllNICs(ctx); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err = templateTask.host.CloseGCSConnection(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| utc, err = templateTask.host.GenerateTemplateConfig() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| templateConfig = &clone.TemplateConfig{ | ||
| TemplateUVMID: utc.UVMID, | ||
| TemplateUVMResources: utc.Resources, | ||
| TemplateUVMCreateOpts: utc.CreateOpts, | ||
| TemplateContainerID: templateTask.id, | ||
| TemplateContainerSpec: *templateTask.taskSpec, | ||
| } | ||
|
|
||
| if err = clone.SaveTemplateConfig(ctx, templateConfig); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err = templateTask.host.SaveAsTemplate(ctx); err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/Microsoft/hcsshim/internal/cmd" | ||
| "github.com/Microsoft/hcsshim/internal/cow" | ||
| "github.com/Microsoft/hcsshim/internal/log" | ||
| "github.com/Microsoft/hcsshim/internal/uvm" | ||
| "github.com/opencontainers/runtime-spec/specs-go" | ||
| "github.com/sirupsen/logrus" | ||
| ) | ||
|
|
||
| func newClonedExec( | ||
| ctx context.Context, | ||
| events publisher, | ||
| tid string, | ||
| host *uvm.UtilityVM, | ||
| c cow.Container, | ||
| id, bundle string, | ||
| isWCOW bool, | ||
| spec *specs.Process, | ||
| io cmd.UpstreamIO) *clonedExec { | ||
| log.G(ctx).WithFields(logrus.Fields{ | ||
| "tid": tid, | ||
| "eid": id, // Init exec ID is always same as Task ID | ||
| "bundle": bundle, | ||
| }).Debug("newClonedExec") | ||
|
|
||
| he := &hcsExec{ | ||
| events: events, | ||
| tid: tid, | ||
| host: host, | ||
| c: c, | ||
| id: id, | ||
| bundle: bundle, | ||
| isWCOW: isWCOW, | ||
| spec: spec, | ||
| io: io, | ||
| processDone: make(chan struct{}), | ||
| state: shimExecStateCreated, | ||
| exitStatus: 255, // By design for non-exited process status. | ||
| exited: make(chan struct{}), | ||
| } | ||
|
|
||
| ce := &clonedExec{ | ||
| he, | ||
| } | ||
| go he.waitForContainerExit() | ||
| return ce | ||
| } | ||
|
|
||
| var _ = (shimExec)(&clonedExec{}) | ||
|
|
||
| // clonedExec inherits from hcsExec. The only difference between these two is that | ||
| // on starting a clonedExec it doesn't attempt to start the container even if the | ||
| // exec is the init process. This is because in case of clonedExec the container is | ||
| // already running inside the pod. | ||
| type clonedExec struct { | ||
| *hcsExec | ||
| } | ||
|
|
||
| func (ce *clonedExec) Start(ctx context.Context) (err error) { | ||
| // A cloned exec should never initialize the container as it should | ||
| // already be running. | ||
| return ce.startInternal(ctx, false) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.