Skip to content

Commit

Permalink
agent: set sandbox id log field in CreateSandbox
Browse files Browse the repository at this point in the history
This effectively reverts 04457e3("logging: Add sandbox field").
CreateSandbox() is the point we know which sandbox id will use
this guest. If we rely on the kernel command line for it, we have
to put sandbox id in qemu args and it breaks vm factory.

Fixes: kata-containers#308

Signed-off-by: Peng Tao <[email protected]>
  • Loading branch information
bergwolf committed Jul 27, 2018
1 parent 17b44df commit 745fa71
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 161 deletions.
1 change: 1 addition & 0 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type sandbox struct {
sync.RWMutex

id string
hostname string
containers map[string]*container
channel channel
network network
Expand Down
3 changes: 0 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const (
optionPrefix = "agent."
logLevelFlag = optionPrefix + "log"
devModeFlag = optionPrefix + "devmode"
sandboxFlag = optionPrefix + "sandbox"
kernelCmdlineFile = "/proc/cmdline"
)

Expand Down Expand Up @@ -95,8 +94,6 @@ func (c *agentConfig) parseCmdlineOption(option string) error {
if level == logrus.DebugLevel {
debug = true
}
case sandboxFlag:
agentLog = agentLog.WithField("sandbox", split[valuePosition])
default:
if strings.HasPrefix(split[optionPosition], optionPrefix) {
return grpcStatus.Errorf(codes.NotFound, "Unknown option %s", split[optionPosition])
Expand Down
11 changes: 8 additions & 3 deletions grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,6 @@ func (a *agentGRPC) SignalProcess(ctx context.Context, req *pb.SignalProcessRequ
if status == libcontainer.Stopped {
agentLog.WithFields(logrus.Fields{
"containerID": req.ContainerId,
"sandbox": a.sandbox.id,
"signal": signal.String(),
}).Info("discarding signal as container stopped")
return emptyResp, nil
Expand Down Expand Up @@ -1145,13 +1144,18 @@ func (a *agentGRPC) CreateSandbox(ctx context.Context, req *pb.CreateSandboxRequ
return emptyResp, grpcStatus.Error(codes.AlreadyExists, "Sandbox already started, impossible to start again")
}

a.sandbox.id = req.Hostname
a.sandbox.hostname = req.Hostname
a.sandbox.containers = make(map[string]*container)
a.sandbox.network.ifaces = make(map[string]*pb.Interface)
a.sandbox.network.dns = req.Dns
a.sandbox.running = true
a.sandbox.sandboxPidNs = req.SandboxPidns

if req.SandboxId != "" {
a.sandbox.id = req.SandboxId
agentLog = agentLog.WithField("sandbox", a.sandbox.id)
}

// Set up shared UTS and IPC namespaces
if err := a.sandbox.setupSharedNamespaces(); err != nil {
return emptyResp, err
Expand Down Expand Up @@ -1179,7 +1183,7 @@ func (a *agentGRPC) CreateSandbox(ctx context.Context, req *pb.CreateSandboxRequ

func (a *agentGRPC) DestroySandbox(ctx context.Context, req *pb.DestroySandboxRequest) (*gpb.Empty, error) {
if a.sandbox.running == false {
agentLog.WithField("sandbox", a.sandbox.id).Info("Sandbox not started, this is a no-op")
agentLog.Info("Sandbox not started, this is a no-op")
return emptyResp, nil
}

Expand Down Expand Up @@ -1209,6 +1213,7 @@ func (a *agentGRPC) DestroySandbox(ctx context.Context, req *pb.DestroySandboxRe
return emptyResp, err
}

a.sandbox.hostname = ""
a.sandbox.id = ""
a.sandbox.containers = make(map[string]*container)
a.sandbox.running = false
Expand Down
Loading

0 comments on commit 745fa71

Please sign in to comment.