Skip to content

Commit

Permalink
Merge pull request kata-containers#309 from bergwolf/agent_log
Browse files Browse the repository at this point in the history
agent: set sandbox id log field in CreateSandbox
  • Loading branch information
bergwolf authored Jul 31, 2018
2 parents c6ac153 + 745fa71 commit 061f7a6
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 @@ -90,6 +90,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 @@ -1166,14 +1165,19 @@ 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
a.sandbox.storages = make(map[string]*sandboxStorage)

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 @@ -1201,7 +1205,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 @@ -1240,6 +1244,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 061f7a6

Please sign in to comment.