Merge pull request #57 from mrunalp/pod_name_param

Allow overriding name in a pod sandbox config file
This commit is contained in:
Antonio Murdaca 2016-09-27 07:52:19 +02:00 committed by GitHub
commit fe774f82b1

View file

@ -29,6 +29,11 @@ var runPodSandboxCommand = cli.Command{
Value: "config.json", Value: "config.json",
Usage: "the path of a pod sandbox config file", Usage: "the path of a pod sandbox config file",
}, },
cli.StringFlag{
Name: "name",
Value: "",
Usage: "the name of the pod sandbox",
},
}, },
Action: func(context *cli.Context) error { Action: func(context *cli.Context) error {
// Set up a connection to the server. // Set up a connection to the server.
@ -40,7 +45,7 @@ var runPodSandboxCommand = cli.Command{
client := pb.NewRuntimeServiceClient(conn) client := pb.NewRuntimeServiceClient(conn)
// Test RuntimeServiceClient.RunPodSandbox // Test RuntimeServiceClient.RunPodSandbox
err = RunPodSandbox(client, context.String("config")) err = RunPodSandbox(client, context.String("config"), context.String("name"))
if err != nil { if err != nil {
return fmt.Errorf("Creating the pod sandbox failed: %v", err) return fmt.Errorf("Creating the pod sandbox failed: %v", err)
} }
@ -151,12 +156,17 @@ var listPodSandboxCommand = cli.Command{
// RunPodSandbox sends a RunPodSandboxRequest to the server, and parses // RunPodSandbox sends a RunPodSandboxRequest to the server, and parses
// the returned RunPodSandboxResponse. // the returned RunPodSandboxResponse.
func RunPodSandbox(client pb.RuntimeServiceClient, path string) error { func RunPodSandbox(client pb.RuntimeServiceClient, path string, name string) error {
config, err := loadPodSandboxConfig(path) config, err := loadPodSandboxConfig(path)
if err != nil { if err != nil {
return err return err
} }
// Override the name by the one specified through CLI
if name != "" {
config.Metadata.Name = &name
}
r, err := client.RunPodSandbox(context.Background(), &pb.RunPodSandboxRequest{Config: config}) r, err := client.RunPodSandbox(context.Background(), &pb.RunPodSandboxRequest{Config: config})
if err != nil { if err != nil {
return err return err