Skip to content

Commit

Permalink
Addressed some comments on PR/78
Browse files Browse the repository at this point in the history
  • Loading branch information
madmeignanam committed Sep 27, 2019
1 parent 33d62ef commit cb5cda2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion plugin/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* limitations under the License.
*/

//go:generate go-extpoints . ComposePlugin
//go:generate go-extpoints . ComposePlugin PodStatusHook
package plugin

import (
Expand Down
2 changes: 1 addition & 1 deletion pluginimpl/general/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (gp *generalExt) PreKillTask(taskInfo *mesos.TaskInfo) error {
func (gp *generalExt) PostKillTask(taskInfo *mesos.TaskInfo) error {
logger.Println("PostKillTask begin, pod status:", pod.GetPodStatus())
var err error
if !pod.LaunchCmdExecuted {
if !pod.LaunchCmdAttempted {
logger.Println("Pod hasn't started, no postKill work needed.")
return nil
}
Expand Down
26 changes: 17 additions & 9 deletions utils/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ var PluginOrder []string
var HealthCheckListId = make(map[string]bool)
var MonitorContainerList []string
var SinglePort bool
var LaunchCmdExecuted = false

// LaunchCmdAttempted indicates that an attempt to run the command to launch the pod (docker compose up with params) was
// made. This does not indicate that the result of the command execution.
var LaunchCmdAttempted = false

// taskStatusCh is pushed with the task status sent to Mesos, so any custom pod task status hooks can be executed
var taskStatusCh = make(chan string, 1)

// Check exit code of all the containers in the pod.
Expand Down Expand Up @@ -308,8 +313,8 @@ func LaunchPod(files []string) types.PodStatus {
go dockerLogToPodLogFile(files, true)

err = cmd.Run()
LaunchCmdExecuted = true
log.Println("Updated the state of LaunchCmdExecuted to true.")
LaunchCmdAttempted = true
log.Println("Updated the state of LaunchCmdAttempted to true.")
if err != nil {
log.Printf("POD_LAUNCH_FAIL -- Error running launch task command : %v", err)
return types.POD_FAILED
Expand Down Expand Up @@ -844,7 +849,7 @@ func SendPodStatus(status types.PodStatus) {
}
SendMesosStatus(ComposeExecutorDriver, ComposeTaskInfo.GetTaskId(), mesos.TaskState_TASK_FINISHED.Enum())
case types.POD_FAILED:
if LaunchCmdExecuted {
if LaunchCmdAttempted {
err := StopPod(ComposeFiles)
if err != nil {
logger.Errorf("Error cleaning up pod : %v\n", err.Error())
Expand Down Expand Up @@ -896,7 +901,9 @@ func SendMesosStatus(driver executor.ExecutorDriver, taskId *mesos.TaskID, state
}
}

time.Sleep(5 * time.Second) // FIXME: This wait time is unjustified, find reason and comment or remove it
// Per @kkrishna, This delay is historical, and to have mesos process the status sent above. task failed or finished
// would stop the driver prematurely
time.Sleep(5 * time.Second)

// Push the state to Task status channel so any further steps on a given task status can be executed
taskStatusCh <- state.Enum().String()
Expand All @@ -912,6 +919,7 @@ func WaitOnPod(ctx *context.Context) {
log.Println("POD_LAUNCH_TIMEOUT")
if dump, ok := config.GetConfig().GetStringMap("dockerdump")["enable"].(bool); ok && dump {
DockerDump()

}
SendPodStatus(types.POD_FAILED)
} else if (*ctx).Err() == context.Canceled {
Expand Down Expand Up @@ -1241,10 +1249,10 @@ func ListenOnTaskStatus(driver executor.ExecutorDriver, taskInfo *mesos.TaskInfo
}
case mesos.TaskState_TASK_FAILED.String():
/*
Tasks are marked as Failed at
1. Initial launch failure
2. Health Monitor or any plugin monitors and fails after the task has been running for
a longtime
Tasks are marked as Failed at,
1. Initial launch failure (PodStatus.Launched == false)
2. Health Monitor or any plugin monitors and fails after the task has been running for
a longtime (PodStatus.Launched = true, and marked as failed later)
*/
if err := execPodStatusHooks(status, *cachedTaskInfo); err != nil {
logger.Errorf("executing hooks failed %v ", err)
Expand Down

0 comments on commit cb5cda2

Please sign in to comment.