Merge pull request #4213 from smarterclayton/use_name_from_server

Use name from server when displaying create/update
This commit is contained in:
Jeff Lowdermilk
2015-02-09 09:41:20 -08:00
8 changed files with 82 additions and 42 deletions

View File

@@ -67,11 +67,12 @@ Examples:
if err := schema.ValidateBytes(data); err != nil {
return err
}
if err := resource.NewHelper(info.Client, info.Mapping).Create(info.Namespace, true, data); err != nil {
obj, err := resource.NewHelper(info.Client, info.Mapping).Create(info.Namespace, true, data)
if err != nil {
return err
}
count++
// TODO: if generation of names added to server side, change this to use the server's name
info.Refresh(obj, true)
fmt.Fprintf(out, "%s\n", info.Name)
return nil
})

View File

@@ -26,6 +26,7 @@ import (
func TestCreateObject(t *testing.T) {
pods, _ := testData()
pods.Items[0].Name = "redis-master"
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
@@ -81,13 +82,15 @@ func TestCreateMultipleObject(t *testing.T) {
cmd.Flags().Set("filename", "../../../examples/guestbook/frontend-service.json")
cmd.Run(cmd, []string{})
if buf.String() != "redis-master\nfrontend\n" {
// Names should come from the REST response, NOT the files
if buf.String() != "foo\nbaz\n" {
t.Errorf("unexpected output: %s", buf.String())
}
}
func TestCreateDirectory(t *testing.T) {
pods, svc := testData()
pods.Items[0].Name = "redis-master"
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
@@ -114,7 +117,7 @@ func TestCreateDirectory(t *testing.T) {
cmd.Flags().Set("filename", "../../../examples/guestbook")
cmd.Run(cmd, []string{})
if buf.String() != "frontend-controller\nfrontend\nredis-master\nredis-master\nredis-slave-controller\nredisslave\n" {
if buf.String() != "baz\nbaz\nbaz\nredis-master\nbaz\nbaz\n" {
t.Errorf("unexpected output: %s", buf.String())
}
}

View File

@@ -43,7 +43,7 @@ Examples:
$ cat pod.json | kubectl update -f -
<update a pod based on the json passed into stdin>
$ kubectl update pods my-pod --patch='{ "apiVersion": "v1beta1", "desiredState": { "manifest": [{ "cpu": 100 }]}}'
<update a pod by downloading it, applying the patch, then updating, requires apiVersion be specified>`,
Run: func(cmd *cobra.Command, args []string) {
@@ -68,29 +68,32 @@ Examples:
if len(flags.Filenames) != 0 && len(patch) != 0 {
usageError(cmd, "Can not specify both --filename and --patch")
}
if len(flags.Filenames) > 0 {
err := r.Visit(func(info *resource.Info) error {
data, err := info.Mapping.Codec.Encode(info.Object)
if err != nil {
return err
}
if err := schema.ValidateBytes(data); err != nil {
return err
}
if err := resource.NewHelper(info.Client, info.Mapping).
Update(info.Namespace, info.Name, true, data); err != nil {
return err
}
fmt.Fprintf(out, "%s\n", info.Name)
return nil
})
checkErr(err)
} else {
// TODO: Make patching work with -f, updating with patched JSON input files
// TODO: Make patching work with -f, updating with patched JSON input files
if len(flags.Filenames) == 0 {
name := updateWithPatch(cmd, args, f, patch)
fmt.Fprintf(out, "%s\n", name)
return
}
err = r.Visit(func(info *resource.Info) error {
data, err := info.Mapping.Codec.Encode(info.Object)
if err != nil {
return err
}
if err := schema.ValidateBytes(data); err != nil {
return err
}
obj, err := resource.NewHelper(info.Client, info.Mapping).Update(info.Namespace, info.Name, true, data)
if err != nil {
return err
}
info.Refresh(obj, true)
fmt.Fprintf(out, "%s\n", info.Name)
return nil
})
checkErr(err)
},
}
cmd.Flags().VarP(&flags.Filenames, "filename", "f", "Filename, directory, or URL to file to use to update the resource")
@@ -116,7 +119,7 @@ func updateWithPatch(cmd *cobra.Command, args []string, f *Factory, patch string
data, err := helper.Codec.Encode(obj)
checkErr(err)
err = helper.Update(namespace, name, true, data)
obj, err = helper.Update(namespace, name, true, data)
checkErr(err)
return name
}

View File

@@ -67,7 +67,7 @@ func TestUpdateObject(t *testing.T) {
cmd.Run(cmd, []string{})
// uses the name from the file, not the response
if buf.String() != "redis-master\n" {
if buf.String() != "foo\n" {
t.Errorf("unexpected output: %s", buf.String())
}
}
@@ -104,7 +104,7 @@ func TestUpdateMultipleObject(t *testing.T) {
cmd.Flags().Set("filename", "../../../examples/guestbook/frontend-service.json")
cmd.Run(cmd, []string{})
if buf.String() != "redis-master\nfrontend\n" {
if buf.String() != "foo\nbaz\n" {
t.Errorf("unexpected output: %s", buf.String())
}
}
@@ -139,7 +139,7 @@ func TestUpdateDirectory(t *testing.T) {
cmd.Flags().Set("namespace", "test")
cmd.Run(cmd, []string{})
if buf.String() != "frontend-controller\nfrontend\nredis-master\nredis-master\nredis-slave-controller\nredisslave\n" {
if buf.String() != "qux\nbaz\nbaz\nfoo\nqux\nbaz\n" {
t.Errorf("unexpected output: %s", buf.String())
}
}