Skip to content

Commit

Permalink
Add since-second and since-time feature so that pod
Browse files Browse the repository at this point in the history
logs can be gathered at a particular time.
  • Loading branch information
crombus committed Mar 9, 2020
1 parent b3a52aa commit 10a8ff2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions contrib/completions/bash/oc
Expand Up @@ -2726,6 +2726,9 @@ _oc_adm_inspect()
flags+=("--dest-dir=")
two_word_flags+=("--dest-dir")
local_nonpersistent_flags+=("--dest-dir=")
flags+=("--sinceseconds=")
two_word_flags+=("--sinceseconds")
local_nonpersistent_flags+=("--sinceseconds=")
flags+=("--as=")
two_word_flags+=("--as")
flags+=("--as-group=")
Expand Down
3 changes: 3 additions & 0 deletions contrib/completions/zsh/oc
Expand Up @@ -2868,6 +2868,9 @@ _oc_adm_inspect()
flags+=("--dest-dir=")
two_word_flags+=("--dest-dir")
local_nonpersistent_flags+=("--dest-dir=")
flags+=("--sinceseconds=")
two_word_flags+=("--sinceseconds")
local_nonpersistent_flags+=("--sinceseconds=")
flags+=("--as=")
two_word_flags+=("--as")
flags+=("--as-group=")
Expand Down
4 changes: 4 additions & 0 deletions pkg/cli/admin/inspect/inspect.go
Expand Up @@ -61,8 +61,10 @@ type InspectOptions struct {

fileWriter *MultiSourceFileWriter
builder *resource.Builder
SinceTime *metav1.Time
args []string
namespace string
SinceSeconds int64
allNamespaces bool

// directory where all gathered data will be stored
Expand Down Expand Up @@ -100,6 +102,8 @@ func NewCmdInspect(streams genericclioptions.IOStreams, parentCommandPath string

cmd.Flags().StringVar(&o.destDir, "dest-dir", o.destDir, "Root directory used for storing all gathered cluster operator data. Defaults to $(PWD)/inspect.local.<rand>")
cmd.Flags().BoolVarP(&o.allNamespaces, "all-namespaces", "A", o.allNamespaces, "If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.")
cmd.Flags().Int64Var(&o.SinceSeconds, "sinceseconds", o.SinceSeconds, "An RFC3339 timestamp from which to show logs. If this value precedes the time a pod was started, only logs since the pod start will be returned.")
//cmd.Flags().DurationVar(&o.SinceTime, "sincetime", o.SinceTime, "Only return logs after a specific date (RFC3339). Defaults to all logs. Only one of sinceTime or sinceseconds may be used.")

o.configFlags.AddFlags(cmd.Flags())
return cmd
Expand Down
10 changes: 6 additions & 4 deletions pkg/cli/admin/inspect/pod.go
Expand Up @@ -285,10 +285,12 @@ func (o *InspectOptions) gatherContainerLogs(destDir string, pod *corev1.Pod, co

innerErrs := []error{}
logOptions := &corev1.PodLogOptions{
Container: container.Name,
Follow: false,
Previous: false,
Timestamps: true,
Container: container.Name,
Follow: false,
Previous: false,
Timestamps: true,
SinceSeconds: &o.SinceSeconds,
SinceTime: o.SinceTime,
}
filename := "current.log"
logsReq := o.kubeClient.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, logOptions)
Expand Down

0 comments on commit 10a8ff2

Please sign in to comment.