Skip to content
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

fix: incorrect task status update by deployer #429

Merged
merged 1 commit into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/deployer/app/deployer/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type TaskHealthDetails struct {
Status v1.PodStatus `json:"status"`
JobName string `json:"job_name"`
CreationTime time.Time `json:"creation_time"`
UnknownCount int
}

type K8sDeployer struct {
Expand Down Expand Up @@ -178,6 +179,7 @@ func (deployer *K8sDeployer) GetMonitoredPodStatuses() (map[string]TaskHealthDet
return nil, err
} else if len(out.Items) == 0 {
pod.Status = v1.PodStatus{Phase: v1.PodUnknown}
pod.UnknownCount++
} else {
if len(out.Items) > 1 {
sort.Slice(out.Items, func(i, j int) bool {
Expand All @@ -196,8 +198,12 @@ func (deployer *K8sDeployer) GetMonitoredPodStatuses() (map[string]TaskHealthDet

if lastPod.Status.Phase == v1.PodPending || lastPod.Status.Phase == v1.PodRunning {
pod.Status = lastPod.Status
// reset unknown count
pod.UnknownCount = 0
} else if lastPod.Status.Phase == v1.PodSucceeded {
deployer.DeleteTaskFromMonitoring(pod.TaskID)
} else if lastPod.Status.Phase == v1.PodUnknown {
pod.UnknownCount++
} else {
pod.Status = lastPod.Status
}
Expand All @@ -206,6 +212,7 @@ func (deployer *K8sDeployer) GetMonitoredPodStatuses() (map[string]TaskHealthDet

// update the pod status
deployer.DeployedTasks[pod.TaskID] = pod
zap.S().Infof("Pod status of task %s = %s", pod.TaskID, pod.Status.Phase)
}

return deployer.DeployedTasks, nil
Expand Down
14 changes: 11 additions & 3 deletions cmd/deployer/app/monitor_jobs.go → cmd/deployer/app/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ import (
"github.com/cisco-open/flame/pkg/restapi"
)

const (
tolerateCount = 5
monitorFrequency = time.Minute
)

func (r *resourceHandler) monitorPods() {
if err := r.dplyr.Initialize("", r.namespace); err != nil {
zap.S().Errorf("failed to initialize a job deployer: %v", err)
Expand All @@ -40,7 +45,10 @@ func (r *resourceHandler) monitorPods() {
} else if len(taskHealthDetails) > 0 {
for _, pod := range taskHealthDetails {
if pod.Status.Phase == v1.PodPending ||
pod.Status.Phase == v1.PodRunning {
pod.Status.Phase == v1.PodRunning ||
pod.UnknownCount <= tolerateCount {
// we will tolerate up to "tolerateCount" number of unknown phases
// The total time to tolerate is "monitorFrequency" * "tolerateCount"
continue
}

Expand All @@ -56,12 +64,12 @@ func (r *resourceHandler) monitorPods() {
}

r.dplyr.DeleteTaskFromMonitoring(pod.TaskID)
zap.S().Info("task %s failed; pod status: %s", pod.TaskID, pod.Status.Phase)
zap.S().Infof("task %s failed; pod status: %s", pod.TaskID, pod.Status.Phase)
}
}

// wait for some time before checking the status of pods again
time.Sleep(time.Minute)
time.Sleep(monitorFrequency)
}
}

Expand Down
4 changes: 4 additions & 0 deletions cmd/deployer/app/resource_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ func (r *resourceHandler) revokeResource(jobId string) (err error) {
continue
}
taskStatuses[taskId] = openapi.AGENT_REVOKE_SUCCESS

// stop monitoring of task
r.dplyr.DeleteTaskFromMonitoring(taskId)

// 2.delete all the task resource specification files
deploymentChartPath := filepath.Join(r.deploymentDirPath, jobId, taskId)
removeErr := os.RemoveAll(deploymentChartPath)
Expand Down