diff --git a/cmd/preflight/cli/run.go b/cmd/preflight/cli/run.go index f34f7852..822890d6 100644 --- a/cmd/preflight/cli/run.go +++ b/cmd/preflight/cli/run.go @@ -133,15 +133,21 @@ func runPreflights(v *viper.Viper, arg string) error { if v.GetString("since") != "" { progressChan <- errors.Errorf("Only one of since-time / since may be used. The flag since-time will be used.") } - for _, collectors := range preflightSpec.Spec.Collectors { - if collectors.Logs != nil { - collectors.Logs.Limits.SinceTime = v.GetString("since-time") + for _, collector := range preflightSpec.Spec.Collectors { + if collector.Logs != nil { + if collector.Logs.Limits == nil { + collector.Logs.Limits = new(troubleshootv1beta2.LogLimits) + } + collector.Logs.Limits.SinceTime = v.GetString("since-time") } } } else if v.GetString("since") != "" { - for _, collectors := range preflightSpec.Spec.Collectors { - if collectors.Logs != nil { - collectors.Logs.Limits.Since = v.GetString("since") + for _, collector := range preflightSpec.Spec.Collectors { + if collector.Logs != nil { + if collector.Logs.Limits == nil { + collector.Logs.Limits = new(troubleshootv1beta2.LogLimits) + } + collector.Logs.Limits.Since = v.GetString("since") } } } diff --git a/cmd/troubleshoot/cli/root.go b/cmd/troubleshoot/cli/root.go index 744ecabf..892d6ed0 100644 --- a/cmd/troubleshoot/cli/root.go +++ b/cmd/troubleshoot/cli/root.go @@ -40,7 +40,7 @@ from a server that can be used to assist when troubleshooting a Kubernetes clust cmd.Flags().Bool("redact", true, "enable/disable default redactions") cmd.Flags().Bool("collect-without-permissions", false, "always generate a support bundle, even if it some require additional permissions") cmd.Flags().String("since-time", "", "forces pods logs collectors to return logs after a specific date (RFC3339)") - cmd.Flags().String("since", "", "forces pod's logs collectors to return logs newer than a relative duration like 5s, 2m, or 3h.") + cmd.Flags().String("since", "", "forces pod's logs collectors to return logs newer than a relative duration like 5s, 2m, or 3h.") // hidden in favor of the `insecure-skip-tls-verify` flag cmd.Flags().Bool("allow-insecure-connections", false, "when set, do not verify TLS certs when retrieving spec and reporting results") diff --git a/cmd/troubleshoot/cli/run.go b/cmd/troubleshoot/cli/run.go index cff418d1..66d66d40 100644 --- a/cmd/troubleshoot/cli/run.go +++ b/cmd/troubleshoot/cli/run.go @@ -443,15 +443,21 @@ func runCollectors(v *viper.Viper, collectors []*troubleshootv1beta2.Collect, ad if v.GetString("since") != "" { progressChan <- errors.Errorf("Only one of since-time / since may be used. The flag since-time will be used.") } - for _, collectors := range cleanedCollectors { - if collectors.Collect.Logs != nil { - collectors.Collect.Logs.Limits.SinceTime = v.GetString("since-time") + for _, collector := range cleanedCollectors { + if collector.Collect.Logs != nil { + if collector.Collect.Logs.Limits == nil { + collector.Collect.Logs.Limits = new(troubleshootv1beta2.LogLimits) + } + collector.Collect.Logs.Limits.SinceTime = v.GetString("since-time") } } } else if v.GetString("since") != "" { - for _, collectors := range cleanedCollectors { - if collectors.Collect.Logs != nil { - collectors.Collect.Logs.Limits.Since = v.GetString("since") + for _, collector := range cleanedCollectors { + if collector.Collect.Logs != nil { + if collector.Collect.Logs.Limits == nil { + collector.Collect.Logs.Limits = new(troubleshootv1beta2.LogLimits) + } + collector.Collect.Logs.Limits.Since = v.GetString("since") } } } diff --git a/pkg/collect/logs.go b/pkg/collect/logs.go index 37fee774..885f3d90 100644 --- a/pkg/collect/logs.go +++ b/pkg/collect/logs.go @@ -117,16 +117,7 @@ func getPodLogs(ctx context.Context, client *kubernetes.Clientset, pod corev1.Po podLogOpts.TailLines = &limits.MaxLines } - if limits != nil && limits.SinceTime != "" { - t, err := time.Parse(time.RFC3339, limits.SinceTime) - if err != nil { - logger.Printf("unable to parse --since-time=%s\n", limits.SinceTime) - } - - sinceTime := metav1.NewTime(t) - podLogOpts.SinceTime = &sinceTime - - } else if limits != nil && (limits.MaxAge != "" || limits.Since != "") { + if limits != nil && (limits.MaxAge != "" || limits.Since != "") { if limits.Since != "" { limits.MaxAge = limits.Since } @@ -142,6 +133,17 @@ func getPodLogs(ctx context.Context, client *kubernetes.Clientset, pod corev1.Po } } + if limits != nil && limits.SinceTime != "" { + t, err := time.Parse(time.RFC3339, limits.SinceTime) + fmt.Println("time", t) + if err != nil { + logger.Printf("unable to parse --since-time=%s\n", limits.SinceTime) + } + + sinceTime := metav1.NewTime(t) + podLogOpts.SinceTime = &sinceTime + + } fileKey := fmt.Sprintf("%s/%s", name, pod.Name) if container != "" { fileKey = fmt.Sprintf("%s/%s/%s", name, pod.Name, container)