-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Use new resource builder in kubectl update #3805
Merged
satnam6502
merged 2 commits into
kubernetes:master
from
mnagy:allow_multiple_files_in_update
Feb 2, 2015
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/* | ||
Copyright 2015 Google Inc. All rights reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cmd_test | ||
|
||
import ( | ||
"bytes" | ||
"net/http" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" | ||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client" | ||
) | ||
|
||
func rcTestData() *api.ReplicationControllerList { | ||
rc := &api.ReplicationControllerList{ | ||
ListMeta: api.ListMeta{ | ||
ResourceVersion: "17", | ||
}, | ||
Items: []api.ReplicationController{ | ||
{ | ||
ObjectMeta: api.ObjectMeta{Name: "qux", Namespace: "test", ResourceVersion: "13"}, | ||
}, | ||
}, | ||
} | ||
return rc | ||
} | ||
|
||
func TestUpdateObject(t *testing.T) { | ||
pods, _ := testData() | ||
|
||
f, tf, codec := NewAPIFactory() | ||
tf.Printer = &testPrinter{} | ||
tf.Client = &client.FakeRESTClient{ | ||
Codec: codec, | ||
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) { | ||
switch p, m := req.URL.Path, req.Method; { | ||
case p == "/ns/test/pods/redis-master" && m == "GET": | ||
return &http.Response{StatusCode: 200, Body: objBody(codec, &pods.Items[0])}, nil | ||
case p == "/ns/test/pods/redis-master" && m == "PUT": | ||
return &http.Response{StatusCode: 200, Body: objBody(codec, &pods.Items[0])}, nil | ||
default: | ||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req) | ||
return nil, nil | ||
} | ||
}), | ||
} | ||
tf.Namespace = "test" | ||
buf := bytes.NewBuffer([]byte{}) | ||
|
||
cmd := f.NewCmdUpdate(buf) | ||
cmd.Flags().Set("filename", "../../../examples/guestbook/redis-master.json") | ||
cmd.Run(cmd, []string{}) | ||
|
||
// uses the name from the file, not the response | ||
if buf.String() != "redis-master\n" { | ||
t.Errorf("unexpected output: %s", buf.String()) | ||
} | ||
} | ||
|
||
func TestUpdateMultipleObject(t *testing.T) { | ||
pods, svc := testData() | ||
|
||
f, tf, codec := NewAPIFactory() | ||
tf.Printer = &testPrinter{} | ||
tf.Client = &client.FakeRESTClient{ | ||
Codec: codec, | ||
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) { | ||
switch p, m := req.URL.Path, req.Method; { | ||
case p == "/ns/test/pods/redis-master" && m == "GET": | ||
return &http.Response{StatusCode: 200, Body: objBody(codec, &pods.Items[0])}, nil | ||
case p == "/ns/test/pods/redis-master" && m == "PUT": | ||
return &http.Response{StatusCode: 200, Body: objBody(codec, &pods.Items[0])}, nil | ||
|
||
case p == "/ns/test/services/frontend" && m == "GET": | ||
return &http.Response{StatusCode: 200, Body: objBody(codec, &svc.Items[0])}, nil | ||
case p == "/ns/test/services/frontend" && m == "PUT": | ||
return &http.Response{StatusCode: 200, Body: objBody(codec, &svc.Items[0])}, nil | ||
default: | ||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req) | ||
return nil, nil | ||
} | ||
}), | ||
} | ||
tf.Namespace = "test" | ||
buf := bytes.NewBuffer([]byte{}) | ||
|
||
cmd := f.NewCmdUpdate(buf) | ||
cmd.Flags().Set("filename", "../../../examples/guestbook/redis-master.json") | ||
cmd.Flags().Set("filename", "../../../examples/guestbook/frontend-service.json") | ||
cmd.Run(cmd, []string{}) | ||
|
||
if buf.String() != "redis-master\nfrontend\n" { | ||
t.Errorf("unexpected output: %s", buf.String()) | ||
} | ||
} | ||
|
||
func TestUpdateDirectory(t *testing.T) { | ||
pods, svc := testData() | ||
rc := rcTestData() | ||
|
||
f, tf, codec := NewAPIFactory() | ||
tf.Printer = &testPrinter{} | ||
tf.Client = &client.FakeRESTClient{ | ||
Codec: codec, | ||
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) { | ||
switch p, m := req.URL.Path, req.Method; { | ||
case strings.HasPrefix(p, "/ns/test/pods/") && (m == "GET" || m == "PUT"): | ||
return &http.Response{StatusCode: 200, Body: objBody(codec, &pods.Items[0])}, nil | ||
case strings.HasPrefix(p, "/ns/test/services/") && (m == "GET" || m == "PUT"): | ||
return &http.Response{StatusCode: 200, Body: objBody(codec, &svc.Items[0])}, nil | ||
case strings.HasPrefix(p, "/ns/test/replicationcontrollers/") && (m == "GET" || m == "PUT"): | ||
return &http.Response{StatusCode: 200, Body: objBody(codec, &rc.Items[0])}, nil | ||
default: | ||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req) | ||
return nil, nil | ||
} | ||
}), | ||
} | ||
tf.Namespace = "test" | ||
buf := bytes.NewBuffer([]byte{}) | ||
|
||
cmd := f.NewCmdUpdate(buf) | ||
cmd.Flags().Set("filename", "../../../examples/guestbook") | ||
cmd.Flags().Set("namespace", "test") | ||
cmd.Run(cmd, []string{}) | ||
|
||
if buf.String() != "frontend-controller\nfrontend\nredis-master\nredis-master\nredis-slave-controller\nredisslave\n" { | ||
t.Errorf("unexpected output: %s", buf.String()) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If flags.Filenames is length 0, what is this command doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add test cases in update_test that roughly parallel create_test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is, in the case that no files are provided, and neither is patch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, if no files and no patch are provided, you'll just get an error. If no filenames are provided, it just works with patch mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you leave a TODO about making update with patch apply to all files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can, no problem. But before I do, just to make sure: You do know that this would be a totally new feature, in the sense that patch mode now works by patching downloaded objects and not files provided by command line, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Patch is an operation on arbitrary json. Where that json comes from is irrelevant.