Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Don't Get Logs When Container Doesn't Exist Yet (#33)
Browse files Browse the repository at this point in the history
This fix is not urgent because by default all logs are disabled currently.

It appears one of two things is happening:

1. GetTaskStatus is being called prior to BuildResources
2. Containers cannot be immediately referenced following BuildResources

This is causing a panic due to an expected container not being found.
TESTS WERE BYPASSED
REVIEWS WERE BYPASSED
  • Loading branch information
matthewphsmith authored and lyft-buildnotify-4 committed Dec 29, 2018
1 parent 4471efd commit f3f0ec7
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions go/tasks/v1/k8splugins/logging_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,36 @@ var GetLogConfig = plugins.GetLogConfig

func GetLogsForContainerInPod(pod *v1.Pod, index uint32, nameSuffix string) ([]*core.TaskLog, error) {
var logs []*core.TaskLog
logConfig := GetLogConfig()

if logConfig.IsKubernetesEnabled {
k8sLog, err := logUtils.NewKubernetesLogPlugin(logConfig.KubernetesURL).GetTaskLog(
pod.Name,
pod.Namespace,
pod.Spec.Containers[index].Name,
pod.Status.ContainerStatuses[index].ContainerID,
"Kubernetes Logs"+nameSuffix)

if err != nil {
return nil, err
}
logs = append(logs, &k8sLog)
}

if logConfig.IsCloudwatchEnabled {
cwLogs, err := logUtils.NewCloudwatchLogPlugin(logConfig.AWSRegion).GetTaskLog(
pod.Name,
pod.Namespace,
pod.Spec.Containers[index].Name,
pod.Status.ContainerStatuses[index].ContainerID,
"Cloudwatch Logs"+nameSuffix)
if uint32(len(pod.Spec.Containers)) > index && uint32(len(pod.Status.ContainerStatuses)) > index {
logConfig := GetLogConfig()
if logConfig.IsKubernetesEnabled {
k8sLog, err := logUtils.NewKubernetesLogPlugin(logConfig.KubernetesURL).GetTaskLog(
pod.Name,
pod.Namespace,
pod.Spec.Containers[index].Name,
pod.Status.ContainerStatuses[index].ContainerID,
"Kubernetes Logs"+nameSuffix)

if err != nil {
return nil, err
}
logs = append(logs, &k8sLog)
}

if err != nil {
return nil, err
if logConfig.IsCloudwatchEnabled {
cwLogs, err := logUtils.NewCloudwatchLogPlugin(logConfig.AWSRegion).GetTaskLog(
pod.Name,
pod.Namespace,
pod.Spec.Containers[index].Name,
pod.Status.ContainerStatuses[index].ContainerID,
"Cloudwatch Logs"+nameSuffix)

if err != nil {
return nil, err
}
logs = append(logs, &cwLogs)
}
logs = append(logs, &cwLogs)
}

return logs, nil
Expand Down

0 comments on commit f3f0ec7

Please sign in to comment.