You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: podlogs.go
    path of file: ./repos/kubernetes/test/e2e/storage/podlogs
    
    the code of the file until where you have to start completion: /*
Copyright 2018 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package podlogs enables live capturing of all events and log
// messages for some or all pods in a namespace as they get generated.
// This helps debugging both a running test (wha
    
func WatchPods(ctx context.Context, cs clientset.Interface, ns string, to io.Writer, toCloser io.Closer) (finalErr error) {
	defer func() {
		if finalErr != nil && toCloser != nil {
			toCloser.Close()
		}
	}()

	pods, err := cs.CoreV1().Pods(ns).Watch(context.Background(), meta.ListOptions{})
	if err != nil {
		return fmt.Errorf("cannot create Pod watcher: %w", err)
	}
	defer func() {
		if finalErr != nil {
			pods.Stop()
		}
	}()

	events, err := cs.CoreV1().Events(ns).Watch(context.Background(), meta.ListOptions{})
	if err != nil {
		return fmt.Errorf("cannot create Event watcher: %w", err)
	}

	go func() {
		defer func() {
			pods.Stop()
			events.Stop()
			if toCloser != nil {
				toCloser.Close()
			}
		}()
		timeFormat := "15:04:05.000"
		for {
			select {
			case e := <-pods.ResultChan():
				if e.Object == nil {
					continue
				}

				pod, ok := e.Object.(*v1.Pod)
				if !ok {
					continue
				}
				buffer := new(bytes.Buffer)
				fmt.Fprintf(buffer,
					"%s pod: %s: %s/%s %s: %s %s\n",
					time.Now().Format(timeFormat),
					e.Type,
					pod.Namespace,
					pod.Name,
					pod.Status.Phase,
					pod.Status.Reason,
					pod.Status.Conditions,
				)
				for _, cst := range pod.Status.ContainerStatuses {
					fmt.Fprintf(buffer, "   %s: ", cst.Name)
					if cst.State.Waiting != nil {
						fmt.Fprintf(buffer, "WAITING: %s - %s",
							cst.State.Waiting.Reason,
							cst.State.Waiting.Message,
						)
					} else if cst.State.Running != nil {
						fmt.Fprintf(buffer, "RUNNING")
					} else if cst.State.Terminated != nil {
						fmt.Fprintf(buffer, "TERMINATED: %s - %s",
							cst.State.Terminated.Reason,
							cst.State.Terminated.Message,
						)
					}
					fmt.Fprintf(buffer, "\n")
				}
				to.Write(buffer.Bytes())
			case e := <-events.ResultChan():
				if e.Object == nil {
					continue
				}

				event, ok := e.Object.(*v1.Event)
				if !ok {
					continue
				}
				to.Write([]byte(fmt.Sprintf("%s event: %s/%s %s: %s %s: %s (%v - %v)\n",
					time.Now().Format(timeFormat),
					event.InvolvedObject.APIVersion,
					event.InvolvedObject.Kind,
					event.InvolvedObject.Name,
					event.Source.Component,
					event.Type,
					event.Message,
					event.FirstTimestamp,
					event.LastTimestamp,
				)))
			case <-ctx.Done():
				to.Write([]byte(fmt.Sprintf("%s ==== stopping pod watch ====\n",
					time.Now().Format(timeFormat))))
				return
			}
		}
	}()

	return nil
}