Merge pull request #74 from danielnorberg/dano/cloudcfg-start
cloudcfg: resize <name> <replicas> command
This commit is contained in:
@@ -150,6 +150,25 @@ func StopController(name string, client client.ClientInterface) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ResizeController resizes a controller named 'name' by setting replicas to 'replicas'
|
||||
func ResizeController(name string, replicas int, client client.ClientInterface) error {
|
||||
controller, err := client.GetReplicationController(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
controller.DesiredState.Replicas = replicas
|
||||
controllerOut, err := client.UpdateReplicationController(controller)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data, err := yaml.Marshal(controllerOut)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Print(string(data))
|
||||
return nil
|
||||
}
|
||||
|
||||
func makePorts(spec string) []api.Port {
|
||||
parts := strings.Split(spec, ",")
|
||||
var result []api.Port
|
||||
|
@@ -222,6 +222,25 @@ func TestStopController(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestResizeController(t *testing.T) {
|
||||
fakeClient := FakeKubeClient{}
|
||||
name := "name"
|
||||
replicas := 17
|
||||
ResizeController(name, replicas, &fakeClient)
|
||||
if len(fakeClient.actions) != 2 {
|
||||
t.Errorf("Unexpected actions: %#v", fakeClient.actions)
|
||||
}
|
||||
if fakeClient.actions[0].action != "get-controller" ||
|
||||
fakeClient.actions[0].value.(string) != name {
|
||||
t.Errorf("Unexpected action: %#v", fakeClient.actions[0])
|
||||
}
|
||||
controller := fakeClient.actions[1].value.(ReplicationController)
|
||||
if fakeClient.actions[1].action != "update-controller" ||
|
||||
controller.DesiredState.Replicas != 17 {
|
||||
t.Errorf("Unexpected action: %#v", fakeClient.actions[1])
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloudCfgDeleteController(t *testing.T) {
|
||||
fakeClient := FakeKubeClient{}
|
||||
name := "name"
|
||||
|
Reference in New Issue
Block a user