Fix closure var reference bug

pull/3479/head
Timofey Kirillov 8 years ago
parent 5f652cdbe5
commit 7d52779027

@ -98,11 +98,6 @@ func (pod *PodWatchMonitor) FollowContainerLogs(containerName string) error {
return err return err
} }
// var sinceTime *metav1.Time
// if v, found := pod.ProcessedContainerLogTimestamps[containerName]; found {
// sinceTime = &metav1.Time{v}
// }
req := client.Core(). req := client.Core().
Pods(pod.Namespace). Pods(pod.Namespace).
GetLogs(pod.ResourceName, &core.PodLogOptions{ GetLogs(pod.ResourceName, &core.PodLogOptions{
@ -151,57 +146,17 @@ func (pod *PodWatchMonitor) FollowContainerLogs(containerName string) error {
} }
return nil return nil
// buf := bytes.Buffer{}
// _, err = io.Copy(&buf, readCloser)
// lines := strings.Split(strings.TrimSuffix(buf.String(), "\n"), "\n")
// res := make([]LogLine, 0)
// for _, line := range lines {
// lineParts := strings.SplitN(line, " ", 2)
// if len(lineParts) == 2 {
// ll := LogLine{
// Timestamp: lineParts[0],
// Data: lineParts[1],
// }
// res = append(res, ll)
// pod.Kube.Log(">>> %s", ll)
// }
// }
// if len(res) > 0 {
// t, err := time.Parse(time.RFC3339, res[len(res)-1].Timestamp)
// if err != nil {
// return nil, err
// }
// pod.ProcessedContainerLogTimestamps[containerName] = t
// }
// logLines, err := pod.GetContainerLogs(containerName)
// if err != nil {
// return err
// }
// pod.PodLogChunk <- &PodLogChunk{
// PodName: pod.ResourceName,
// ContainerName: containerName,
// LogLines: logLines,
// }
// return res, nil
} }
func (pod *PodWatchMonitor) WatchContainerLogs(containerName string) error { func (pod *PodWatchMonitor) WatchContainerLogs(containerName string) error {
for { for {
for _, containerName := range pod.ContainersNames {
switch pod.ContainerMonitorStates[containerName] { switch pod.ContainerMonitorStates[containerName] {
case "Running", "Terminated": case "Running", "Terminated":
return pod.FollowContainerLogs(containerName) return pod.FollowContainerLogs(containerName)
case "Waiting": case "Waiting":
default: default:
} }
}
time.Sleep(time.Duration(200) * time.Millisecond) time.Sleep(time.Duration(200) * time.Millisecond)
} }
@ -209,7 +164,8 @@ func (pod *PodWatchMonitor) WatchContainerLogs(containerName string) error {
} }
func (pod *PodWatchMonitor) Watch() error { func (pod *PodWatchMonitor) Watch() error {
for _, containerName := range pod.ContainersNames { for i := range pod.ContainersNames {
containerName := pod.ContainersNames[i]
go func() { go func() {
err := pod.WatchContainerLogs(containerName) err := pod.WatchContainerLogs(containerName)
if err != nil { if err != nil {

Loading…
Cancel
Save