@@ -43,10 +43,9 @@ const TimestampFormatShort = "01-02 15:04:05"
4343type Tail struct {
4444 clientset corev1client.CoreV1Interface
4545
46- NodeName string
47- Namespace string
48- PodName string
49- ContainerName string
46+ Pod * corev1.Pod
47+ ContainerName string
48+
5049 Options * TailOptions
5150 closed chan struct {}
5251 podColor * color.Color
@@ -67,14 +66,12 @@ type ResumeRequest struct {
6766}
6867
6968// NewTail returns a new tail for a Kubernetes container inside a pod
70- func NewTail (clientset corev1client.CoreV1Interface , nodeName , namespace , podName , containerName string , tmpl * template.Template , out , errOut io.Writer , options * TailOptions , diffContainer bool ) * Tail {
71- podColor , containerColor := determineColor (podName , containerName , diffContainer )
69+ func NewTail (clientset corev1client.CoreV1Interface , pod * corev1. Pod , containerName string , tmpl * template.Template , out , errOut io.Writer , options * TailOptions , diffContainer bool ) * Tail {
70+ podColor , containerColor := determineColor (pod . Name , containerName , diffContainer )
7271
7372 return & Tail {
7473 clientset : clientset ,
75- NodeName : nodeName ,
76- Namespace : namespace ,
77- PodName : podName ,
74+ Pod : pod ,
7875 ContainerName : containerName ,
7976 Options : options ,
8077 closed : make (chan struct {}),
@@ -111,7 +108,7 @@ func (t *Tail) Start(ctx context.Context) error {
111108
112109 t .printStarting ()
113110
114- req := t .clientset .Pods (t .Namespace ).GetLogs (t .PodName , & corev1.PodLogOptions {
111+ req := t .clientset .Pods (t .Pod . Namespace ).GetLogs (t .Pod . Name , & corev1.PodLogOptions {
115112 Follow : t .Options .Follow ,
116113 Timestamps : true ,
117114 Container : t .ContainerName ,
@@ -155,9 +152,9 @@ func (t *Tail) printStarting() {
155152 p := t .podColor .SprintFunc ()
156153 c := t .containerColor .SprintFunc ()
157154 if t .Options .Namespace {
158- fmt .Fprintf (t .errOut , "%s %s %s › %s\n " , g ("+" ), p (t .Namespace ), p (t .PodName ), c (t .ContainerName ))
155+ fmt .Fprintf (t .errOut , "%s %s %s › %s\n " , g ("+" ), p (t .Pod . Namespace ), p (t .Pod . Name ), c (t .ContainerName ))
159156 } else {
160- fmt .Fprintf (t .errOut , "%s %s › %s\n " , g ("+" ), p (t .PodName ), c (t .ContainerName ))
157+ fmt .Fprintf (t .errOut , "%s %s › %s\n " , g ("+" ), p (t .Pod . Name ), c (t .ContainerName ))
161158 }
162159 }
163160}
@@ -168,9 +165,9 @@ func (t *Tail) printStopping() {
168165 p := t .podColor .SprintFunc ()
169166 c := t .containerColor .SprintFunc ()
170167 if t .Options .Namespace {
171- fmt .Fprintf (t .errOut , "%s %s %s › %s\n " , r ("-" ), p (t .Namespace ), p (t .PodName ), c (t .ContainerName ))
168+ fmt .Fprintf (t .errOut , "%s %s %s › %s\n " , r ("-" ), p (t .Pod . Namespace ), p (t .Pod . Name ), c (t .ContainerName ))
172169 } else {
173- fmt .Fprintf (t .errOut , "%s %s › %s\n " , r ("-" ), p (t .PodName ), c (t .ContainerName ))
170+ fmt .Fprintf (t .errOut , "%s %s › %s\n " , r ("-" ), p (t .Pod . Name ), c (t .ContainerName ))
174171 }
175172 }
176173}
@@ -204,10 +201,12 @@ func (t *Tail) ConsumeRequest(ctx context.Context, request rest.ResponseWrapper)
204201func (t * Tail ) Print (msg string ) {
205202 vm := Log {
206203 Message : msg ,
207- NodeName : t .NodeName ,
208- Namespace : t .Namespace ,
209- PodName : t .PodName ,
204+ NodeName : t .Pod . Spec . NodeName ,
205+ Namespace : t .Pod . Namespace ,
206+ PodName : t .Pod . Name ,
210207 ContainerName : t .ContainerName ,
208+ Labels : t .Pod .Labels ,
209+ Annotations : t .Pod .Annotations ,
211210 PodColor : t .podColor ,
212211 ContainerColor : t .containerColor ,
213212 }
0 commit comments