Skip to content

Commit

Permalink
Merge pull request kubernetes#74 from danielnorberg/dano/cloudcfg-start
Browse files Browse the repository at this point in the history
cloudcfg: resize <name> <replicas> command
  • Loading branch information
brendandburns committed Jun 13, 2014
2 parents 1524ed7 + 3396237 commit 4a8c53e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cmd/cloudcfg/cloudcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,21 @@ func main() {
log.Fatalf("Error: %#v", err)
}
return
case "resize":
args := flag.Args()
if len(args) < 3 {
log.Fatal("usage: cloudcfg resize <name> <replicas>")
}
name := args[1]
replicas, err := strconv.Atoi(args[2])
if err != nil {
log.Fatalf("Error parsing replicas: %#v", err)
}
err = cloudcfg.ResizeController(name, replicas, kube_client.Client{Host: *httpServer, Auth: auth})
if err != nil {
log.Fatalf("Error: %#v", err)
}
return
case "rm":
err = cloudcfg.DeleteController(flag.Arg(1), kube_client.Client{Host: *httpServer, Auth: auth})
if err != nil {
Expand Down
19 changes: 19 additions & 0 deletions pkg/cloudcfg/cloudcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions pkg/cloudcfg/cloudcfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4a8c53e

Please sign in to comment.