@@ -110,27 +110,7 @@ func getPodLogs(ctx context.Context, client *kubernetes.Clientset, pod corev1.Po
110110 Container : container ,
111111 }
112112
113- defaultMaxLines := int64 (10000 )
114- if limits == nil || limits .MaxLines == 0 {
115- podLogOpts .TailLines = & defaultMaxLines
116- } else {
117- podLogOpts .TailLines = & limits .MaxLines
118- }
119- if limits != nil && ! limits .SinceTime .IsZero () {
120- podLogOpts .SinceTime = & limits .SinceTime
121-
122- } else if limits != nil && limits .MaxAge != "" {
123- parsedDuration , err := time .ParseDuration (limits .MaxAge )
124- if err != nil {
125- logger .Printf ("unable to parse time duration %s\n " , limits .MaxAge )
126- } else {
127- now := time .Now ()
128- then := now .Add (0 - parsedDuration )
129- kthen := metav1 .NewTime (then )
130-
131- podLogOpts .SinceTime = & kthen
132- }
133- }
113+ setLogLimits (& podLogOpts , limits , convertMaxAgeToTime )
134114
135115 fileKey := fmt .Sprintf ("%s/%s" , name , pod .Name )
136116 if container != "" {
@@ -172,6 +152,48 @@ func getPodLogs(ctx context.Context, client *kubernetes.Clientset, pod corev1.Po
172152 return result , nil
173153}
174154
155+ func convertMaxAgeToTime (maxAge string ) * metav1.Time {
156+ parsedDuration , err := time .ParseDuration (maxAge )
157+ if err != nil {
158+ logger .Printf ("unable to parse time duration %s\n " , maxAge )
159+ return nil
160+ }
161+
162+ now := time .Now ()
163+ then := now .Add (0 - parsedDuration )
164+ kthen := metav1 .NewTime (then )
165+
166+ return & kthen
167+ }
168+
169+ func setLogLimits (podLogOpts * corev1.PodLogOptions , limits * troubleshootv1beta2.LogLimits , maxAgeParser func (maxAge string ) * metav1.Time ) {
170+ if podLogOpts == nil {
171+ return
172+ }
173+
174+ defaultMaxLines := int64 (10000 )
175+ if limits == nil {
176+ podLogOpts .TailLines = & defaultMaxLines
177+ return
178+ }
179+
180+ if ! limits .SinceTime .IsZero () {
181+ podLogOpts .SinceTime = & limits .SinceTime
182+ return
183+ }
184+
185+ if limits .MaxAge != "" {
186+ podLogOpts .SinceTime = maxAgeParser (limits .MaxAge )
187+ return
188+ }
189+
190+ if limits .MaxLines == 0 {
191+ podLogOpts .TailLines = & defaultMaxLines
192+ } else {
193+ podLogOpts .TailLines = & limits .MaxLines
194+ }
195+ }
196+
175197func getLogsErrorsFileName (logsCollector * troubleshootv1beta2.Logs ) string {
176198 if len (logsCollector .Name ) > 0 {
177199 return fmt .Sprintf ("%s/errors.json" , logsCollector .Name )
0 commit comments