Skip to content

Commit

Permalink
Merge pull request #15 from trivago/Improve-logging
Browse files Browse the repository at this point in the history
Improve logging on pot create fail and pot destroy failure
  • Loading branch information
ebarriosjr authored Jan 29, 2020
2 parents 31398b3 + 0fb844e commit 3a1be66
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
15 changes: 12 additions & 3 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,20 +384,29 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
if exists == 0 {
if err := se.createContainer(cfg); err != nil {
//Destroy container if err on creation
se.destroyContainer(cfg)
err := se.destroyContainer(cfg)
if err != nil {
d.logger.Error("Error destroying container with err: ", err)
}
return nil, nil, fmt.Errorf("unable to create container: %v", err)
}
d.logger.Trace("StartTask", "Created container, se:", se)

if err := se.startContainer(cfg); err != nil {
se.destroyContainer(cfg)
err := se.destroyContainer(cfg)
if err != nil {
d.logger.Error("Error destroying container with err: ", err)
}
return nil, nil, fmt.Errorf("unable to start container: %v", err)
}
d.logger.Trace("StartTask", "Started task, se", se)
} else {
d.logger.Trace("StartTask", "Container existed, se", se)
if err := se.startContainer(cfg); err != nil {
se.destroyContainer(cfg)
err := se.destroyContainer(cfg)
if err != nil {
d.logger.Error("Error destroying container with err: ", err)
}
return nil, nil, fmt.Errorf("unable to start container: %v", err)
}
}
Expand Down
6 changes: 3 additions & 3 deletions driver/pot.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (s *syexec) createContainer(commandCfg *drivers.TaskConfig) error {
_, err = exec.Command("sh", "-c", s.argvEnv).Output()
if err != nil {
message := "Error setting env variables for pot with err: " + err.Error()
s.logger.Error(message)
return errors.New(string(message))
}

// Set hosts file inside the pot
Expand All @@ -297,7 +297,7 @@ func (s *syexec) createContainer(commandCfg *drivers.TaskConfig) error {
_, err = exec.Command("sh", "-c", s.argvExtraHosts).Output()
if err != nil {
message := "Error setting hosts file for pot with err: " + err.Error()
s.logger.Error(message)
return errors.New(string(message))
}

//Set memory limit for pot
Expand All @@ -307,7 +307,7 @@ func (s *syexec) createContainer(commandCfg *drivers.TaskConfig) error {
_, err = exec.Command("sh", "-c", s.argvMem).Output()
if err != nil {
message := "Error setting memory limit for pot with err: " + err.Error()
s.logger.Error(message)
return errors.New(string(message))
}

return nil
Expand Down

0 comments on commit 3a1be66

Please sign in to comment.