@@ -35,6 +35,7 @@ import (
35
35
"k8s.io/api/core/v1"
36
36
internalapi "k8s.io/cri-api/pkg/apis"
37
37
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
38
+ "k8s.io/kubernetes/pkg/kubelet/types"
38
39
"k8s.io/kubernetes/pkg/util/tail"
39
40
)
40
41
@@ -47,8 +48,10 @@ import (
47
48
// TODO(random-liu): Support log rotation.
48
49
49
50
const (
50
- // timeFormat is the time format used in the log.
51
- timeFormat = time .RFC3339Nano
51
+ // timeFormatOut is the format for writing timestamps to output.
52
+ timeFormatOut = types .RFC3339NanoFixed
53
+ // timeFormatIn is the format for parsing timestamps from other logs.
54
+ timeFormatIn = types .RFC3339NanoLenient
52
55
53
56
// logForceCheckPeriod is the period to check for a new read
54
57
logForceCheckPeriod = 1 * time .Second
@@ -128,9 +131,9 @@ func parseCRILog(log []byte, msg *logMessage) error {
128
131
if idx < 0 {
129
132
return fmt .Errorf ("timestamp is not found" )
130
133
}
131
- msg .timestamp , err = time .Parse (timeFormat , string (log [:idx ]))
134
+ msg .timestamp , err = time .Parse (timeFormatIn , string (log [:idx ]))
132
135
if err != nil {
133
- return fmt .Errorf ("unexpected timestamp format %q: %v" , timeFormat , err )
136
+ return fmt .Errorf ("unexpected timestamp format %q: %v" , timeFormatIn , err )
134
137
}
135
138
136
139
// Parse stream type
@@ -238,7 +241,7 @@ func (w *logWriter) write(msg *logMessage) error {
238
241
}
239
242
line := msg .log
240
243
if w .opts .timestamp {
241
- prefix := append ([]byte (msg .timestamp .Format (timeFormat )), delimiter [0 ])
244
+ prefix := append ([]byte (msg .timestamp .Format (timeFormatOut )), delimiter [0 ])
242
245
line = append (prefix , line ... )
243
246
}
244
247
// If the line is longer than the remaining bytes, cut it.
0 commit comments