From b1004185b0faf5594bb454417c7d37b5c645ccc9 Mon Sep 17 00:00:00 2001 From: Pengfei Ni Date: Thu, 24 Aug 2017 16:23:28 +0800 Subject: [PATCH 1/2] Add support of creating from yaml config --- cmd/crictl/container.go | 2 +- cmd/crictl/main.go | 30 +++++++++++++++--------------- cmd/crictl/sandbox.go | 2 +- cmd/crictl/util.go | 6 ++++-- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/cmd/crictl/container.go b/cmd/crictl/container.go index 40b7066ab7..540068abe5 100644 --- a/cmd/crictl/container.go +++ b/cmd/crictl/container.go @@ -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 { diff --git a/cmd/crictl/main.go b/cmd/crictl/main.go index dc5562e5f7..f021b64dfc 100644 --- a/cmd/crictl/main.go +++ b/cmd/crictl/main.go @@ -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{ diff --git a/cmd/crictl/sandbox.go b/cmd/crictl/sandbox.go index d15e0e1846..84112cd075 100644 --- a/cmd/crictl/sandbox.go +++ b/cmd/crictl/sandbox.go @@ -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 == "" { diff --git a/cmd/crictl/util.go b/cmd/crictl/util.go index c5fe775eaf..d89b546a12 100644 --- a/cmd/crictl/util.go +++ b/cmd/crictl/util.go @@ -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" ) @@ -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 { @@ -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 @@ -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 From f11363680a6aa40b3ceccf28667b95df6912116b Mon Sep 17 00:00:00 2001 From: Pengfei Ni Date: Thu, 24 Aug 2017 16:23:38 +0800 Subject: [PATCH 2/2] Add examples --- docs/examples/container-config.json | 13 +++++++++++++ docs/examples/container-config.yaml | 6 ++++++ docs/examples/sandbox-config.json | 10 ++++++++++ docs/examples/sandbox-config.yaml | 8 ++++++++ 4 files changed, 37 insertions(+) create mode 100644 docs/examples/container-config.json create mode 100644 docs/examples/container-config.yaml create mode 100644 docs/examples/sandbox-config.json create mode 100644 docs/examples/sandbox-config.yaml diff --git a/docs/examples/container-config.json b/docs/examples/container-config.json new file mode 100644 index 0000000000..59dd177713 --- /dev/null +++ b/docs/examples/container-config.json @@ -0,0 +1,13 @@ +{ + "metadata": { + "name": "busybox" + }, + "image":{ + "image": "busybox" + }, + "command": [ + "top" + ], + "linux": { + } +} \ No newline at end of file diff --git a/docs/examples/container-config.yaml b/docs/examples/container-config.yaml new file mode 100644 index 0000000000..17ba9de8a7 --- /dev/null +++ b/docs/examples/container-config.yaml @@ -0,0 +1,6 @@ +metadata: + name: busybox +image: + image: busybox:latest +command: +- top \ No newline at end of file diff --git a/docs/examples/sandbox-config.json b/docs/examples/sandbox-config.json new file mode 100644 index 0000000000..b46d4c5392 --- /dev/null +++ b/docs/examples/sandbox-config.json @@ -0,0 +1,10 @@ +{ + "metadata": { + "name": "busybox-sandbox", + "namespace": "default", + "attempt": 1, + "uid": "hdishd83djaidwnduwk28bcsb" + }, + "linux": { + } +} \ No newline at end of file diff --git a/docs/examples/sandbox-config.yaml b/docs/examples/sandbox-config.yaml new file mode 100644 index 0000000000..6b3acbb1b3 --- /dev/null +++ b/docs/examples/sandbox-config.yaml @@ -0,0 +1,8 @@ +metadata: + attempt: 1 + name: busybox-sandbox + namespace: default + uid: hdishd83djaidwnduwk28bcsb +linux: + namespaces: + options: {}