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

Create sandbox and container from yaml #124

Merged
merged 2 commits into from
Aug 24, 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 @@ -43,7 +43,7 @@ type createOptions struct {
var createContainerCommand = cli.Command{
Name: "create",
Usage: "Create a new container",
ArgsUsage: "SANDBOX container-config.json sandbox-config.json",
ArgsUsage: "SANDBOX container-config.[json|yaml] sandbox-config.[json|yaml]",
Flags: []cli.Flag{},
Action: func(context *cli.Context) error {
if len(context.Args()) != 3 {
Expand Down
30 changes: 15 additions & 15 deletions cmd/crictl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,27 @@ func main() {
app.Version = "0.1.0"

app.Commands = []cli.Command{
runtimeAttachCommand,
createContainerCommand,
runtimeExecCommand,
runtimeVersionCommand,
listImageCommand,
containerStatusCommand,
imageStatusCommand,
podSandboxStatusCommand,
logsCommand,
runtimePortForwardCommand,
listContainersCommand,
pullImageCommand,
runPodSandboxCommand,
stopPodSandboxCommand,
removeContainerCommand,
removeImageCommand,
removePodSandboxCommand,
podSandboxStatusCommand,
listPodSandboxCommand,
createContainerCommand,
startContainerCommand,
stopContainerCommand,
removeContainerCommand,
containerStatusCommand,
listContainersCommand,
runtimeStatusCommand,
runtimeAttachCommand,
pullImageCommand,
listImageCommand,
imageStatusCommand,
removeImageCommand,
runtimeExecCommand,
runtimePortForwardCommand,
logsCommand,
stopContainerCommand,
stopPodSandboxCommand,
}

app.Flags = []cli.Flag{
Expand Down
2 changes: 1 addition & 1 deletion cmd/crictl/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
var runPodSandboxCommand = cli.Command{
Name: "runs",
Usage: "Run a new sandbox",
ArgsUsage: "sandbox-config.json",
ArgsUsage: "sandbox-config.[json|yaml]",
Action: func(context *cli.Context) error {
sandboxSpec := context.Args().First()
if sandboxSpec == "" {
Expand Down
6 changes: 4 additions & 2 deletions cmd/crictl/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/ghodss/yaml"
"github.com/urfave/cli"
"google.golang.org/grpc"
utilyaml "k8s.io/apimachinery/pkg/util/yaml"
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
)

Expand Down Expand Up @@ -86,6 +87,7 @@ func getSortedKeys(m map[string]string) []string {

return keys
}

func loadContainerConfig(path string) (*pb.ContainerConfig, error) {
f, err := openFile(path)
if err != nil {
Expand All @@ -94,7 +96,7 @@ func loadContainerConfig(path string) (*pb.ContainerConfig, error) {
defer f.Close()

var config pb.ContainerConfig
if err := json.NewDecoder(f).Decode(&config); err != nil {
if err := utilyaml.NewYAMLOrJSONDecoder(f, 4096).Decode(&config); err != nil {
return nil, err
}
return &config, nil
Expand All @@ -108,7 +110,7 @@ func loadPodSandboxConfig(path string) (*pb.PodSandboxConfig, error) {
defer f.Close()

var config pb.PodSandboxConfig
if err := json.NewDecoder(f).Decode(&config); err != nil {
if err := utilyaml.NewYAMLOrJSONDecoder(f, 4096).Decode(&config); err != nil {
return nil, err
}
return &config, nil
Expand Down
13 changes: 13 additions & 0 deletions docs/examples/container-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"metadata": {
"name": "busybox"
},
"image":{
"image": "busybox"
},
"command": [
"top"
],
"linux": {
}
}
6 changes: 6 additions & 0 deletions docs/examples/container-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
metadata:
name: busybox
image:
image: busybox:latest
command:
- top
10 changes: 10 additions & 0 deletions docs/examples/sandbox-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"metadata": {
"name": "busybox-sandbox",
"namespace": "default",
"attempt": 1,
"uid": "hdishd83djaidwnduwk28bcsb"
},
"linux": {
}
}
8 changes: 8 additions & 0 deletions docs/examples/sandbox-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
metadata:
attempt: 1
name: busybox-sandbox
namespace: default
uid: hdishd83djaidwnduwk28bcsb
linux:
namespaces:
options: {}