Skip to content

Commit

Permalink
Add runtime handler support.
Browse files Browse the repository at this point in the history
Signed-off-by: Lantao Liu <lantaol@google.com>
  • Loading branch information
Random-Liu committed Sep 17, 2018
1 parent a60705d commit 49a5dad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
19 changes: 10 additions & 9 deletions cmd/crictl/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package main

import (
"context"
"fmt"
"os"
"time"
Expand Down Expand Up @@ -59,25 +60,25 @@ var logsCommand = cli.Command{
Usage: "Show timestamps",
},
},
Action: func(context *cli.Context) error {
runtimeService, err := getRuntimeService(context)
Action: func(ctx *cli.Context) error {
runtimeService, err := getRuntimeService(ctx)
if err != nil {
return err
}

containerID := context.Args().First()
containerID := ctx.Args().First()
if containerID == "" {
return fmt.Errorf("ID cannot be empty")
}
tailLines := context.Int64("tail")
limitBytes := context.Int64("limit-bytes")
since, err := parseTimestamp(context.String("since"))
tailLines := ctx.Int64("tail")
limitBytes := ctx.Int64("limit-bytes")
since, err := parseTimestamp(ctx.String("since"))
if err != nil {
return err
}
timestamp := context.Bool("timestamps")
timestamp := ctx.Bool("timestamps")
logOptions := logs.NewLogOptions(&v1.PodLogOptions{
Follow: context.Bool("follow"),
Follow: ctx.Bool("follow"),
TailLines: &tailLines,
LimitBytes: &limitBytes,
SinceTime: since,
Expand All @@ -91,7 +92,7 @@ var logsCommand = cli.Command{
if logPath == "" {
return fmt.Errorf("The container has not set log path")
}
return logs.ReadLogs(logPath, status.GetId(), logOptions, runtimeService, os.Stdout, os.Stderr)
return logs.ReadLogs(context.Background(), logPath, status.GetId(), logOptions, runtimeService, os.Stdout, os.Stderr)
},
After: closeConnection,
}
Expand Down
16 changes: 13 additions & 3 deletions cmd/crictl/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ var runPodCommand = cli.Command{
Name: "runp",
Usage: "Run a new pod",
ArgsUsage: "pod-config.[json|yaml]",
Flags: []cli.Flag{
cli.StringFlag{
Name: "runtime, r",
Usage: "Runtime handler to use. Available options are defined by the container runtime.",
},
},

Action: func(context *cli.Context) error {
sandboxSpec := context.Args().First()
if sandboxSpec == "" {
Expand All @@ -63,7 +70,7 @@ var runPodCommand = cli.Command{
}

// Test RuntimeServiceClient.RunPodSandbox
err = RunPodSandbox(runtimeClient, podSandboxConfig)
err = RunPodSandbox(runtimeClient, podSandboxConfig, context.String("runtime"))
if err != nil {
return fmt.Errorf("run pod sandbox failed: %v", err)
}
Expand Down Expand Up @@ -236,8 +243,11 @@ var listPodCommand = cli.Command{

// RunPodSandbox sends a RunPodSandboxRequest to the server, and parses
// the returned RunPodSandboxResponse.
func RunPodSandbox(client pb.RuntimeServiceClient, config *pb.PodSandboxConfig) error {
request := &pb.RunPodSandboxRequest{Config: config}
func RunPodSandbox(client pb.RuntimeServiceClient, config *pb.PodSandboxConfig, runtime string) error {
request := &pb.RunPodSandboxRequest{
Config: config,
RuntimeHandler: runtime,
}
logrus.Debugf("RunPodSandboxRequest: %v", request)
r, err := client.RunPodSandbox(context.Background(), request)
logrus.Debugf("RunPodSandboxResponse: %v", r)
Expand Down
2 changes: 1 addition & 1 deletion pkg/validate/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"strings"
"time"

"github.com/docker/docker/pkg/jsonlog"
"github.com/docker/docker/daemon/logger/jsonfilelog/jsonlog"
"github.com/kubernetes-sigs/cri-tools/pkg/framework"
internalapi "k8s.io/kubernetes/pkg/kubelet/apis/cri"
runtimeapi "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
Expand Down

0 comments on commit 49a5dad

Please sign in to comment.