Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve log support #205

Merged
merged 2 commits into from
Nov 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/crictl/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ func ListContainers(client pb.RuntimeServiceClient, opts listOptions) error {
filter.PodSandboxId = opts.podID
}
st := &pb.ContainerStateValue{}
if !opts.all {
if !opts.all && opts.state == "" {
st.State = pb.ContainerState_CONTAINER_RUNNING
filter.State = st
}
Expand Down
38 changes: 37 additions & 1 deletion cmd/crictl/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import (
"os"
"time"

timetypes "github.com/docker/docker/api/types/time"
"github.com/urfave/cli"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/kubelet/kuberuntime/logs"
)

Expand All @@ -36,7 +38,7 @@ var logsCommand = cli.Command{
Usage: "Follow log output",
},
cli.Int64Flag{
Name: "tail, t",
Name: "tail",
Value: -1,
Usage: "Number of lines to show from the end of the logs. Defaults to all",
},
Expand All @@ -45,6 +47,15 @@ var logsCommand = cli.Command{
Value: -1,
Usage: "Maximum bytes of logs to return. Defaults to no limit",
},
cli.StringFlag{
Name: "since",
Value: "",
Usage: "Show logs since timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)",
},
cli.BoolFlag{
Name: "timestamps, t",
Usage: "Show timestamps",
},
},
Action: func(context *cli.Context) error {
runtimeService, err := getRuntimeService(context)
Expand All @@ -58,10 +69,17 @@ var logsCommand = cli.Command{
}
tailLines := context.Int64("tail")
limitBytes := context.Int64("limit-bytes")
since, err := parseTimestamp(context.String("since"))
if err != nil {
return err
}
timestamp := context.Bool("timestamps")
logOptions := logs.NewLogOptions(&v1.PodLogOptions{
Follow: context.Bool("follow"),
TailLines: &tailLines,
LimitBytes: &limitBytes,
SinceTime: since,
Timestamps: timestamp,
}, time.Now())
status, err := runtimeService.ContainerStatus(containerID)
if err != nil {
Expand All @@ -75,3 +93,21 @@ var logsCommand = cli.Command{
},
After: closeConnection,
}

// parseTimestamp parses timestamp string as golang duration,
// then RFC3339 time and finally as a Unix timestamp.
func parseTimestamp(value string) (*metav1.Time, error) {
if value == "" {
return nil, nil
}
str, err := timetypes.GetTimestamp(value, time.Now())
if err != nil {
return nil, err
}
s, ns, err := timetypes.ParseTimestamps(str, 0)
if err != nil {
return nil, err
}
t := metav1.NewTime(time.Unix(s, ns))
return &t, nil
}
2 changes: 1 addition & 1 deletion vendor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ github.com/juju/ratelimit 5b9ff866471762aa2ab2dced63c9fb6f53921342
github.com/mailru/easyjson d5b7844b561a7bc640052f1b935f7b800330d7e0
github.com/onsi/ginkgo 67b9df7f55fe1165fd9ad49aca7754cce01a42b8
github.com/onsi/gomega d59fa0ac68bb5dd932ee8d24eed631cdd519efc3
github.com/opencontainers/selinux b29023b86e4a69d1b46b7e7b4e2b6fda03f0b9cd
github.com/pborman/uuid ca53cad383cad2479bbba7f7a1a05797ec1386e4
github.com/peterbourgon/diskv 5f041e8faa004a95c88a202771f4cc3e991971e6
github.com/PuerkitoBio/purell v1.0.0
Expand All @@ -41,4 +42,3 @@ k8s.io/client-go 72e1c2a1ef30b3f8da039e92d4a6a1f079f374e8
k8s.io/kube-openapi 39a7bf85c140f972372c2a0d1ee40adbf0c8bfe1
k8s.io/kubernetes 164317879bcd810b97e5ebf1c8df041770f2ff1b
k8s.io/utils bf963466fd3fea33c428098b12a89d8ecd012f2
github.com/opencontainers/selinux b29023b86e4a69d1b46b7e7b4e2b6fda03f0b9cd
42 changes: 42 additions & 0 deletions vendor/github.com/docker/docker/api/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.