mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-04-15 07:16:34 +00:00
nil and error handling
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user