Skip to content

Commit

Permalink
Merge pull request #124 from feiskyer/yaml
Browse files Browse the repository at this point in the history
Create sandbox and container from yaml
  • Loading branch information
xlgao-zju authored Aug 24, 2017
2 parents 26a7a4f + f113636 commit 67362cf
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 19 deletions.
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: {}

0 comments on commit 67362cf

Please sign in to comment.